Skip to content

Commit bb4dbe4

Browse files
committed
chore(deps): Update sqlparser to 0.60
Signed-off-by: StandingMan <jmtangcs@gmail.com>
1 parent 1f654bb commit bb4dbe4

8 files changed

Lines changed: 50 additions & 101 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 4 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
@@ -181,7 +181,7 @@ recursive = "0.1.1"
181181
regex = "1.12"
182182
rstest = "0.26.1"
183183
serde_json = "1"
184-
sqlparser = { version = "0.59.0", default-features = false, features = ["std", "visitor"] }
184+
sqlparser = { version = "0.60.0", default-features = false, features = ["std", "visitor"] }
185185
strum = "0.27.2"
186186
strum_macros = "0.27.2"
187187
tempfile = "3"

datafusion/expr/src/expr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use datafusion_functions_window_common::field::WindowUDFFieldArgs;
4242
#[cfg(feature = "sql")]
4343
use sqlparser::ast::{
4444
ExceptSelectItem, ExcludeSelectItem, IlikeSelectItem, RenameSelectItem,
45-
ReplaceSelectElement, display_comma_separated,
45+
ReplaceSelectElement,
4646
};
4747

4848
// Moved in 51.0.0 to datafusion_common
@@ -1403,7 +1403,9 @@ pub struct PlannedReplaceSelectItem {
14031403
impl Display for PlannedReplaceSelectItem {
14041404
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
14051405
write!(f, "REPLACE")?;
1406-
write!(f, " ({})", display_comma_separated(&self.items))?;
1406+
for item in &self.items {
1407+
write!(f, " ({item})")?;
1408+
}
14071409
Ok(())
14081410
}
14091411
}

datafusion/sql/src/planner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
823823
| SQLDataType::HugeInt
824824
| SQLDataType::UHugeInt
825825
| SQLDataType::UBigInt
826-
| SQLDataType::TimestampNtz
826+
| SQLDataType::TimestampNtz{..}
827827
| SQLDataType::NamedTable { .. }
828828
| SQLDataType::TsVector
829829
| SQLDataType::TsQuery

datafusion/sql/src/query.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
170170
name: alias,
171171
// Apply to all fields
172172
columns: vec![],
173+
explicit: true,
173174
},
174175
),
175176
PipeOperator::Union {

datafusion/sql/src/statement.rs

Lines changed: 37 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ use datafusion_expr::{
5555
TransactionIsolationLevel, TransactionStart, Volatility, WriteOp, cast, col,
5656
};
5757
use sqlparser::ast::{
58-
self, BeginTransactionKind, IndexColumn, IndexType, NullsDistinctOption, OrderByExpr,
59-
OrderByOptions, Set, ShowStatementIn, ShowStatementOptions, SqliteOnConflict,
60-
TableObject, UpdateTableFromKind, ValueWithSpan,
58+
self, BeginTransactionKind, IndexColumn, IndexType, OrderByExpr, Set,
59+
ShowStatementIn, ShowStatementOptions, SqliteOnConflict, TableObject, Update,
60+
UpdateTableFromKind, ValueWithSpan,
6161
};
6262
use sqlparser::ast::{
6363
Assignment, AssignmentTarget, ColumnDef, CreateIndex, CreateTable,
@@ -102,78 +102,22 @@ fn get_schema_name(schema_name: &SchemaName) -> String {
102102
/// Construct `TableConstraint`(s) for the given columns by iterating over
103103
/// `columns` and extracting individual inline constraint definitions.
104104
fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConstraint> {
105-
let mut constraints = vec![];
105+
let mut constraints: Vec<TableConstraint> = vec![];
106106
for column in columns {
107-
for ast::ColumnOptionDef { name, option } in &column.options {
107+
for ast::ColumnOptionDef { name: _, option } in &column.options {
108108
match option {
109-
ast::ColumnOption::Unique {
110-
is_primary: false,
111-
characteristics,
112-
} => constraints.push(TableConstraint::Unique {
113-
name: name.clone(),
114-
columns: vec![IndexColumn {
115-
column: OrderByExpr {
116-
expr: SQLExpr::Identifier(column.name.clone()),
117-
options: OrderByOptions {
118-
asc: None,
119-
nulls_first: None,
120-
},
121-
with_fill: None,
122-
},
123-
operator_class: None,
124-
}],
125-
characteristics: *characteristics,
126-
index_name: None,
127-
index_type_display: ast::KeyOrIndexDisplay::None,
128-
index_type: None,
129-
index_options: vec![],
130-
nulls_distinct: NullsDistinctOption::None,
131-
}),
132-
ast::ColumnOption::Unique {
133-
is_primary: true,
134-
characteristics,
135-
} => constraints.push(TableConstraint::PrimaryKey {
136-
name: name.clone(),
137-
columns: vec![IndexColumn {
138-
column: OrderByExpr {
139-
expr: SQLExpr::Identifier(column.name.clone()),
140-
options: OrderByOptions {
141-
asc: None,
142-
nulls_first: None,
143-
},
144-
with_fill: None,
145-
},
146-
operator_class: None,
147-
}],
148-
characteristics: *characteristics,
149-
index_name: None,
150-
index_type: None,
151-
index_options: vec![],
152-
}),
153-
ast::ColumnOption::ForeignKey {
154-
foreign_table,
155-
referred_columns,
156-
on_delete,
157-
on_update,
158-
characteristics,
159-
} => constraints.push(TableConstraint::ForeignKey {
160-
name: name.clone(),
161-
columns: vec![],
162-
foreign_table: foreign_table.clone(),
163-
referred_columns: referred_columns.to_vec(),
164-
on_delete: *on_delete,
165-
on_update: *on_update,
166-
characteristics: *characteristics,
167-
index_name: None,
168-
}),
109+
ast::ColumnOption::Unique(constraint) => {
110+
constraints.push(TableConstraint::Unique(constraint.clone()))
111+
}
112+
ast::ColumnOption::PrimaryKey(constraint) => {
113+
constraints.push(TableConstraint::PrimaryKey(constraint.clone()))
114+
}
115+
ast::ColumnOption::ForeignKey(constraint) => {
116+
constraints.push(TableConstraint::ForeignKey(constraint.clone()))
117+
}
169118
ast::ColumnOption::Check(expr) => {
170-
constraints.push(TableConstraint::Check {
171-
name: name.clone(),
172-
expr: Box::new(expr.clone()),
173-
enforced: None,
174-
})
119+
constraints.push(TableConstraint::Check(expr.clone()))
175120
}
176-
// Other options are not constraint related.
177121
ast::ColumnOption::Default(_)
178122
| ast::ColumnOption::Null
179123
| ast::ColumnOption::NotNull
@@ -191,7 +135,8 @@ fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConst
191135
| ast::ColumnOption::Tags(_)
192136
| ast::ColumnOption::Alias(_)
193137
| ast::ColumnOption::Srid(_)
194-
| ast::ColumnOption::Collation(_) => {}
138+
| ast::ColumnOption::Collation(_)
139+
| ast::ColumnOption::Invisible => {}
195140
}
196141
}
197142
}
@@ -557,7 +502,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
557502
}
558503
}
559504
}
560-
Statement::CreateView {
505+
Statement::CreateView(ast::CreateView {
561506
or_replace,
562507
materialized,
563508
name,
@@ -574,7 +519,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
574519
or_alter,
575520
secure,
576521
name_before_not_exists,
577-
} => {
522+
}) => {
578523
if materialized {
579524
return not_impl_err!("Materialized views not supported")?;
580525
}
@@ -596,7 +541,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
596541

597542
// put the statement back together temporarily to get the SQL
598543
// string representation
599-
let stmt = Statement::CreateView {
544+
let stmt = Statement::CreateView(ast::CreateView {
600545
or_replace,
601546
materialized,
602547
name,
@@ -613,16 +558,16 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
613558
or_alter,
614559
secure,
615560
name_before_not_exists,
616-
};
561+
});
617562
let sql = stmt.to_string();
618-
let Statement::CreateView {
563+
let Statement::CreateView(ast::CreateView {
619564
name,
620565
columns,
621566
query,
622567
or_replace,
623568
temporary,
624569
..
625-
} = stmt
570+
}) = stmt
626571
else {
627572
return internal_err!("Unreachable code in create view");
628573
};
@@ -965,6 +910,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
965910
has_table_keyword,
966911
settings,
967912
format_clause,
913+
..
968914
}) => {
969915
let table_name = match table {
970916
TableObject::TableName(table_name) => table_name,
@@ -1025,15 +971,16 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
1025971
let _ = has_table_keyword;
1026972
self.insert_to_plan(table_name, columns, source, overwrite, replace_into)
1027973
}
1028-
Statement::Update {
974+
Statement::Update(Update {
1029975
table,
1030976
assignments,
1031977
from,
1032978
selection,
1033979
returning,
1034980
or,
1035981
limit,
1036-
} => {
982+
..
983+
}) => {
1037984
let from_clauses =
1038985
from.map(|update_table_from_kind| match update_table_from_kind {
1039986
UpdateTableFromKind::BeforeSet(from_clauses) => from_clauses,
@@ -1064,6 +1011,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
10641011
from,
10651012
order_by,
10661013
limit,
1014+
..
10671015
}) => {
10681016
if !tables.is_empty() {
10691017
plan_err!("DELETE <TABLE> not supported")?;
@@ -1295,7 +1243,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
12951243
let function_body = match function_body {
12961244
Some(r) => Some(self.sql_to_expr(
12971245
match r {
1298-
ast::CreateFunctionBody::AsBeforeOptions(expr) => expr,
1246+
ast::CreateFunctionBody::AsBeforeOptions{body: expr, ..} => expr,
12991247
ast::CreateFunctionBody::AsAfterOptions(expr) => expr,
13001248
ast::CreateFunctionBody::Return(expr) => expr,
13011249
ast::CreateFunctionBody::AsBeginEnd(_) => {
@@ -1338,22 +1286,18 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
13381286

13391287
Ok(LogicalPlan::Ddl(statement))
13401288
}
1341-
Statement::DropFunction {
1342-
if_exists,
1343-
func_desc,
1344-
..
1345-
} => {
1289+
Statement::DropFunction(func) => {
13461290
// According to postgresql documentation it can be only one function
13471291
// specified in drop statement
1348-
if let Some(desc) = func_desc.first() {
1292+
if let Some(desc) = func.func_desc.first() {
13491293
// At the moment functions can't be qualified `schema.name`
13501294
let name = match &desc.name.0[..] {
13511295
[] => exec_err!("Function should have name")?,
13521296
[n] => n.as_ident().unwrap().value.clone(),
13531297
[..] => not_impl_err!("Qualified functions are not supported")?,
13541298
};
13551299
let statement = DdlStatement::DropFunction(DropFunction {
1356-
if_exists,
1300+
if_exists: func.if_exists,
13571301
name,
13581302
schema: DFSchemaRef::new(DFSchema::empty()),
13591303
});
@@ -1716,24 +1660,24 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
17161660
let constraints = constraints
17171661
.iter()
17181662
.map(|c: &TableConstraint| match c {
1719-
TableConstraint::Unique { name, columns, .. } => {
1720-
let constraint_name = match name {
1663+
TableConstraint::Unique(constraint) => {
1664+
let constraint_name = match &constraint.name {
17211665
Some(name) => &format!("unique constraint with name '{name}'"),
17221666
None => "unique constraint",
17231667
};
17241668
// Get unique constraint indices in the schema
17251669
let indices = self.get_constraint_column_indices(
17261670
df_schema,
1727-
columns,
1671+
&constraint.columns,
17281672
constraint_name,
17291673
)?;
17301674
Ok(Constraint::Unique(indices))
17311675
}
1732-
TableConstraint::PrimaryKey { columns, .. } => {
1676+
TableConstraint::PrimaryKey(constraint) => {
17331677
// Get primary key indices in the schema
17341678
let indices = self.get_constraint_column_indices(
17351679
df_schema,
1736-
columns,
1680+
&constraint.columns,
17371681
"primary key",
17381682
)?;
17391683
Ok(Constraint::PrimaryKey(indices))

datafusion/sql/src/unparser/plan.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,7 @@ impl Unparser<'_> {
13951395
ast::TableAlias {
13961396
name: self.new_ident_quoted_if_needs(alias),
13971397
columns,
1398+
explicit: true,
13981399
}
13991400
}
14001401

datafusion/sql/src/values.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
3131
let SQLValues {
3232
explicit_row: _,
3333
rows,
34+
value_keyword: _,
3435
} = values;
3536

3637
let empty_schema = Arc::new(DFSchema::empty());

0 commit comments

Comments
 (0)