Repository navigation
Add Dialect::supports_cte_materialization and enable it for DuckDB - #2651
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2651 +/- ##
=======================================
Coverage 81.24% 81.25%
=======================================
Files 42 42
Lines 33901 33910 +9
Branches 33901 33910 +9
=======================================
+ Hits 27543 27553 +10
Misses 2792 2792
+ Partials 3566 3565 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 Approval recommended
The focused change preserves defaults and includes relevant coverage, with no blocking issues identified; tests were not executed.
No open issues 🎉
What changed in this PR
Makes CTE materialization support configurable by dialect, enabling DuckDB while preserving existing defaults.
Changes:
- Adds
Dialect::supports_cte_materialization, enabled for PostgreSQL and DuckDB. - Replaces the parser’s hard-coded PostgreSQL check.
- Adds AST, round-trip, and unsupported-dialect rejection tests.
| File | Description |
|---|---|
| tests/sqlparser_common.rs | Tests materialization directives and rejection. |
| src/parser/mod.rs | Uses the dialect capability flag. |
| src/dialect/postgresql.rs | Preserves PostgreSQL support. |
| src/dialect/mod.rs | Defines the capability and test-wrapper delegation. |
| src/dialect/duckdb.rs | Enables DuckDB support. |
Review effort: Balanced
| ), | ||
| ] { | ||
| let sql = format!("WITH c AS {directive}(SELECT 1) SELECT * FROM c"); | ||
| let query = all_dialects_where(|d| d.supports_cte_materialization()).verified_query(&sql); |
There was a problem hiding this comment.
You should add this DuckDB red test, because nothing fails if DuckDbDialect::supports_cte_materialization returns false. DuckDB then moves into the rejecting set and parse_cte_materialization still passes. With this line, that regression fails with Expected: (, found: MATERIALIZED.
| let query = all_dialects_where(|d| d.supports_cte_materialization()).verified_query(&sql); | |
| TestedDialects::new(vec![Box::new(DuckDbDialect {})]).verified_query(&sql); | |
| let query = all_dialects_where(|d| d.supports_cte_materialization()).verified_query(&sql); |
Co-Authored-By: LucaCappelletti94 <7738570+LucaCappelletti94@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
db428f8 to
420fab6
Compare
WITH c AS [NOT] MATERIALIZED (...)parses only withPostgreSqlDialect, because the parser uses a hard-coded dialect check. DuckDB also accepts this syntax, and custom dialects cannot opt in to it.This PR replaces the check with a
Dialect::supports_cte_materializationmethod that is off by default. The method returnstruefor PostgreSQL and DuckDB.GenericDialectstill rejects the syntax. Tests check the AST value, the SQL round trip, and the rejection by every dialect that does not opt in.