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/18 13:10:50 UTC
(datafusion-sqlparser-rs) 01/01: DuckDB: Always render the macro argument list parentheses (#2656)
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-2656-8977e96a98796fd574f3716540021e0ea249daf5
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
commit ada831442e98c004d9d046182f26edc5cac3d6c9
Author: Luca Cappelletti <ca...@gmail.com>
AuthorDate: Sun Oct 18 13:10:28 2026 +0000
DuckDB: Always render the macro argument list parentheses (#2656)
---
src/ast/mod.rs | 8 +++++---
tests/sqlparser_duckdb.rs | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index f585121ad..c0fb446d2 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -5570,9 +5570,11 @@ impl fmt::Display for Statement {
temp = if *temporary { "TEMPORARY " } else { "" },
or_replace = if *or_replace { "OR REPLACE " } else { "" },
)?;
- if let Some(args) = args {
- write!(f, "({})", display_comma_separated(args))?;
- }
+ write!(
+ f,
+ "({})",
+ display_comma_separated(args.as_deref().unwrap_or(&[]))
+ )?;
match definition {
MacroDefinition::Expr(expr) => write!(f, " AS {expr}")?,
MacroDefinition::Table(query) => write!(f, " AS TABLE {query}")?,
diff --git a/tests/sqlparser_duckdb.rs b/tests/sqlparser_duckdb.rs
index fe5d29c5c..216d51471 100644
--- a/tests/sqlparser_duckdb.rs
+++ b/tests/sqlparser_duckdb.rs
@@ -939,3 +939,40 @@ fn test_duckdb_nested_block_comments() {
))
);
}
+
+#[test]
+fn parse_create_macro_without_arguments() {
+ duckdb_and_generic().verified_stmt("CREATE MACRO four() AS 4");
+ duckdb_and_generic()
+ .verified_stmt("CREATE OR REPLACE TEMPORARY MACRO nothing() AS TABLE SELECT 1");
+ duckdb().one_statement_parses_to("CREATE FUNCTION add() AS 1", "CREATE MACRO add() AS 1");
+}
+
+#[test]
+fn display_create_macro_propagates_argument_list_errors() {
+ use core::fmt::{self, Write};
+
+ struct RejectingWriter(char);
+
+ impl Write for RejectingWriter {
+ fn write_str(&mut self, value: &str) -> fmt::Result {
+ if value.contains(self.0) {
+ Err(fmt::Error)
+ } else {
+ Ok(())
+ }
+ }
+ }
+
+ for sql in [
+ "CREATE MACRO four() AS 4",
+ "CREATE MACRO add(a, b) AS a + b",
+ "CREATE MACRO nothing() AS TABLE SELECT 1",
+ ] {
+ let statement = duckdb_and_generic().verified_stmt(sql);
+ for rejected in ['(', ')'] {
+ let mut writer = RejectingWriter(rejected);
+ assert_eq!(write!(writer, "{statement}"), Err(fmt::Error));
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org