Skip to content

Commit b9328b9

Browse files
alambJefffrey
andauthored
Upgrade to sqlparser 0.61.0 (#20177)
DRAFT until SQL parser is released ## Which issue does this PR close? - part of apache/datafusion-sqlparser-rs#2117 ## Rationale for this change Keep up to date with dependencies I think @Samyak2 specifically would like access to the `:` field syntax ## What changes are included in this PR? 1. Update to 0.61.0 2. Update APIs ## Are these changes tested? Yes by existing tests ## Are there any user-facing changes? New dependency --------- Co-authored-by: Jeffrey Vo <jeffrey.vo.australia@gmail.com>
1 parent d303f58 commit b9328b9

File tree

10 files changed

+123
-55
lines changed

10 files changed

+123
-55
lines changed

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
@@ -183,7 +183,7 @@ regex = "1.12"
183183
rstest = "0.26.1"
184184
serde_json = "1"
185185
sha2 = "^0.10.9"
186-
sqlparser = { version = "0.60.0", default-features = false, features = ["std", "visitor"] }
186+
sqlparser = { version = "0.61.0", default-features = false, features = ["std", "visitor"] }
187187
strum = "0.27.2"
188188
strum_macros = "0.27.2"
189189
tempfile = "3"

datafusion/sql/src/expr/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,16 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
267267
planner_context,
268268
),
269269

270+
SQLExpr::Cast { array: true, .. } => {
271+
not_impl_err!("`CAST(... AS type ARRAY`) not supported")
272+
}
273+
270274
SQLExpr::Cast {
271275
kind: CastKind::Cast | CastKind::DoubleColon,
272276
expr,
273277
data_type,
274278
format,
279+
array: false,
275280
} => {
276281
self.sql_cast_to_expr(*expr, &data_type, format, schema, planner_context)
277282
}
@@ -281,6 +286,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
281286
expr,
282287
data_type,
283288
format,
289+
array: false,
284290
} => {
285291
if let Some(format) = format {
286292
return not_impl_err!("CAST with format is not supported: {format}");

datafusion/sql/src/select.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
361361
// Process distinct clause
362362
let plan = match select.distinct {
363363
None => Ok(plan),
364+
Some(Distinct::All) => Ok(plan),
364365
Some(Distinct::Distinct) => {
365366
LogicalPlanBuilder::from(plan).distinct()?.build()
366367
}

datafusion/sql/src/statement.rs

Lines changed: 70 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -342,26 +342,28 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
342342
refresh_mode,
343343
initialize,
344344
require_user,
345+
partition_of,
346+
for_values,
345347
}) => {
346348
if temporary {
347-
return not_impl_err!("Temporary tables not supported")?;
349+
return not_impl_err!("Temporary tables not supported");
348350
}
349351
if external {
350-
return not_impl_err!("External tables not supported")?;
352+
return not_impl_err!("External tables not supported");
351353
}
352354
if global.is_some() {
353-
return not_impl_err!("Global tables not supported")?;
355+
return not_impl_err!("Global tables not supported");
354356
}
355357
if transient {
356-
return not_impl_err!("Transient tables not supported")?;
358+
return not_impl_err!("Transient tables not supported");
357359
}
358360
if volatile {
359-
return not_impl_err!("Volatile tables not supported")?;
361+
return not_impl_err!("Volatile tables not supported");
360362
}
361363
if hive_distribution != ast::HiveDistributionStyle::NONE {
362364
return not_impl_err!(
363365
"Hive distribution not supported: {hive_distribution:?}"
364-
)?;
366+
);
365367
}
366368
if hive_formats.is_some()
367369
&& !matches!(
@@ -374,122 +376,126 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
374376
})
375377
)
376378
{
377-
return not_impl_err!(
378-
"Hive formats not supported: {hive_formats:?}"
379-
)?;
379+
return not_impl_err!("Hive formats not supported: {hive_formats:?}");
380380
}
381381
if file_format.is_some() {
382-
return not_impl_err!("File format not supported")?;
382+
return not_impl_err!("File format not supported");
383383
}
384384
if location.is_some() {
385-
return not_impl_err!("Location not supported")?;
385+
return not_impl_err!("Location not supported");
386386
}
387387
if without_rowid {
388-
return not_impl_err!("Without rowid not supported")?;
388+
return not_impl_err!("Without rowid not supported");
389389
}
390390
if like.is_some() {
391-
return not_impl_err!("Like not supported")?;
391+
return not_impl_err!("Like not supported");
392392
}
393393
if clone.is_some() {
394-
return not_impl_err!("Clone not supported")?;
394+
return not_impl_err!("Clone not supported");
395395
}
396396
if comment.is_some() {
397-
return not_impl_err!("Comment not supported")?;
397+
return not_impl_err!("Comment not supported");
398398
}
399399
if on_commit.is_some() {
400-
return not_impl_err!("On commit not supported")?;
400+
return not_impl_err!("On commit not supported");
401401
}
402402
if on_cluster.is_some() {
403-
return not_impl_err!("On cluster not supported")?;
403+
return not_impl_err!("On cluster not supported");
404404
}
405405
if primary_key.is_some() {
406-
return not_impl_err!("Primary key not supported")?;
406+
return not_impl_err!("Primary key not supported");
407407
}
408408
if order_by.is_some() {
409-
return not_impl_err!("Order by not supported")?;
409+
return not_impl_err!("Order by not supported");
410410
}
411411
if partition_by.is_some() {
412-
return not_impl_err!("Partition by not supported")?;
412+
return not_impl_err!("Partition by not supported");
413413
}
414414
if cluster_by.is_some() {
415-
return not_impl_err!("Cluster by not supported")?;
415+
return not_impl_err!("Cluster by not supported");
416416
}
417417
if clustered_by.is_some() {
418-
return not_impl_err!("Clustered by not supported")?;
418+
return not_impl_err!("Clustered by not supported");
419419
}
420420
if strict {
421-
return not_impl_err!("Strict not supported")?;
421+
return not_impl_err!("Strict not supported");
422422
}
423423
if copy_grants {
424-
return not_impl_err!("Copy grants not supported")?;
424+
return not_impl_err!("Copy grants not supported");
425425
}
426426
if enable_schema_evolution.is_some() {
427-
return not_impl_err!("Enable schema evolution not supported")?;
427+
return not_impl_err!("Enable schema evolution not supported");
428428
}
429429
if change_tracking.is_some() {
430-
return not_impl_err!("Change tracking not supported")?;
430+
return not_impl_err!("Change tracking not supported");
431431
}
432432
if data_retention_time_in_days.is_some() {
433-
return not_impl_err!("Data retention time in days not supported")?;
433+
return not_impl_err!("Data retention time in days not supported");
434434
}
435435
if max_data_extension_time_in_days.is_some() {
436436
return not_impl_err!(
437437
"Max data extension time in days not supported"
438-
)?;
438+
);
439439
}
440440
if default_ddl_collation.is_some() {
441-
return not_impl_err!("Default DDL collation not supported")?;
441+
return not_impl_err!("Default DDL collation not supported");
442442
}
443443
if with_aggregation_policy.is_some() {
444-
return not_impl_err!("With aggregation policy not supported")?;
444+
return not_impl_err!("With aggregation policy not supported");
445445
}
446446
if with_row_access_policy.is_some() {
447-
return not_impl_err!("With row access policy not supported")?;
447+
return not_impl_err!("With row access policy not supported");
448448
}
449449
if with_tags.is_some() {
450-
return not_impl_err!("With tags not supported")?;
450+
return not_impl_err!("With tags not supported");
451451
}
452452
if iceberg {
453-
return not_impl_err!("Iceberg not supported")?;
453+
return not_impl_err!("Iceberg not supported");
454454
}
455455
if external_volume.is_some() {
456-
return not_impl_err!("External volume not supported")?;
456+
return not_impl_err!("External volume not supported");
457457
}
458458
if base_location.is_some() {
459-
return not_impl_err!("Base location not supported")?;
459+
return not_impl_err!("Base location not supported");
460460
}
461461
if catalog.is_some() {
462-
return not_impl_err!("Catalog not supported")?;
462+
return not_impl_err!("Catalog not supported");
463463
}
464464
if catalog_sync.is_some() {
465-
return not_impl_err!("Catalog sync not supported")?;
465+
return not_impl_err!("Catalog sync not supported");
466466
}
467467
if storage_serialization_policy.is_some() {
468-
return not_impl_err!("Storage serialization policy not supported")?;
468+
return not_impl_err!("Storage serialization policy not supported");
469469
}
470470
if inherits.is_some() {
471-
return not_impl_err!("Table inheritance not supported")?;
471+
return not_impl_err!("Table inheritance not supported");
472472
}
473473
if dynamic {
474-
return not_impl_err!("Dynamic tables not supported")?;
474+
return not_impl_err!("Dynamic tables not supported");
475475
}
476476
if version.is_some() {
477-
return not_impl_err!("Version not supported")?;
477+
return not_impl_err!("Version not supported");
478478
}
479479
if target_lag.is_some() {
480-
return not_impl_err!("Target lag not supported")?;
480+
return not_impl_err!("Target lag not supported");
481481
}
482482
if warehouse.is_some() {
483-
return not_impl_err!("Warehouse not supported")?;
483+
return not_impl_err!("Warehouse not supported");
484484
}
485485
if refresh_mode.is_some() {
486-
return not_impl_err!("Refresh mode not supported")?;
486+
return not_impl_err!("Refresh mode not supported");
487487
}
488488
if initialize.is_some() {
489-
return not_impl_err!("Initialize not supported")?;
489+
return not_impl_err!("Initialize not supported");
490490
}
491491
if require_user {
492-
return not_impl_err!("Require user not supported")?;
492+
return not_impl_err!("Require user not supported");
493+
}
494+
if partition_of.is_some() {
495+
return not_impl_err!("PARTITION OF not supported");
496+
}
497+
if for_values.is_some() {
498+
return not_impl_err!("PARTITION OF .. FOR VALUES .. not supported");
493499
}
494500
// Merge inline constraints and existing constraints
495501
let mut all_constraints = constraints;
@@ -989,7 +995,8 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
989995
has_table_keyword,
990996
settings,
991997
format_clause,
992-
insert_token: _insert_token, // record the location the `INSERT` token
998+
insert_token: _, // record the location the `INSERT` token
999+
optimizer_hint,
9931000
}) => {
9941001
let table_name = match table {
9951002
TableObject::TableName(table_name) => table_name,
@@ -1045,6 +1052,9 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
10451052
if format_clause.is_some() {
10461053
plan_err!("Inserts with format clause not supported")?;
10471054
}
1055+
if optimizer_hint.is_some() {
1056+
plan_err!("Optimizer hints not supported")?;
1057+
}
10481058
// optional keywords don't change behavior
10491059
let _ = into;
10501060
let _ = has_table_keyword;
@@ -1059,6 +1069,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
10591069
or,
10601070
limit,
10611071
update_token: _,
1072+
optimizer_hint,
10621073
}) => {
10631074
let from_clauses =
10641075
from.map(|update_table_from_kind| match update_table_from_kind {
@@ -1079,6 +1090,9 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
10791090
if limit.is_some() {
10801091
return not_impl_err!("Update-limit clause not supported")?;
10811092
}
1093+
if optimizer_hint.is_some() {
1094+
plan_err!("Optimizer hints not supported")?;
1095+
}
10821096
self.update_to_plan(table, &assignments, update_from, selection)
10831097
}
10841098

@@ -1091,6 +1105,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
10911105
order_by,
10921106
limit,
10931107
delete_token: _,
1108+
optimizer_hint,
10941109
}) => {
10951110
if !tables.is_empty() {
10961111
plan_err!("DELETE <TABLE> not supported")?;
@@ -1108,6 +1123,10 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
11081123
plan_err!("Delete-order-by clause not yet supported")?;
11091124
}
11101125

1126+
if optimizer_hint.is_some() {
1127+
plan_err!("Optimizer hints not supported")?;
1128+
}
1129+
11111130
let table_name = self.get_delete_target(from)?;
11121131
self.delete_to_plan(&table_name, selection, limit)
11131132
}
@@ -1393,6 +1412,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
13931412
cascade,
13941413
on_cluster,
13951414
table,
1415+
if_exists,
13961416
}) => {
13971417
let _ = table; // Support TRUNCATE TABLE and TRUNCATE syntax
13981418
if table_names.len() != 1 {
@@ -1421,6 +1441,9 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
14211441
if on_cluster.is_some() {
14221442
return not_impl_err!("TRUNCATE with ON CLUSTER is not supported");
14231443
}
1444+
if if_exists {
1445+
return not_impl_err!("TRUNCATE .. with IF EXISTS is not supported");
1446+
}
14241447
let table = self.object_name_to_table_reference(target.name.clone())?;
14251448
let source = self.context_provider.get_table_source(table.clone())?;
14261449

datafusion/sql/src/unparser/ast.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ impl SelectBuilder {
315315
}
316316
pub fn build(&self) -> Result<ast::Select, BuilderError> {
317317
Ok(ast::Select {
318+
optimizer_hint: None,
318319
distinct: self.distinct.clone(),
320+
select_modifiers: None,
319321
top_before_distinct: false,
320322
top: self.top.clone(),
321323
projection: self.projection.clone().unwrap_or_default(),
@@ -340,12 +342,12 @@ impl SelectBuilder {
340342
named_window: self.named_window.clone(),
341343
qualify: self.qualify.clone(),
342344
value_table_mode: self.value_table_mode,
343-
connect_by: None,
345+
connect_by: Vec::new(),
344346
window_before_qualify: false,
345347
prewhere: None,
346348
select_token: AttachedToken::empty(),
347349
flavor: match self.flavor {
348-
Some(ref value) => value.clone(),
350+
Some(ref value) => *value,
349351
None => return Err(Into::into(UninitializedFieldError::from("flavor"))),
350352
},
351353
exclude: None,
@@ -608,6 +610,7 @@ impl DerivedRelationBuilder {
608610
}
609611
},
610612
alias: self.alias.clone(),
613+
sample: None,
611614
})
612615
}
613616
fn create_empty() -> Self {

datafusion/sql/src/unparser/dialect.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ impl PostgreSqlDialect {
372372
kind: ast::CastKind::Cast,
373373
expr: Box::new(expr.clone()),
374374
data_type: ast::DataType::Numeric(ast::ExactNumberInfo::None),
375+
array: false,
375376
format: None,
376377
};
377378
}

0 commit comments

Comments
 (0)