Skip to content

Apache DataFusion SQL Query Engine

chore(deps): update sqlparser requirement from 0.33 to 0.34 (#6416)

Andrew Lamba8246bfb7223
diff --git a/datafusion-cli/Cargo.lock b/datafusion-cli/Cargo.lock
index 9deb4726bb..b40b7a0c2d 100644
--- a/datafusion-cli/Cargo.lock
+++ b/datafusion-cli/Cargo.lock
@@ -610,9 +610,9 @@ dependencies = [
[[package]]
name = "base64"
-version = "0.21.0"
+version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
+checksum = "3f1e31e207a6b8fb791a38ea3105e6cb541f55e4d029902d3039a4ad07cc4105"
[[package]]
name = "base64-simd"
@@ -1131,9 +1131,9 @@ dependencies = [
[[package]]
name = "digest"
-version = "0.10.6"
+version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f"
+checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
@@ -1812,9 +1812,9 @@ dependencies = [
[[package]]
name = "linux-raw-sys"
-version = "0.3.7"
+version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ece97ea872ece730aed82664c424eb4c8291e1ff2480247ccf7409044bc6479f"
+checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
[[package]]
name = "lock_api"
@@ -2762,9 +2762,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "sqlparser"
-version = "0.33.0"
+version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "355dc4d4b6207ca8a3434fc587db0a8016130a574dbcdbfb93d7f7b5bc5b211a"
+checksum = "37d3706eefb17039056234df6b566b0014f303f867f2656108334a55b8096f59"
dependencies = [
"log",
"sqlparser_derive",
@@ -2820,9 +2820,9 @@ dependencies = [
[[package]]
name = "subtle"
-version = "2.4.1"
+version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
+checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
[[package]]
name = "syn"
diff --git a/datafusion/common/Cargo.toml b/datafusion/common/Cargo.toml
index 701cbdb515..441d723c4f 100644
--- a/datafusion/common/Cargo.toml
+++ b/datafusion/common/Cargo.toml
@@ -47,7 +47,7 @@ num_cpus = "1.13.0"
object_store = { version = "0.5.4", default-features = false, optional = true }
parquet = { workspace = true, optional = true }
pyo3 = { version = "0.18.0", optional = true }
-sqlparser = "0.33"
+sqlparser = "0.34"
[dev-dependencies]
rand = "0.8.4"
diff --git a/datafusion/core/Cargo.toml b/datafusion/core/Cargo.toml
index d0fb1d12a6..4f4fd4f8d1 100644
--- a/datafusion/core/Cargo.toml
+++ b/datafusion/core/Cargo.toml
@@ -85,7 +85,7 @@ percent-encoding = "2.2.0"
pin-project-lite = "^0.2.7"
rand = "0.8"
smallvec = { version = "1.6", features = ["union"] }
-sqlparser = { version = "0.33", features = ["visitor"] }
+sqlparser = { version = "0.34", features = ["visitor"] }
tempfile = "3"
tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync", "fs", "parking_lot"] }
tokio-stream = "0.1"
diff --git a/datafusion/core/tests/sqllogictests/test_files/groupby.slt b/datafusion/core/tests/sqllogictests/test_files/groupby.slt
index 106837348a..79520ff734 100644
--- a/datafusion/core/tests/sqllogictests/test_files/groupby.slt
+++ b/datafusion/core/tests/sqllogictests/test_files/groupby.slt
@@ -2091,7 +2091,7 @@ GRC [80.0, 30.0] 110
# Currently we do not support multiple ordering requirement for aggregation
# once this support is added. This test should change
# See issue: https://github.com/sqlparser-rs/sqlparser-rs/issues/875
-statement error DataFusion error: SQL error: ParserError\("Expected \), found: ,"\)
+statement error DataFusion error: This feature is not implemented: ARRAY_AGG only supports a single ORDER BY expression\. Got 2
SELECT s.country, ARRAY_AGG(s.amount ORDER BY s.amount DESC, s.country DESC) AS amounts,
SUM(s.amount ORDER BY s.amount DESC) AS sum1
FROM sales_global AS s
diff --git a/datafusion/core/tests/sqllogictests/test_files/union.slt b/datafusion/core/tests/sqllogictests/test_files/union.slt
index 4c5a5c8ed8..a031d7ef9e 100644
--- a/datafusion/core/tests/sqllogictests/test_files/union.slt
+++ b/datafusion/core/tests/sqllogictests/test_files/union.slt
@@ -472,4 +472,4 @@ UnionExec
--ProjectionExec: expr=[2 as a]
----EmptyExec: produce_one_row=true
--ProjectionExec: expr=[3 as a]
-----EmptyExec: produce_one_row=true
\ No newline at end of file
+----EmptyExec: produce_one_row=true
diff --git a/datafusion/expr/Cargo.toml b/datafusion/expr/Cargo.toml
index 17b318e3b6..b2d336a89d 100644
--- a/datafusion/expr/Cargo.toml
+++ b/datafusion/expr/Cargo.toml
@@ -38,7 +38,7 @@ path = "src/lib.rs"
ahash = { version = "0.8", default-features = false, features = ["runtime-rng"] }
arrow = { workspace = true }
datafusion-common = { path = "../common", version = "25.0.0" }
-sqlparser = "0.33"
+sqlparser = "0.34"
[dev-dependencies]
ctor = "0.2.0"
diff --git a/datafusion/expr/src/window_frame.rs b/datafusion/expr/src/window_frame.rs
index 97f767bfab..f48dd33930 100644
--- a/datafusion/expr/src/window_frame.rs
+++ b/datafusion/expr/src/window_frame.rs
@@ -238,11 +238,11 @@ pub fn convert_frame_bound_to_scalar_value(v: ast::Expr) -> Result<ScalarValue>
Ok(ScalarValue::Utf8(Some(match v {
ast::Expr::Value(ast::Value::Number(value, false))
| ast::Expr::Value(ast::Value::SingleQuotedString(value)) => value,
- ast::Expr::Interval {
+ ast::Expr::Interval(ast::Interval {
value,
leading_field,
..
- } => {
+ }) => {
let result = match *value {
ast::Expr::Value(ast::Value::SingleQuotedString(item)) => item,
e => {
diff --git a/datafusion/sql/Cargo.toml b/datafusion/sql/Cargo.toml
index 6a0a5a75c0..ffefe89440 100644
--- a/datafusion/sql/Cargo.toml
+++ b/datafusion/sql/Cargo.toml
@@ -42,7 +42,7 @@ arrow-schema = { workspace = true }
datafusion-common = { path = "../common", version = "25.0.0" }
datafusion-expr = { path = "../expr", version = "25.0.0" }
log = "^0.4"
-sqlparser = "0.33"
+sqlparser = "0.34"
[dev-dependencies]
ctor = "0.2.0"
diff --git a/datafusion/sql/src/expr/function.rs b/datafusion/sql/src/expr/function.rs
index 2bc3125d73..bf69c381cd 100644
--- a/datafusion/sql/src/expr/function.rs
+++ b/datafusion/sql/src/expr/function.rs
@@ -25,7 +25,7 @@ use datafusion_expr::{
WindowFunction,
};
use sqlparser::ast::{
- Expr as SQLExpr, Function as SQLFunction, FunctionArg, FunctionArgExpr,
+ Expr as SQLExpr, Function as SQLFunction, FunctionArg, FunctionArgExpr, WindowType,
};
use std::str::FromStr;
@@ -54,7 +54,19 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
};
// then, window function
- if let Some(window) = function.over.take() {
+ let window = function
+ .over
+ .take()
+ // TODO support named windows
+ .map(|window| match window {
+ WindowType::WindowSpec(window_spec) => Ok(window_spec),
+ WindowType::NamedWindow(name) => Err(DataFusionError::NotImplemented(
+ format!("Named windows ({name}) are not supported"),
+ )),
+ })
+ .transpose()?;
+
+ if let Some(window) = window {
let partition_by = window
.partition_by
.into_iter()
diff --git a/datafusion/sql/src/expr/mod.rs b/datafusion/sql/src/expr/mod.rs
index df0f3c54b6..05136a4a06 100644
--- a/datafusion/sql/src/expr/mod.rs
+++ b/datafusion/sql/src/expr/mod.rs
@@ -36,7 +36,7 @@ use datafusion_expr::{
col, expr, lit, AggregateFunction, Between, BinaryExpr, BuiltinScalarFunction, Cast,
Expr, ExprSchemable, GetIndexedField, Like, Operator, TryCast,
};
-use sqlparser::ast::{ArrayAgg, Expr as SQLExpr, TrimWhereField, Value};
+use sqlparser::ast::{ArrayAgg, Expr as SQLExpr, Interval, TrimWhereField, Value};
use sqlparser::parser::ParserError::ParserError;
impl<'a, S: ContextProvider> SqlToRel<'a, S> {
@@ -161,13 +161,13 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
))),
SQLExpr::Array(arr) => self.sql_array_literal(arr.elem, schema),
- SQLExpr::Interval {
+ SQLExpr::Interval(Interval {
value,
leading_field,
leading_precision,
last_field,
fractional_seconds_precision,
- } => self.sql_interval_to_expr(
+ }) => self.sql_interval_to_expr(
*value,
schema,
planner_context,
@@ -350,11 +350,25 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
within_group,
} = array_agg;
- let order_by = if let Some(order_by) = order_by {
+ let order_by = if let Some(mut order_by) = order_by {
// TODO: Once sqlparser supports multiple order by clause, handle it
// see issue: https://github.com/sqlparser-rs/sqlparser-rs/issues/875
+ let order_by = match order_by.len() {
+ 0 => {
+ return Err(DataFusionError::NotImplemented(
+ "ARRAY_AGG with empty ORDER BY not supported".to_string(),
+ ))
+ }
+ 1 => order_by.pop().unwrap(),
+ n => {
+ return Err(DataFusionError::NotImplemented(format!(
+ "ARRAY_AGG only supports a single ORDER BY expression. Got {n}"
+ )))
+ }
+ };
+
Some(vec![self.order_by_to_sort_expr(
- *order_by,
+ order_by,
input_schema,
planner_context,
)?])
diff --git a/datafusion/sql/src/select.rs b/datafusion/sql/src/select.rs
index 2da967a224..2acc2c7a8b 100644
--- a/datafusion/sql/src/select.rs
+++ b/datafusion/sql/src/select.rs
@@ -34,7 +34,7 @@ use datafusion_expr::{
CreateMemoryTable, DdlStatement, Expr, Filter, GroupingSet, LogicalPlan,
LogicalPlanBuilder, Partitioning,
};
-use sqlparser::ast::{Expr as SQLExpr, WildcardAdditionalOptions};
+use sqlparser::ast::{Distinct, Expr as SQLExpr, WildcardAdditionalOptions};
use sqlparser::ast::{Select, SelectItem, TableWithJoins};
use std::collections::HashSet;
use std::sync::Arc;
@@ -198,7 +198,18 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
let plan = project(plan, select_exprs_post_aggr)?;
// process distinct clause
- let plan = if select.distinct {
+ let distinct = select
+ .distinct
+ .map(|distinct| match distinct {
+ Distinct::Distinct => Ok(true),
+ Distinct::On(_) => Err(DataFusionError::NotImplemented(
+ "DISTINCT ON Exprs not supported".to_string(),
+ )),
+ })
+ .transpose()?
+ .unwrap_or(false);
+
+ let plan = if distinct {
LogicalPlanBuilder::from(plan).distinct()?.build()
} else {
Ok(plan)
diff --git a/datafusion/sql/src/statement.rs b/datafusion/sql/src/statement.rs
index bd9ca3ffa8..e5ee3d43d9 100644
--- a/datafusion/sql/src/statement.rs
+++ b/datafusion/sql/src/statement.rs
@@ -404,11 +404,18 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
}
Statement::Delete {
- table_name,
+ tables,
using,
selection,
returning,
+ from,
} => {
+ if !tables.is_empty() {
+ return Err(DataFusionError::NotImplemented(
+ "DELETE <TABLE> not supported".to_string(),
+ ));
+ }
+
if using.is_some() {
Err(DataFusionError::Plan(
"Using clause not supported".to_owned(),
@@ -419,6 +426,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
"Delete-returning clause not yet supported".to_owned(),
))?;
}
+ let table_name = self.get_delete_target(from)?;
self.delete_to_plan(table_name, selection)
}
@@ -493,6 +501,28 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
}
}
+ fn get_delete_target(&self, mut from: Vec<TableWithJoins>) -> Result<ObjectName> {
+ if from.len() != 1 {
+ return Err(DataFusionError::NotImplemented(format!(
+ "DELETE FROM only supports single table, got {}: {from:?}",
+ from.len()
+ )));
+ }
+ let table_factor = from.pop().unwrap();
+ if !table_factor.joins.is_empty() {
+ return Err(DataFusionError::NotImplemented(
+ "DELETE FROM only supports single table, got: joins".to_string(),
+ ));
+ }
+ let TableFactor::Table{name, ..} = table_factor.relation else {
+ return Err(DataFusionError::NotImplemented(format!(
+ "DELETE FROM only supports single table, got: {table_factor:?}"
+ )))
+ };
+
+ Ok(name)
+ }
+
/// Generate a logical plan from a "SHOW TABLES" query
fn show_tables_to_plan(
&self,
@@ -789,16 +819,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
fn delete_to_plan(
&self,
- table_factor: TableFactor,
+ table_name: ObjectName,
predicate_expr: Option<Expr>,
) -> Result<LogicalPlan> {
- let table_name = match &table_factor {
- TableFactor::Table { name, .. } => name.clone(),
- _ => Err(DataFusionError::Plan(
- "Cannot delete from non-table relations!".to_string(),
- ))?,
- };
-
// Do a table lookup to verify the table exists
let table_ref = self.object_name_to_table_reference(table_name.clone())?;
let provider = self.schema_provider.get_table_provider(table_ref.clone())?;