Skip to content

Commit

Permalink
feat: optimize athena tables
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-Q committed Jun 17, 2023
1 parent b620971 commit f3c3515
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ module.exports = grammar({
keyword_compute: _ => make_keyword("compute"),
keyword_stats: _ => make_keyword("stats"),
keyword_statistics: _ => make_keyword("statistics"),
keyword_optimize: _ => make_keyword("optimize"),
keyword_rewrite: _ => make_keyword("rewrite"),
keyword_bin_pack: _ => make_keyword("bin_pack"),
keyword_incremental: _ => make_keyword("incremental"),
keyword_location: _ => make_keyword("location"),
keyword_partitioned: _ => make_keyword("partitioned"),
Expand Down Expand Up @@ -1349,6 +1352,7 @@ module.exports = grammar({

// Compute stats for Impala and Hive
_compute_stats: $ => choice(
// Hive
seq(
$.keyword_analyze,
$.keyword_table,
Expand All @@ -1370,6 +1374,7 @@ module.exports = grammar({
),
optional($.keyword_noscan),
),
// Impala
seq(
$.keyword_compute,
optional(
Expand All @@ -1384,6 +1389,18 @@ module.exports = grammar({
)
)
),
// Athena/Iceberg
seq(
$.keyword_optimize,
$.table_reference,
$.keyword_rewrite,
$.keyword_data,
$.keyword_using,
$.keyword_bin_pack,
optional(
$.where,
)
),
),

// TODO: this does not account for partitions specs like
Expand Down
28 changes: 28 additions & 0 deletions test/corpus/optimize.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,31 @@ NOSCAN
(keyword_cache)
(keyword_metadata)
(keyword_noscan)))

================================================================================
Athena/Iceberg: Optimize table
================================================================================

OPTIMIZE mytable REWRITE DATA USING BIN_PACK
WHERE col1 is not null
--------------------------------------------------------------------------------

(program
(statement
(keyword_optimize)
(table_reference
(identifier))
(keyword_rewrite)
(keyword_data)
(keyword_using)
(keyword_bin_pack)
(where
(keyword_where)
(binary_expression
(field
(identifier))
(is_not
(keyword_is)
(keyword_not))
(literal
(keyword_null))))))

0 comments on commit f3c3515

Please sign in to comment.