Skip to content

Commit 382bf4f

Browse files
upgrade sqlparser 0.47 -> 0.48 (#11453)
* upgrade sqlparser 0.47 -> 0.48 * clean imports and qualified imports * update df-cli cargo lock * fix trailing commas in slt tests * update slt tests results * restore rowsort in slt tests * fix slt tests * rerun CI * reset unchanged slt files * Revert "clean imports and qualified imports" This reverts commit 7be2263. * update non-windows systems stack size * update windows stack size * remove windows-only unused import * use same test main for all systems * Reapply "clean imports and qualified imports" This reverts commit 4fc036a.
1 parent c54a638 commit 382bf4f

32 files changed

+123
-105
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ rand = "0.8"
123123
regex = "1.8"
124124
rstest = "0.21.0"
125125
serde_json = "1"
126-
sqlparser = { version = "0.47", features = ["visitor"] }
126+
sqlparser = { version = "0.48", features = ["visitor"] }
127127
tempfile = "3"
128128
thiserror = "1.0.44"
129129
tokio = { version = "1.36", features = ["macros", "rt", "sync"] }

datafusion-cli/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.

datafusion/sql/src/expr/function.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ impl FunctionArgs {
109109
filter,
110110
mut null_treatment,
111111
within_group,
112+
..
112113
} = function;
113114

114115
// Handle no argument form (aka `current_time` as opposed to `current_time()`)

datafusion/sql/src/parser.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,14 +1006,15 @@ mod tests {
10061006
expect_parse_ok(sql, expected)?;
10071007

10081008
// positive case: it is ok for sql stmt with `COMPRESSION TYPE GZIP` tokens
1009-
let sqls = vec![
1010-
("CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV LOCATION 'foo.csv' OPTIONS
1009+
let sqls =
1010+
vec![
1011+
("CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV LOCATION 'foo.csv' OPTIONS
10111012
('format.compression' 'GZIP')", "GZIP"),
1012-
("CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV LOCATION 'foo.csv' OPTIONS
1013+
("CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV LOCATION 'foo.csv' OPTIONS
10131014
('format.compression' 'BZIP2')", "BZIP2"),
1014-
("CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV LOCATION 'foo.csv' OPTIONS
1015+
("CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV LOCATION 'foo.csv' OPTIONS
10151016
('format.compression' 'XZ')", "XZ"),
1016-
("CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV LOCATION 'foo.csv' OPTIONS
1017+
("CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV LOCATION 'foo.csv' OPTIONS
10171018
('format.compression' 'ZSTD')", "ZSTD"),
10181019
];
10191020
for (sql, compression) in sqls {
@@ -1123,7 +1124,10 @@ mod tests {
11231124
// negative case: mixed column defs and column names in `PARTITIONED BY` clause
11241125
let sql =
11251126
"CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV PARTITIONED BY (p1 int, c1) LOCATION 'foo.csv'";
1126-
expect_parse_error(sql, "sql parser error: Expected a data type name, found: )");
1127+
expect_parse_error(
1128+
sql,
1129+
"sql parser error: Expected: a data type name, found: )",
1130+
);
11271131

11281132
// negative case: mixed column defs and column names in `PARTITIONED BY` clause
11291133
let sql =
@@ -1291,7 +1295,7 @@ mod tests {
12911295
LOCATION 'foo.parquet'
12921296
OPTIONS ('format.compression' 'zstd',
12931297
'format.delimiter' '*',
1294-
'ROW_GROUP_SIZE' '1024',
1298+
'ROW_GROUP_SIZE' '1024',
12951299
'TRUNCATE' 'NO',
12961300
'format.has_header' 'true')";
12971301
let expected = Statement::CreateExternalTable(CreateExternalTable {

datafusion/sql/src/planner.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,27 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
468468
| SQLDataType::Float64
469469
| SQLDataType::JSONB
470470
| SQLDataType::Unspecified
471+
// Clickhouse datatypes
472+
| SQLDataType::Int16
473+
| SQLDataType::Int32
474+
| SQLDataType::Int128
475+
| SQLDataType::Int256
476+
| SQLDataType::UInt8
477+
| SQLDataType::UInt16
478+
| SQLDataType::UInt32
479+
| SQLDataType::UInt64
480+
| SQLDataType::UInt128
481+
| SQLDataType::UInt256
482+
| SQLDataType::Float32
483+
| SQLDataType::Date32
484+
| SQLDataType::Datetime64(_, _)
485+
| SQLDataType::FixedString(_)
486+
| SQLDataType::Map(_, _)
487+
| SQLDataType::Tuple(_)
488+
| SQLDataType::Nested(_)
489+
| SQLDataType::Union(_)
490+
| SQLDataType::Nullable(_)
491+
| SQLDataType::LowCardinality(_)
471492
=> not_impl_err!(
472493
"Unsupported SQL type {sql_type:?}"
473494
),

datafusion/sql/src/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
149149
let aggr_exprs = find_aggregate_exprs(&aggr_expr_haystack);
150150

151151
// All of the group by expressions
152-
let group_by_exprs = if let GroupByExpr::Expressions(exprs) = select.group_by {
152+
let group_by_exprs = if let GroupByExpr::Expressions(exprs, _) = select.group_by {
153153
exprs
154154
.into_iter()
155155
.map(|e| {

datafusion/sql/src/statement.rs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,19 @@ use datafusion_expr::{
4646
cast, col, Analyze, CreateCatalog, CreateCatalogSchema,
4747
CreateExternalTable as PlanCreateExternalTable, CreateFunction, CreateFunctionBody,
4848
CreateMemoryTable, CreateView, DescribeTable, DmlStatement, DropCatalogSchema,
49-
DropFunction, DropTable, DropView, EmptyRelation, Explain, ExprSchemable, Filter,
50-
LogicalPlan, LogicalPlanBuilder, OperateFunctionArg, PlanType, Prepare, SetVariable,
51-
Statement as PlanStatement, ToStringifiedPlan, TransactionAccessMode,
49+
DropFunction, DropTable, DropView, EmptyRelation, Explain, Expr, ExprSchemable,
50+
Filter, LogicalPlan, LogicalPlanBuilder, OperateFunctionArg, PlanType, Prepare,
51+
SetVariable, Statement as PlanStatement, ToStringifiedPlan, TransactionAccessMode,
5252
TransactionConclusion, TransactionEnd, TransactionIsolationLevel, TransactionStart,
5353
Volatility, WriteOp,
5454
};
5555
use sqlparser::ast;
5656
use sqlparser::ast::{
57-
Assignment, ColumnDef, CreateTableOptions, Delete, DescribeAlias, Expr as SQLExpr,
58-
Expr, FromTable, Ident, Insert, ObjectName, ObjectType, OneOrManyWithParens, Query,
59-
SchemaName, SetExpr, ShowCreateObject, ShowStatementFilter, Statement,
60-
TableConstraint, TableFactor, TableWithJoins, TransactionMode, UnaryOperator, Value,
57+
Assignment, AssignmentTarget, ColumnDef, CreateTable, CreateTableOptions, Delete,
58+
DescribeAlias, Expr as SQLExpr, FromTable, Ident, Insert, ObjectName, ObjectType,
59+
OneOrManyWithParens, Query, SchemaName, SetExpr, ShowCreateObject,
60+
ShowStatementFilter, Statement, TableConstraint, TableFactor, TableWithJoins,
61+
TransactionMode, UnaryOperator, Value,
6162
};
6263
use sqlparser::parser::ParserError::ParserError;
6364

@@ -240,7 +241,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
240241
value,
241242
} => self.set_variable_to_plan(local, hivevar, &variables, value),
242243

243-
Statement::CreateTable {
244+
Statement::CreateTable(CreateTable {
244245
query,
245246
name,
246247
columns,
@@ -250,7 +251,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
250251
if_not_exists,
251252
or_replace,
252253
..
253-
} if table_properties.is_empty() && with_options.is_empty() => {
254+
}) if table_properties.is_empty() && with_options.is_empty() => {
254255
// Merge inline constraints and existing constraints
255256
let mut all_constraints = constraints;
256257
let inline_constraints = calc_inline_constraints_from_columns(&columns);
@@ -954,7 +955,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
954955
order_exprs: Vec<LexOrdering>,
955956
schema: &DFSchemaRef,
956957
planner_context: &mut PlannerContext,
957-
) -> Result<Vec<Vec<datafusion_expr::Expr>>> {
958+
) -> Result<Vec<Vec<Expr>>> {
958959
// Ask user to provide a schema if schema is empty.
959960
if !order_exprs.is_empty() && schema.fields().is_empty() {
960961
return plan_err!(
@@ -1159,7 +1160,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
11591160
local: bool,
11601161
hivevar: bool,
11611162
variables: &OneOrManyWithParens<ObjectName>,
1162-
value: Vec<Expr>,
1163+
value: Vec<SQLExpr>,
11631164
) -> Result<LogicalPlan> {
11641165
if local {
11651166
return not_impl_err!("LOCAL is not supported");
@@ -1218,7 +1219,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
12181219
fn delete_to_plan(
12191220
&self,
12201221
table_name: ObjectName,
1221-
predicate_expr: Option<Expr>,
1222+
predicate_expr: Option<SQLExpr>,
12221223
) -> Result<LogicalPlan> {
12231224
// Do a table lookup to verify the table exists
12241225
let table_ref = self.object_name_to_table_reference(table_name.clone())?;
@@ -1264,7 +1265,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
12641265
table: TableWithJoins,
12651266
assignments: Vec<Assignment>,
12661267
from: Option<TableWithJoins>,
1267-
predicate_expr: Option<Expr>,
1268+
predicate_expr: Option<SQLExpr>,
12681269
) -> Result<LogicalPlan> {
12691270
let (table_name, table_alias) = match &table.relation {
12701271
TableFactor::Table { name, alias, .. } => (name.clone(), alias.clone()),
@@ -1284,16 +1285,20 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
12841285
let mut assign_map = assignments
12851286
.iter()
12861287
.map(|assign| {
1287-
let col_name: &Ident = assign
1288-
.id
1288+
let cols = match &assign.target {
1289+
AssignmentTarget::ColumnName(cols) => cols,
1290+
_ => plan_err!("Tuples are not supported")?,
1291+
};
1292+
let col_name: &Ident = cols
1293+
.0
12891294
.iter()
12901295
.last()
12911296
.ok_or_else(|| plan_datafusion_err!("Empty column id"))?;
12921297
// Validate that the assignment target column exists
12931298
table_schema.field_with_unqualified_name(&col_name.value)?;
12941299
Ok((col_name.value.clone(), assign.value.clone()))
12951300
})
1296-
.collect::<Result<HashMap<String, Expr>>>()?;
1301+
.collect::<Result<HashMap<String, SQLExpr>>>()?;
12971302

12981303
// Build scan, join with from table if it exists.
12991304
let mut input_tables = vec![table];
@@ -1332,8 +1337,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
13321337
&mut planner_context,
13331338
)?;
13341339
// Update placeholder's datatype to the type of the target column
1335-
if let datafusion_expr::Expr::Placeholder(placeholder) = &mut expr
1336-
{
1340+
if let Expr::Placeholder(placeholder) = &mut expr {
13371341
placeholder.data_type = placeholder
13381342
.data_type
13391343
.take()
@@ -1345,14 +1349,12 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
13451349
None => {
13461350
// If the target table has an alias, use it to qualify the column name
13471351
if let Some(alias) = &table_alias {
1348-
datafusion_expr::Expr::Column(Column::new(
1352+
Expr::Column(Column::new(
13491353
Some(self.normalizer.normalize(alias.name.clone())),
13501354
field.name(),
13511355
))
13521356
} else {
1353-
datafusion_expr::Expr::Column(Column::from((
1354-
qualifier, field,
1355-
)))
1357+
Expr::Column(Column::from((qualifier, field)))
13561358
}
13571359
}
13581360
};
@@ -1427,7 +1429,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
14271429
if let SetExpr::Values(ast::Values { rows, .. }) = (*source.body).clone() {
14281430
for row in rows.iter() {
14291431
for (idx, val) in row.iter().enumerate() {
1430-
if let ast::Expr::Value(Value::Placeholder(name)) = val {
1432+
if let SQLExpr::Value(Value::Placeholder(name)) = val {
14311433
let name =
14321434
name.replace('$', "").parse::<usize>().map_err(|_| {
14331435
plan_datafusion_err!("Can't parse placeholder: {name}")
@@ -1460,23 +1462,23 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
14601462
.map(|(i, value_index)| {
14611463
let target_field = table_schema.field(i);
14621464
let expr = match value_index {
1463-
Some(v) => datafusion_expr::Expr::Column(Column::from(
1464-
source.schema().qualified_field(v),
1465-
))
1466-
.cast_to(target_field.data_type(), source.schema())?,
1465+
Some(v) => {
1466+
Expr::Column(Column::from(source.schema().qualified_field(v)))
1467+
.cast_to(target_field.data_type(), source.schema())?
1468+
}
14671469
// The value is not specified. Fill in the default value for the column.
14681470
None => table_source
14691471
.get_column_default(target_field.name())
14701472
.cloned()
14711473
.unwrap_or_else(|| {
14721474
// If there is no default for the column, then the default is NULL
1473-
datafusion_expr::Expr::Literal(ScalarValue::Null)
1475+
Expr::Literal(ScalarValue::Null)
14741476
})
14751477
.cast_to(target_field.data_type(), &DFSchema::empty())?,
14761478
};
14771479
Ok(expr.alias(target_field.name()))
14781480
})
1479-
.collect::<Result<Vec<datafusion_expr::Expr>>>()?;
1481+
.collect::<Result<Vec<Expr>>>()?;
14801482
let source = project(source, exprs)?;
14811483

14821484
let op = if overwrite {

datafusion/sql/src/unparser/ast.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ impl QueryBuilder {
9393
fetch: self.fetch.clone(),
9494
locks: self.locks.clone(),
9595
for_clause: self.for_clause.clone(),
96+
settings: None,
97+
format_clause: None,
9698
})
9799
}
98100
fn create_empty() -> Self {
@@ -234,6 +236,7 @@ impl SelectBuilder {
234236
value_table_mode: self.value_table_mode,
235237
connect_by: None,
236238
window_before_qualify: false,
239+
prewhere: None,
237240
})
238241
}
239242
fn create_empty() -> Self {
@@ -245,7 +248,7 @@ impl SelectBuilder {
245248
from: Default::default(),
246249
lateral_views: Default::default(),
247250
selection: Default::default(),
248-
group_by: Some(ast::GroupByExpr::Expressions(Vec::new())),
251+
group_by: Some(ast::GroupByExpr::Expressions(Vec::new(), Vec::new())),
249252
cluster_by: Default::default(),
250253
distribute_by: Default::default(),
251254
sort_by: Default::default(),

datafusion/sql/src/unparser/expr.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ impl Unparser<'_> {
176176
null_treatment: None,
177177
over: None,
178178
within_group: vec![],
179+
parameters: ast::FunctionArguments::None,
179180
}))
180181
}
181182
Expr::Between(Between {
@@ -306,6 +307,7 @@ impl Unparser<'_> {
306307
null_treatment: None,
307308
over,
308309
within_group: vec![],
310+
parameters: ast::FunctionArguments::None,
309311
}))
310312
}
311313
Expr::SimilarTo(Like {
@@ -351,6 +353,7 @@ impl Unparser<'_> {
351353
null_treatment: None,
352354
over: None,
353355
within_group: vec![],
356+
parameters: ast::FunctionArguments::None,
354357
}))
355358
}
356359
Expr::ScalarSubquery(subq) => {

datafusion/sql/src/unparser/plan.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ impl Unparser<'_> {
172172
.iter()
173173
.map(|expr| self.expr_to_sql(expr))
174174
.collect::<Result<Vec<_>>>()?,
175+
vec![],
175176
));
176177
}
177178
Some(AggVariant::Window(window)) => {

0 commit comments

Comments
 (0)