Skip to content

Commit a47e58c

Browse files
upgrade sqlparser 0.47 -> 0.48
1 parent dc21a6c commit a47e58c

30 files changed

+194
-631
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/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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use datafusion_expr::{
5252
TransactionConclusion, TransactionEnd, TransactionIsolationLevel, TransactionStart,
5353
Volatility, WriteOp,
5454
};
55-
use sqlparser::ast;
55+
use sqlparser::ast::{self, AssignmentTarget, CreateTable};
5656
use sqlparser::ast::{
5757
Assignment, ColumnDef, CreateTableOptions, Delete, DescribeAlias, Expr as SQLExpr,
5858
Expr, FromTable, Ident, Insert, ObjectName, ObjectType, OneOrManyWithParens, Query,
@@ -240,7 +240,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
240240
value,
241241
} => self.set_variable_to_plan(local, hivevar, &variables, value),
242242

243-
Statement::CreateTable {
243+
Statement::CreateTable(CreateTable {
244244
query,
245245
name,
246246
columns,
@@ -250,7 +250,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
250250
if_not_exists,
251251
or_replace,
252252
..
253-
} if table_properties.is_empty() && with_options.is_empty() => {
253+
}) if table_properties.is_empty() && with_options.is_empty() => {
254254
// Merge inline constraints and existing constraints
255255
let mut all_constraints = constraints;
256256
let inline_constraints = calc_inline_constraints_from_columns(&columns);
@@ -1284,8 +1284,12 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
12841284
let mut assign_map = assignments
12851285
.iter()
12861286
.map(|assign| {
1287-
let col_name: &Ident = assign
1288-
.id
1287+
let cols = match &assign.target {
1288+
AssignmentTarget::ColumnName(cols) => cols,
1289+
_ => plan_err!("Tuples are not supported")?,
1290+
};
1291+
let col_name: &Ident = cols
1292+
.0
12891293
.iter()
12901294
.last()
12911295
.ok_or_else(|| plan_datafusion_err!("Empty column id"))?;

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
@@ -175,6 +175,7 @@ impl Unparser<'_> {
175175
null_treatment: None,
176176
over: None,
177177
within_group: vec![],
178+
parameters: ast::FunctionArguments::None,
178179
}))
179180
}
180181
Expr::Between(Between {
@@ -305,6 +306,7 @@ impl Unparser<'_> {
305306
null_treatment: None,
306307
over,
307308
within_group: vec![],
309+
parameters: ast::FunctionArguments::None,
308310
}))
309311
}
310312
Expr::SimilarTo(Like {
@@ -350,6 +352,7 @@ impl Unparser<'_> {
350352
null_treatment: None,
351353
over: None,
352354
within_group: vec![],
355+
parameters: ast::FunctionArguments::None,
353356
}))
354357
}
355358
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)) => {

datafusion/sql/tests/sql_integration.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3627,7 +3627,7 @@ fn test_prepare_statement_to_plan_panic_prepare_wrong_syntax() {
36273627
let sql = "PREPARE AS SELECT id, age FROM person WHERE age = $foo";
36283628
assert_eq!(
36293629
logical_plan(sql).unwrap_err().strip_backtrace(),
3630-
"SQL error: ParserError(\"Expected AS, found: SELECT\")"
3630+
"SQL error: ParserError(\"Expected: AS, found: SELECT\")"
36313631
)
36323632
}
36333633

@@ -3668,7 +3668,7 @@ fn test_non_prepare_statement_should_infer_types() {
36683668

36693669
#[test]
36703670
#[should_panic(
3671-
expected = "value: SQL(ParserError(\"Expected [NOT] NULL or TRUE|FALSE or [NOT] DISTINCT FROM after IS, found: $1\""
3671+
expected = "value: SQL(ParserError(\"Expected: [NOT] NULL or TRUE|FALSE or [NOT] DISTINCT FROM after IS, found: $1\""
36723672
)]
36733673
fn test_prepare_statement_to_plan_panic_is_param() {
36743674
let sql = "PREPARE my_plan(INT) AS SELECT id, age FROM person WHERE age is $1";
@@ -4347,7 +4347,7 @@ fn test_parse_escaped_string_literal_value() {
43474347
let sql = r"SELECT character_length(E'\000') AS len";
43484348
assert_eq!(
43494349
logical_plan(sql).unwrap_err().strip_backtrace(),
4350-
"SQL error: TokenizerError(\"Unterminated encoded string literal at Line: 1, Column 25\")"
4350+
"SQL error: TokenizerError(\"Unterminated encoded string literal at Line: 1, Column: 25\")"
43514351
)
43524352
}
43534353

0 commit comments

Comments
 (0)