Skip to content

Commit

Permalink
Merge pull request #297 from matthias-Q/unload_statement
Browse files Browse the repository at this point in the history
feat: add athena `unload` statement
  • Loading branch information
matthias-Q authored Nov 28, 2024
2 parents 44bb864 + b87b5e9 commit 7a00106
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
13 changes: 12 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ module.exports = grammar({
keyword_truncate: _ => make_keyword("truncate"),
keyword_merge: _ => make_keyword("merge"),
keyword_show: _ => make_keyword("show"),
keyword_unload: _ => make_keyword("unload"),
keyword_into: _ => make_keyword("into"),
keyword_overwrite: _ => make_keyword("overwrite"),
keyword_values: _ => make_keyword("values"),
Expand Down Expand Up @@ -744,10 +745,20 @@ module.exports = grammar({
$._select_statement,
$.set_operation,
$._show_statement,
$._unload_statement,
),
),
),

// athena
_unload_statement: $ => seq(
$.keyword_unload,
wrapped_in_parenthesis($._select_statement),
$.keyword_to,
$._single_quote_string,
$.storage_parameters,
),

_show_statement: $ => seq(
$.keyword_show,
choice(
Expand Down Expand Up @@ -994,7 +1005,7 @@ module.exports = grammar({
storage_parameters: $ => seq(
$.keyword_with,
paren_list(
seq($.identifier, optional(seq('=', $.literal))),
seq($.identifier, optional(seq('=', choice($.literal, $.array)))),
true
),
),
Expand Down
1 change: 1 addition & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
(keyword_delete)
(keyword_create)
(keyword_show)
(keyword_unload)
(keyword_insert)
(keyword_merge)
(keyword_distinct)
Expand Down
71 changes: 71 additions & 0 deletions test/corpus/unload.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
================================================================================
Simple Unload
================================================================================

UNLOAD (SELECT * FROM old_table)
TO 's3://amzn-s3-demo-bucket/unload_test_1/'
WITH (format = 'JSON')

--------------------------------------------------------------------------------

(program
(statement
(keyword_unload)
(select
(keyword_select)
(select_expression
(term
(all_fields))))
(from
(keyword_from)
(relation
(object_reference
(identifier))))
(keyword_to)
(storage_parameters
(keyword_with)
(identifier)
(literal))))

================================================================================
Unload with ARRAY
================================================================================

UNLOAD (SELECT name1, address1, comment1, key1 FROM table1)
TO 's3://amzn-s3-demo-bucket/ partitioned/'
WITH (format = 'TEXTFILE', partitioned_by = ARRAY['key1'])

--------------------------------------------------------------------------------

(program
(statement
(keyword_unload)
(select
(keyword_select)
(select_expression
(term
(field
(identifier)))
(term
(field
(identifier)))
(term
(field
(identifier)))
(term
(field
(identifier)))))
(from
(keyword_from)
(relation
(object_reference
(identifier))))
(keyword_to)
(storage_parameters
(keyword_with)
(identifier)
(literal)
(identifier)
(array
(keyword_array)
(literal)))))

0 comments on commit 7a00106

Please sign in to comment.