Skip to content

Commit

Permalink
feat: add summarize to duckdb
Browse files Browse the repository at this point in the history
  • Loading branch information
benfdking committed Nov 24, 2024
1 parent 1533b5b commit da66325
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/lib-core/src/dialects/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ impl Dialect {
self.sets_mut(set_label).extend(keywords);
}

pub fn add_keyword_to_set(&mut self, set_label: &'static str, value: &'static str) {
self.sets_mut(set_label).insert(value);
}

pub fn bracket_sets(&self, label: &str) -> AHashSet<BracketPair> {
assert!(
label == "bracket_pairs" || label == "angle_bracket_pairs",
Expand Down
19 changes: 18 additions & 1 deletion crates/lib-dialects/src/duckdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub fn raw_dialect() -> Dialect {
let mut duckdb_dialect = postgres_dialect;
duckdb_dialect.name = DialectKind::Duckdb;

duckdb_dialect.add_keyword_to_set("reserved_keywords", "Summarize");

duckdb_dialect.add([
(
"SingleIdentifierGrammar".into(),
Expand Down Expand Up @@ -71,6 +73,18 @@ pub fn raw_dialect() -> Dialect {
.to_matchable()
.into(),
),
(
"SummarizeStatemenSegment".into(),
Sequence::new(vec_of_erased![
Ref::keyword("SUMMARIZE"),
one_of(vec_of_erased![
Ref::new("SingleIdentifierGrammar"),
Ref::new("SelectStatementSegment")
])
])
.to_matchable()
.into(),
),
]);

duckdb_dialect.insert_lexer_matchers(
Expand Down Expand Up @@ -191,7 +205,10 @@ pub fn raw_dialect() -> Dialect {
duckdb_dialect.replace_grammar(
"StatementSegment",
postgres::statement_segment().copy(
Some(vec_of_erased![Ref::new("LoadStatementSegment")]),
Some(vec_of_erased![
Ref::new("LoadStatementSegment"),
Ref::new("SummarizeStatemenSegment")
]),
None,
None,
None,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SUMMARIZE tbl;

SUMMARIZE SELECT * FROM tbl;
22 changes: 22 additions & 0 deletions crates/lib-dialects/test/fixtures/dialects/duckdb/summarize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
file:
- statement:
- keyword: SUMMARIZE
- naked_identifier: tbl
- statement_terminator: ;
- statement:
- keyword: SUMMARIZE
- select_statement:
- select_clause:
- keyword: SELECT
- select_clause_element:
- wildcard_expression:
- wildcard_identifier:
- star: '*'
- from_clause:
- keyword: FROM
- from_expression:
- from_expression_element:
- table_expression:
- table_reference:
- naked_identifier: tbl
- statement_terminator: ;

0 comments on commit da66325

Please sign in to comment.