Skip to content

Commit 2d42a2c

Browse files
Jefffreyccciudatu
authored andcommitted
chore(deps): update sqlparser requirement from 0.44.0 to 0.45.0 (apache#10137)
* chore(deps): update sqlparser requirement from 0.44.0 to 0.45.0 * Bump datafusion-cli Cargo.lock * Enhance error messages
1 parent 78b92dc commit 2d42a2c

File tree

6 files changed

+60
-21
lines changed

6 files changed

+60
-21
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ parquet = { version = "51.0.0", default-features = false, features = ["arrow", "
103103
rand = "0.8"
104104
rstest = "0.19.0"
105105
serde_json = "1"
106-
sqlparser = { version = "0.44.0", features = ["visitor"] }
106+
sqlparser = { version = "0.45.0", features = ["visitor"] }
107107
tempfile = "3"
108108
thiserror = "1.0.44"
109109
tokio = { version = "1.36", features = ["macros", "rt", "sync"] }

datafusion-cli/Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/common/src/functional_dependencies.rs

+30-14
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,48 @@ impl Constraints {
6868
let constraints = constraints
6969
.iter()
7070
.map(|c: &TableConstraint| match c {
71-
TableConstraint::Unique {
72-
columns,
73-
is_primary,
74-
..
75-
} => {
71+
TableConstraint::Unique { name, columns, .. } => {
7672
let field_names = df_schema.field_names();
77-
// Get primary key and/or unique indices in the schema:
73+
// Get unique constraint indices in the schema:
7874
let indices = columns
7975
.iter()
80-
.map(|pk| {
76+
.map(|u| {
8177
let idx = field_names
8278
.iter()
83-
.position(|item| *item == pk.value)
79+
.position(|item| *item == u.value)
8480
.ok_or_else(|| {
81+
let name = name
82+
.as_ref()
83+
.map(|name| format!("with name '{name}' "))
84+
.unwrap_or("".to_string());
8585
DataFusionError::Execution(
86-
"Primary key doesn't exist".to_string(),
86+
format!("Column for unique constraint {}not found in schema: {}", name,u.value)
8787
)
8888
})?;
8989
Ok(idx)
9090
})
9191
.collect::<Result<Vec<_>>>()?;
92-
Ok(if *is_primary {
93-
Constraint::PrimaryKey(indices)
94-
} else {
95-
Constraint::Unique(indices)
96-
})
92+
Ok(Constraint::Unique(indices))
93+
}
94+
TableConstraint::PrimaryKey { columns, .. } => {
95+
let field_names = df_schema.field_names();
96+
// Get primary key indices in the schema:
97+
let indices = columns
98+
.iter()
99+
.map(|pk| {
100+
let idx = field_names
101+
.iter()
102+
.position(|item| *item == pk.value)
103+
.ok_or_else(|| {
104+
DataFusionError::Execution(format!(
105+
"Column for primary key not found in schema: {}",
106+
pk.value
107+
))
108+
})?;
109+
Ok(idx)
110+
})
111+
.collect::<Result<Vec<_>>>()?;
112+
Ok(Constraint::PrimaryKey(indices))
97113
}
98114
TableConstraint::ForeignKey { .. } => {
99115
_plan_err!("Foreign key constraints are not currently supported")

datafusion/sql/src/expr/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
194194

195195
SQLExpr::MapAccess { column, keys } => {
196196
if let SQLExpr::Identifier(id) = *column {
197+
let keys = keys.into_iter().map(|mak| mak.key).collect();
197198
self.plan_indexed(
198199
col(self.normalizer.normalize(id)),
199200
keys,

datafusion/sql/src/expr/value.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,17 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
215215
return not_impl_err!("Unsupported interval operator: {op:?}");
216216
}
217217
};
218-
match (interval.leading_field, left.as_ref(), right.as_ref()) {
218+
match (
219+
interval.leading_field.as_ref(),
220+
left.as_ref(),
221+
right.as_ref(),
222+
) {
219223
(_, _, SQLExpr::Value(_)) => {
220224
let left_expr = self.sql_interval_to_expr(
221225
negative,
222226
Interval {
223227
value: left,
224-
leading_field: interval.leading_field,
228+
leading_field: interval.leading_field.clone(),
225229
leading_precision: None,
226230
last_field: None,
227231
fractional_seconds_precision: None,

datafusion/sql/src/statement.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,27 @@ fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConst
9494
for ast::ColumnOptionDef { name, option } in &column.options {
9595
match option {
9696
ast::ColumnOption::Unique {
97-
is_primary,
97+
is_primary: false,
9898
characteristics,
9999
} => constraints.push(ast::TableConstraint::Unique {
100100
name: name.clone(),
101101
columns: vec![column.name.clone()],
102-
is_primary: *is_primary,
103102
characteristics: *characteristics,
103+
index_name: None,
104+
index_type_display: ast::KeyOrIndexDisplay::None,
105+
index_type: None,
106+
index_options: vec![],
107+
}),
108+
ast::ColumnOption::Unique {
109+
is_primary: true,
110+
characteristics,
111+
} => constraints.push(ast::TableConstraint::PrimaryKey {
112+
name: name.clone(),
113+
columns: vec![column.name.clone()],
114+
characteristics: *characteristics,
115+
index_name: None,
116+
index_type: None,
117+
index_options: vec![],
104118
}),
105119
ast::ColumnOption::ForeignKey {
106120
foreign_table,
@@ -465,6 +479,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
465479
table_alias,
466480
replace_into,
467481
priority,
482+
insert_alias,
468483
} => {
469484
if or.is_some() {
470485
plan_err!("Inserts with or clauses not supported")?;
@@ -503,6 +518,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
503518
"Inserts with a `PRIORITY` clause not supported: {priority:?}"
504519
)?
505520
};
521+
if insert_alias.is_some() {
522+
plan_err!("Inserts with an alias not supported")?;
523+
}
506524
let _ = into; // optional keyword doesn't change behavior
507525
self.insert_to_plan(table_name, columns, source, overwrite)
508526
}

0 commit comments

Comments
 (0)