Skip to content

Commit 28fba58

Browse files
authored
chore: upgrade sqlparser (#17925)
* chore: upgrade sqlparser * chore: upgrade sqlparser * update
1 parent 8769d99 commit 28fba58

11 files changed

Lines changed: 84 additions & 18 deletions

File tree

‎Cargo.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ recursive = "0.1.1"
172172
regex = "1.11"
173173
rstest = "0.25.0"
174174
serde_json = "1"
175-
sqlparser = { version = "0.58.0", default-features = false, features = ["std", "visitor"] }
175+
sqlparser = { version = "0.59.0", default-features = false, features = ["std", "visitor"] }
176176
tempfile = "3"
177177
testcontainers = { version = "0.24", features = ["default"] }
178178
testcontainers-modules = { version = "0.12" }

‎datafusion/sql/src/expr/function.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ impl FunctionArgs {
182182
"Calling {name}: JSON NULL clause not supported in function arguments: {jn}"
183183
)
184184
}
185+
FunctionArgumentClause::JsonReturningClause(jr) => {
186+
return not_impl_err!(
187+
"Calling {name}: JSON RETURNING clause not supported in function arguments: {jr}"
188+
)
189+
},
185190
}
186191
}
187192

‎datafusion/sql/src/expr/mod.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use datafusion_expr::planner::{
2222
use sqlparser::ast::{
2323
AccessExpr, BinaryOperator, CastFormat, CastKind, DataType as SQLDataType,
2424
DictionaryField, Expr as SQLExpr, ExprWithAlias as SQLExprWithAlias, MapEntry,
25-
StructField, Subscript, TrimWhereField, Value, ValueWithSpan,
25+
StructField, Subscript, TrimWhereField, TypedString, Value, ValueWithSpan,
2626
};
2727

2828
use datafusion_common::{
@@ -291,7 +291,11 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
291291
)))
292292
}
293293

294-
SQLExpr::TypedString { data_type, value } => Ok(Expr::Cast(Cast::new(
294+
SQLExpr::TypedString(TypedString {
295+
data_type,
296+
value,
297+
uses_odbc_syntax: _,
298+
}) => Ok(Expr::Cast(Cast::new(
295299
Box::new(lit(value.into_string().unwrap())),
296300
self.convert_data_type(&data_type)?,
297301
))),

‎datafusion/sql/src/parser.rs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,9 @@ mod tests {
10761076
use super::*;
10771077
use datafusion_common::assert_contains;
10781078
use sqlparser::ast::Expr::Identifier;
1079-
use sqlparser::ast::{BinaryOperator, DataType, Expr, Ident, ValueWithSpan};
1079+
use sqlparser::ast::{
1080+
BinaryOperator, DataType, ExactNumberInfo, Expr, Ident, ValueWithSpan,
1081+
};
10801082
use sqlparser::dialect::SnowflakeDialect;
10811083
use sqlparser::tokenizer::Span;
10821084

@@ -1573,7 +1575,7 @@ mod tests {
15731575
name: name.clone(),
15741576
columns: vec![
15751577
make_column_def("c1", DataType::Int(None)),
1576-
make_column_def("c2", DataType::Float(None)),
1578+
make_column_def("c2", DataType::Float(ExactNumberInfo::None)),
15771579
],
15781580
file_type: "PARQUET".to_string(),
15791581
location: "foo.parquet".into(),
@@ -1641,7 +1643,7 @@ mod tests {
16411643
name: name.clone(),
16421644
columns: vec![
16431645
make_column_def("c1", DataType::Int(None)),
1644-
make_column_def("c2", DataType::Float(None)),
1646+
make_column_def("c2", DataType::Float(ExactNumberInfo::None)),
16451647
],
16461648
file_type: "PARQUET".to_string(),
16471649
location: "foo.parquet".into(),

‎datafusion/sql/src/planner.rs‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,10 +720,15 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
720720
(Some(precision), Some(scale))
721721
}
722722
};
723-
make_decimal_type(precision, scale)
723+
make_decimal_type(precision, scale.map(|s| s as u64))
724724
}
725725
SQLDataType::Bytea => Ok(DataType::Binary),
726-
SQLDataType::Interval => Ok(DataType::Interval(IntervalUnit::MonthDayNano)),
726+
SQLDataType::Interval { fields, precision } => {
727+
if fields.is_some() || precision.is_some() {
728+
return not_impl_err!("Unsupported SQL type {sql_type}");
729+
}
730+
Ok(DataType::Interval(IntervalUnit::MonthDayNano))
731+
}
727732
SQLDataType::Struct(fields, _) => {
728733
let fields = fields
729734
.iter()
@@ -818,7 +823,14 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
818823
| SQLDataType::NamedTable { .. }
819824
| SQLDataType::TsVector
820825
| SQLDataType::TsQuery
821-
| SQLDataType::GeometricType(_) => {
826+
| SQLDataType::GeometricType(_)
827+
| SQLDataType::DecimalUnsigned(_) // deprecated mysql type
828+
| SQLDataType::FloatUnsigned(_) // deprecated mysql type
829+
| SQLDataType::RealUnsigned // deprecated mysql type
830+
| SQLDataType::DecUnsigned(_) // deprecated mysql type
831+
| SQLDataType::DoubleUnsigned(_) // deprecated mysql type
832+
| SQLDataType::DoublePrecisionUnsigned // deprecated mysql type
833+
=> {
822834
not_impl_err!("Unsupported SQL type {sql_type}")
823835
}
824836
}

‎datafusion/sql/src/query.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ pub(crate) fn to_order_by_exprs_with_select(
390390
quote_style: None,
391391
span: Span::empty(),
392392
}),
393-
options: order_by_options.clone(),
393+
options: order_by_options,
394394
with_fill: None,
395395
}),
396396
// TODO: Support other types of expressions

‎datafusion/sql/src/relation/join.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
9595
JoinOperator::FullOuter(constraint) => {
9696
self.parse_join(left, right, constraint, JoinType::Full, planner_context)
9797
}
98-
JoinOperator::CrossJoin => self.parse_cross_join(left, right),
98+
JoinOperator::CrossJoin(JoinConstraint::None) => {
99+
self.parse_cross_join(left, right)
100+
}
99101
other => not_impl_err!("Unsupported JOIN operator {other:?}"),
100102
}
101103
}

‎datafusion/sql/src/statement.rs‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,13 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
302302
storage_serialization_policy,
303303
inherits,
304304
table_options: CreateTableOptions::None,
305+
dynamic,
306+
version,
307+
target_lag,
308+
warehouse,
309+
refresh_mode,
310+
initialize,
311+
require_user,
305312
}) => {
306313
if temporary {
307314
return not_impl_err!("Temporary tables not supported")?;
@@ -428,7 +435,27 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
428435
if inherits.is_some() {
429436
return not_impl_err!("Table inheritance not supported")?;
430437
}
431-
438+
if dynamic {
439+
return not_impl_err!("Dynamic tables not supported")?;
440+
}
441+
if version.is_some() {
442+
return not_impl_err!("Version not supported")?;
443+
}
444+
if target_lag.is_some() {
445+
return not_impl_err!("Target lag not supported")?;
446+
}
447+
if warehouse.is_some() {
448+
return not_impl_err!("Warehouse not supported")?;
449+
}
450+
if refresh_mode.is_some() {
451+
return not_impl_err!("Refresh mode not supported")?;
452+
}
453+
if initialize.is_some() {
454+
return not_impl_err!("Initialize not supported")?;
455+
}
456+
if require_user {
457+
return not_impl_err!("Require user not supported")?;
458+
}
432459
// Merge inline constraints and existing constraints
433460
let mut all_constraints = constraints;
434461
let inline_constraints = calc_inline_constraints_from_columns(&columns);
@@ -534,6 +561,8 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
534561
to,
535562
params,
536563
or_alter,
564+
secure,
565+
name_before_not_exists,
537566
} => {
538567
if materialized {
539568
return not_impl_err!("Materialized views not supported")?;
@@ -571,6 +600,8 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
571600
to,
572601
params,
573602
or_alter,
603+
secure,
604+
name_before_not_exists,
574605
};
575606
let sql = stmt.to_string();
576607
let Statement::CreateView {
@@ -975,6 +1006,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
9751006
selection,
9761007
returning,
9771008
or,
1009+
limit,
9781010
} => {
9791011
let from_clauses =
9801012
from.map(|update_table_from_kind| match update_table_from_kind {
@@ -992,6 +1024,9 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
9921024
if or.is_some() {
9931025
plan_err!("ON conflict not supported")?;
9941026
}
1027+
if limit.is_some() {
1028+
return not_impl_err!("Update-limit clause not supported")?;
1029+
}
9951030
self.update_to_plan(table, assignments, update_from, selection)
9961031
}
9971032

‎datafusion/sql/src/unparser/expr.rs‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ impl Unparser<'_> {
16891689
DataType::Float16 => {
16901690
not_impl_err!("Unsupported DataType: conversion: {data_type}")
16911691
}
1692-
DataType::Float32 => Ok(ast::DataType::Float(None)),
1692+
DataType::Float32 => Ok(ast::DataType::Float(ast::ExactNumberInfo::None)),
16931693
DataType::Float64 => Ok(self.dialect.float64_ast_dtype()),
16941694
DataType::Timestamp(time_unit, tz) => {
16951695
Ok(self.dialect.timestamp_cast_dtype(time_unit, tz))
@@ -1705,7 +1705,10 @@ impl Unparser<'_> {
17051705
DataType::Duration(_) => {
17061706
not_impl_err!("Unsupported DataType: conversion: {data_type}")
17071707
}
1708-
DataType::Interval(_) => Ok(ast::DataType::Interval),
1708+
DataType::Interval(_) => Ok(ast::DataType::Interval {
1709+
fields: None,
1710+
precision: None,
1711+
}),
17091712
DataType::Binary => {
17101713
not_impl_err!("Unsupported DataType: conversion: {data_type}")
17111714
}
@@ -1755,7 +1758,10 @@ impl Unparser<'_> {
17551758
}
17561759

17571760
Ok(ast::DataType::Decimal(
1758-
ast::ExactNumberInfo::PrecisionAndScale(new_precision, new_scale),
1761+
ast::ExactNumberInfo::PrecisionAndScale(
1762+
new_precision,
1763+
new_scale as i64,
1764+
),
17591765
))
17601766
}
17611767
DataType::Map(_, _) => {

0 commit comments

Comments
 (0)