You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/10/17 15:21:09 UTC
(datafusion-sqlparser-rs) branch gh-readonly-queue/main/pr-2651-7b5821dd45ce13ba6a77b24c39854a863848c2b2 created (now 1aabd12d1)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a change to branch gh-readonly-queue/main/pr-2651-7b5821dd45ce13ba6a77b24c39854a863848c2b2
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
at 1aabd12d1 Add `Dialect::supports_cte_materialization` and enable it for DuckDB (#2651)
This branch includes the following new commits:
new 1aabd12d1 Add `Dialect::supports_cte_materialization` and enable it for DuckDB (#2651)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org
(datafusion-sqlparser-rs) 01/01: Add `Dialect::supports_cte_materialization` and enable it for DuckDB (#2651)
Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-2651-7b5821dd45ce13ba6a77b24c39854a863848c2b2
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
commit 1aabd12d12234de55b27f658add789eed1eaaa5c
Author: Adrian Garcia Badaracco <17...@users.noreply.github.com>
AuthorDate: Sat Oct 17 15:20:45 2026 +0000
Add `Dialect::supports_cte_materialization` and enable it for DuckDB (#2651)
Co-authored-by: LucaCappelletti94 <77...@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <no...@anthropic.com>
---
src/dialect/duckdb.rs | 4 ++++
src/dialect/mod.rs | 10 ++++++++++
src/dialect/postgresql.rs | 4 ++++
src/parser/mod.rs | 2 +-
tests/sqlparser_common.rs | 22 ++++++++++++++++++++++
5 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/src/dialect/duckdb.rs b/src/dialect/duckdb.rs
index 28ee24026..ce72f578a 100644
--- a/src/dialect/duckdb.rs
+++ b/src/dialect/duckdb.rs
@@ -24,6 +24,10 @@ pub struct DuckDbDialect;
// In most cases the redshift dialect is identical to [`PostgresSqlDialect`].
impl Dialect for DuckDbDialect {
+ fn supports_cte_materialization(&self) -> bool {
+ true
+ }
+
fn supports_trailing_commas(&self) -> bool {
true
}
diff --git a/src/dialect/mod.rs b/src/dialect/mod.rs
index d8f93e49e..f7c54a9b7 100644
--- a/src/dialect/mod.rs
+++ b/src/dialect/mod.rs
@@ -386,6 +386,16 @@ pub trait Dialect: Debug + Any {
false
}
+ /// Returns true if the dialect supports `AS MATERIALIZED` and `AS NOT MATERIALIZED`
+ /// in a common table expression.
+ ///
+ /// ```sql
+ /// WITH cte AS MATERIALIZED (SELECT 1) SELECT * FROM cte
+ /// ```
+ fn supports_cte_materialization(&self) -> bool {
+ false
+ }
+
/// Returns true if the dialects supports `group sets, roll up, or cube` expressions.
fn supports_group_by_expr(&self) -> bool {
false
diff --git a/src/dialect/postgresql.rs b/src/dialect/postgresql.rs
index 3bec6ceba..65bfd46a7 100644
--- a/src/dialect/postgresql.rs
+++ b/src/dialect/postgresql.rs
@@ -73,6 +73,10 @@ const AND_PREC: u8 = 20;
const OR_PREC: u8 = 10;
impl Dialect for PostgreSqlDialect {
+ fn supports_cte_materialization(&self) -> bool {
+ true
+ }
+
fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
Some('"')
}
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 7d2006b2d..340b2d077 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -15352,7 +15352,7 @@ impl<'a> Parser<'a> {
};
let mut is_materialized = None;
- if dialect_of!(self is PostgreSqlDialect) {
+ if self.dialect.supports_cte_materialization() {
if self.parse_keyword(Keyword::MATERIALIZED) {
is_materialized = Some(CteAsMaterialized::Materialized);
} else if self.parse_keywords(&[Keyword::NOT, Keyword::MATERIALIZED]) {
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs
index 53fbe1b49..1959bcd34 100644
--- a/tests/sqlparser_common.rs
+++ b/tests/sqlparser_common.rs
@@ -20677,3 +20677,25 @@ fn parse_array_suffix_after_nested_type() {
})
.verified_stmt("SELECT CAST(NULL AS MAP<INT, STRUCT<a INT>> ARRAY)");
}
+
+#[test]
+fn parse_cte_materialization() {
+ for (directive, expected) in [
+ ("", None),
+ ("MATERIALIZED ", Some(CteAsMaterialized::Materialized)),
+ (
+ "NOT MATERIALIZED ",
+ Some(CteAsMaterialized::NotMaterialized),
+ ),
+ ] {
+ let sql = format!("WITH c AS {directive}(SELECT 1) SELECT * FROM c");
+ TestedDialects::new(vec![Box::new(DuckDbDialect {})]).verified_query(&sql);
+ let query = all_dialects_where(|d| d.supports_cte_materialization()).verified_query(&sql);
+ assert_eq!(query.with.unwrap().cte_tables[0].materialized, expected);
+ if expected.is_some() {
+ all_dialects_where(|d| !d.supports_cte_materialization())
+ .parse_sql_statements(&sql)
+ .unwrap_err();
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org