-
Notifications
You must be signed in to change notification settings - Fork 778
DuckDB: Add SUMMARIZE query support #2450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
50e42f1
21f2a0d
ddebcee
d640273
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1024,6 +1024,7 @@ define_keywords!( | |
| SUBTYPE_OPCLASS, | ||
| SUCCEEDS, | ||
| SUM, | ||
| SUMMARIZE, | ||
| SUPER, | ||
| SUPERUSER, | ||
| SUPPORT, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -925,3 +925,73 @@ fn test_duckdb_lambda_function() { | |||||||||
| let sql_transform = "SELECT list_transform([1, 2, 3], lambda x : x * 2)"; | ||||||||||
| duckdb().verified_stmt(sql_transform); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| #[test] | ||||||||||
| fn parse_summarize() { | ||||||||||
| duckdb().verified_stmt("SUMMARIZE users"); | ||||||||||
| duckdb().verified_stmt(r#"SUMMARIZE "analytics"."events""#); | ||||||||||
| duckdb().verified_stmt("SUMMARIZE 'users'"); | ||||||||||
| duckdb().verified_stmt("SUMMARIZE SELECT * FROM users"); | ||||||||||
| duckdb().verified_stmt("SUMMARIZE FROM users"); | ||||||||||
| duckdb().verified_stmt("SUMMARIZE VALUES (1.0), (6754950520)"); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should cover the table names that collide with row constructors. Both lines fail on the current head and pass with the change above.
Suggested change
|
||||||||||
| duckdb().verified_stmt("SUMMARIZE (SELECT 42 AS answer)"); | ||||||||||
| duckdb().verified_stmt("SUMMARIZE WITH users AS (SELECT 1 AS id) SELECT * FROM users"); | ||||||||||
| duckdb().verified_stmt("SELECT column_name FROM (SUMMARIZE SELECT 42 AS answer)"); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should cover
Suggested change
|
||||||||||
|
|
||||||||||
| TestedDialects::new(vec![Box::new(GenericDialect {})]) | ||||||||||
| .parse_sql_statements("SUMMARIZE users") | ||||||||||
| .expect_err("SUMMARIZE should remain DuckDB-specific"); | ||||||||||
| duckdb_and_generic().verified_stmt("SELECT summarize FROM jobs"); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| #[test] | ||||||||||
| fn parse_summarize_scalar_subquery() { | ||||||||||
| for sql in [ | ||||||||||
| "SELECT (SUMMARIZE users)", | ||||||||||
| "SELECT (SUMMARIZE SELECT 42 AS answer)", | ||||||||||
| "SELECT (SUMMARIZE FROM users)", | ||||||||||
| "SELECT (SUMMARIZE VALUES (1))", | ||||||||||
| "SELECT (SUMMARIZE (SELECT 42 AS answer))", | ||||||||||
| "SELECT (SUMMARIZE WITH users AS (SELECT 1 AS id) SELECT * FROM users)", | ||||||||||
| "SELECT ((SUMMARIZE users))", | ||||||||||
| "SELECT coalesce((SUMMARIZE users), 0)", | ||||||||||
| "SELECT 1 = ANY(SUMMARIZE users)", | ||||||||||
| "SELECT 1 >= ALL(SUMMARIZE users)", | ||||||||||
| ] { | ||||||||||
| duckdb().verified_stmt(sql); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| let Expr::Subquery(query) = duckdb().verified_expr("(SUMMARIZE users)") else { | ||||||||||
| panic!("Expected a scalar subquery"); | ||||||||||
| }; | ||||||||||
| assert_eq!( | ||||||||||
| *query.body, | ||||||||||
| SetExpr::Summarize(SummarizeTarget::Table { | ||||||||||
| name: ObjectName::from(vec![Ident::new("users")]), | ||||||||||
| }) | ||||||||||
| ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| #[test] | ||||||||||
| fn parse_summarize_subquery_dialect_gate() { | ||||||||||
| duckdb_and_generic().verified_stmt(r#"SELECT ("summarize") FROM jobs"#); | ||||||||||
| let dialects = all_dialects_where(|dialect| !dialect.supports_summarize()); | ||||||||||
| dialects.verified_stmt("SELECT (summarize) FROM jobs"); | ||||||||||
| dialects.verified_stmt("SELECT summarize(1) FROM jobs"); | ||||||||||
| assert_eq!( | ||||||||||
| dialects | ||||||||||
| .parse_sql_statements("SELECT (SUMMARIZE users)") | ||||||||||
| .unwrap_err(), | ||||||||||
| ParserError::ParserError("Expected: ), found: users".to_owned()) | ||||||||||
| ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| #[test] | ||||||||||
| fn parse_summarize_subquery_missing_target() { | ||||||||||
| assert_eq!( | ||||||||||
| duckdb() | ||||||||||
| .parse_sql_statements("SELECT (SUMMARIZE)") | ||||||||||
| .unwrap_err(), | ||||||||||
| ParserError::ParserError("Expected: identifier, found: )".to_owned()) | ||||||||||
| ); | ||||||||||
| } | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should route
VALUESto the query branch only when a(follows, and dropVALUE. DuckDB 1.4.4 readsSUMMARIZE valueandSUMMARIZE valuesas tables namedvalueandvaluesand rejectsSUMMARIZE VALUE (1), but this branch fails both table forms withExpected: (, found: EOF. Thefuzz_duckdb_acceptsoracle reports it.