From 65159e18ffca03db61c35a7035878fdc10d782a4 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 15 Aug 2024 12:00:32 +0100 Subject: [PATCH] Support HEAD of sqlparser main --- Cargo.toml | 2 +- datafusion-cli/Cargo.lock | 6 ++---- datafusion/sql/src/expr/mod.rs | 2 +- datafusion/sql/src/planner.rs | 1 + datafusion/sql/src/relation/mod.rs | 1 + datafusion/sql/src/statement.rs | 2 +- datafusion/sql/src/unparser/ast.rs | 5 ++++- datafusion/sql/src/unparser/expr.rs | 1 + datafusion/sql/src/unparser/plan.rs | 2 ++ datafusion/sql/src/utils.rs | 1 + 10 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 02b1f1ccd92a..bd955343c87e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -133,7 +133,7 @@ rand = "0.8" regex = "1.8" rstest = "0.22.0" serde_json = "1" -sqlparser = { version = "0.49", features = ["visitor"] } +sqlparser = { git = "https://github.com/sqlparser-rs/sqlparser-rs.git", rev = "fab834d", features = ["visitor"] } tempfile = "3" thiserror = "1.0.44" tokio = { version = "1.36", features = ["macros", "rt", "sync"] } diff --git a/datafusion-cli/Cargo.lock b/datafusion-cli/Cargo.lock index 90995c1d116a..ea3df2f5b01b 100644 --- a/datafusion-cli/Cargo.lock +++ b/datafusion-cli/Cargo.lock @@ -3524,8 +3524,7 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "sqlparser" version = "0.49.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a404d0e14905361b918cb8afdb73605e25c1d5029312bd9785142dcb3aa49e" +source = "git+https://github.com/sqlparser-rs/sqlparser-rs.git?rev=fab834d#fab834dca345c69dfd9c59ec93db8179d0389089" dependencies = [ "log", "sqlparser_derive", @@ -3534,8 +3533,7 @@ dependencies = [ [[package]] name = "sqlparser_derive" version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01b2e185515564f15375f593fb966b5718bc624ba77fe49fa4616ad619690554" +source = "git+https://github.com/sqlparser-rs/sqlparser-rs.git?rev=fab834d#fab834dca345c69dfd9c59ec93db8179d0389089" dependencies = [ "proc-macro2", "quote", diff --git a/datafusion/sql/src/expr/mod.rs b/datafusion/sql/src/expr/mod.rs index 7c94e5ead5c3..035fd3816c6c 100644 --- a/datafusion/sql/src/expr/mod.rs +++ b/datafusion/sql/src/expr/mod.rs @@ -178,7 +178,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { SQLExpr::Value(value) => { self.parse_value(value, planner_context.prepare_param_data_types()) } - SQLExpr::Extract { field, expr } => { + SQLExpr::Extract { field, expr, .. } => { let mut extract_args = vec![ Expr::Literal(ScalarValue::from(format!("{field}"))), self.sql_expr_to_logical_expr(*expr, schema, planner_context)?, diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs index bf7c3fe0be4f..57147abde85a 100644 --- a/datafusion/sql/src/planner.rs +++ b/datafusion/sql/src/planner.rs @@ -513,6 +513,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { | SQLDataType::Union(_) | SQLDataType::Nullable(_) | SQLDataType::LowCardinality(_) + | SQLDataType::Trigger => not_impl_err!( "Unsupported SQL type {sql_type:?}" ), diff --git a/datafusion/sql/src/relation/mod.rs b/datafusion/sql/src/relation/mod.rs index 5d7b3d5918d3..50027a0efd84 100644 --- a/datafusion/sql/src/relation/mod.rs +++ b/datafusion/sql/src/relation/mod.rs @@ -36,6 +36,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { if let Some(func_args) = args { let tbl_func_name = name.0.first().unwrap().value.to_string(); let args = func_args + .args .into_iter() .flat_map(|arg| { if let FunctionArg::Unnamed(FunctionArgExpr::Expr(expr)) = arg diff --git a/datafusion/sql/src/statement.rs b/datafusion/sql/src/statement.rs index 6d47232ec270..e75a96e78d48 100644 --- a/datafusion/sql/src/statement.rs +++ b/datafusion/sql/src/statement.rs @@ -198,8 +198,8 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { match statement { Statement::ExplainTable { describe_alias: DescribeAlias::Describe, // only parse 'DESCRIBE table_name' and not 'EXPLAIN table_name' - hive_format: _, table_name, + .. } => self.describe_table_to_plan(table_name), Statement::Explain { verbose, diff --git a/datafusion/sql/src/unparser/ast.rs b/datafusion/sql/src/unparser/ast.rs index c10db9831457..71ff712985cd 100644 --- a/datafusion/sql/src/unparser/ast.rs +++ b/datafusion/sql/src/unparser/ast.rs @@ -428,7 +428,10 @@ impl TableRelationBuilder { None => return Err(Into::into(UninitializedFieldError::from("name"))), }, alias: self.alias.clone(), - args: self.args.clone(), + args: self.args.clone().map(|args| ast::TableFunctionArgs { + args, + settings: None, + }), with_hints: self.with_hints.clone(), version: self.version.clone(), partitions: self.partitions.clone(), diff --git a/datafusion/sql/src/unparser/expr.rs b/datafusion/sql/src/unparser/expr.rs index 39511ea4d03a..f67de4de5fa6 100644 --- a/datafusion/sql/src/unparser/expr.rs +++ b/datafusion/sql/src/unparser/expr.rs @@ -592,6 +592,7 @@ impl Unparser<'_> { return Some(ast::Expr::Extract { field, expr: Box::new(date_expr), + syntax: ast::ExtractSyntax::From, }); } } diff --git a/datafusion/sql/src/unparser/plan.rs b/datafusion/sql/src/unparser/plan.rs index 024f33fb2c7d..8b5a5b0942b8 100644 --- a/datafusion/sql/src/unparser/plan.rs +++ b/datafusion/sql/src/unparser/plan.rs @@ -403,6 +403,7 @@ impl Unparser<'_> { let ast_join = ast::Join { relation, + global: false, join_operator: self .join_operator_to_sql(join.join_type, join_constraint), }; @@ -435,6 +436,7 @@ impl Unparser<'_> { let ast_join = ast::Join { relation, + global: false, join_operator: self.join_operator_to_sql( JoinType::Inner, ast::JoinConstraint::On(ast::Expr::Value(ast::Value::Boolean( diff --git a/datafusion/sql/src/utils.rs b/datafusion/sql/src/utils.rs index 5cdc546e0267..af161bba45c1 100644 --- a/datafusion/sql/src/utils.rs +++ b/datafusion/sql/src/utils.rs @@ -268,6 +268,7 @@ pub(crate) fn value_to_string(value: &Value) -> Option { Value::SingleQuotedString(s) => Some(s.to_string()), Value::DollarQuotedString(s) => Some(s.to_string()), Value::Number(_, _) | Value::Boolean(_) => Some(value.to_string()), + Value::UnicodeStringLiteral(s) => Some(s.to_string()), Value::DoubleQuotedString(_) | Value::EscapedStringLiteral(_) | Value::NationalStringLiteral(_)