From 54027b6c2264303cf9f74da20208ef66019ae52c Mon Sep 17 00:00:00 2001 From: Simon Vandel Sillesen Date: Wed, 2 Jul 2025 21:40:01 +0200 Subject: [PATCH 1/3] Make GenericDialect support trailing commas in projections Similar to https://github.com/apache/datafusion-sqlparser-rs/pull/1911. The docs for GenericDialect says that is can be permissive, so I thought it could support trailing commas in projections. This would help a bit on the "friendly sql" issue https://github.com/apache/datafusion/issues/14514 --- src/dialect/generic.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/dialect/generic.rs b/src/dialect/generic.rs index 59671e211..5e9f2e4e2 100644 --- a/src/dialect/generic.rs +++ b/src/dialect/generic.rs @@ -116,6 +116,10 @@ impl Dialect for GenericDialect { true } + fn supports_projection_trailing_commas(&self) -> bool { + true + } + fn supports_asc_desc_in_column_definition(&self) -> bool { true } From 44ceedaf0551311e87a7d6e32a395ba216e8f994 Mon Sep 17 00:00:00 2001 From: Simon Vandel Sillesen Date: Wed, 2 Jul 2025 21:44:44 +0200 Subject: [PATCH 2/3] Remove test that now parses --- tests/sqlparser_common.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 61a4de402..e7b4026f5 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -11125,16 +11125,9 @@ fn parse_trailing_comma() { ); trailing_commas.verified_stmt(r#"SELECT "from" FROM "from""#); - // doesn't allow any trailing commas + // doesn't allow all trailing commas let trailing_commas = TestedDialects::new(vec![Box::new(GenericDialect {})]); - assert_eq!( - trailing_commas - .parse_sql_statements("SELECT name, age, from employees;") - .unwrap_err(), - ParserError::ParserError("Expected an expression, found: from".to_string()) - ); - assert_eq!( trailing_commas .parse_sql_statements("REVOKE USAGE, SELECT, ON p TO u") From 83812914bd4f35c6d98b8d9af2ba5d24693492f3 Mon Sep 17 00:00:00 2001 From: Simon Vandel Sillesen Date: Sat, 5 Jul 2025 21:36:46 +0200 Subject: [PATCH 3/3] re-introduce test using postgres dialect --- tests/sqlparser_common.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index e7b4026f5..1980f4bb1 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -11125,8 +11125,15 @@ fn parse_trailing_comma() { ); trailing_commas.verified_stmt(r#"SELECT "from" FROM "from""#); - // doesn't allow all trailing commas - let trailing_commas = TestedDialects::new(vec![Box::new(GenericDialect {})]); + // doesn't allow any trailing commas + let trailing_commas = TestedDialects::new(vec![Box::new(PostgreSqlDialect {})]); + + assert_eq!( + trailing_commas + .parse_sql_statements("SELECT name, age, from employees;") + .unwrap_err(), + ParserError::ParserError("Expected an expression, found: from".to_string()) + ); assert_eq!( trailing_commas