Skip to content

Commit

Permalink
chore(deps): update sqlparser requirement from 0.44.0 to 0.45.0 (#10137)
Browse files Browse the repository at this point in the history
* chore(deps): update sqlparser requirement from 0.44.0 to 0.45.0

* Bump datafusion-cli Cargo.lock

* Enhance error messages
  • Loading branch information
Jefffrey authored Apr 21, 2024
1 parent eb72deb commit fc34dac
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ parquet = { version = "51.0.0", default-features = false, features = ["arrow", "
rand = "0.8"
rstest = "0.19.0"
serde_json = "1"
sqlparser = { version = "0.44.0", features = ["visitor"] }
sqlparser = { version = "0.45.0", features = ["visitor"] }
tempfile = "3"
thiserror = "1.0.44"
tokio = { version = "1.36", features = ["macros", "rt", "sync"] }
Expand Down
4 changes: 2 additions & 2 deletions datafusion-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 30 additions & 14 deletions datafusion/common/src/functional_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,48 @@ impl Constraints {
let constraints = constraints
.iter()
.map(|c: &TableConstraint| match c {
TableConstraint::Unique {
columns,
is_primary,
..
} => {
TableConstraint::Unique { name, columns, .. } => {
let field_names = df_schema.field_names();
// Get primary key and/or unique indices in the schema:
// Get unique constraint indices in the schema:
let indices = columns
.iter()
.map(|pk| {
.map(|u| {
let idx = field_names
.iter()
.position(|item| *item == pk.value)
.position(|item| *item == u.value)
.ok_or_else(|| {
let name = name
.as_ref()
.map(|name| format!("with name '{name}' "))
.unwrap_or("".to_string());
DataFusionError::Execution(
"Primary key doesn't exist".to_string(),
format!("Column for unique constraint {}not found in schema: {}", name,u.value)
)
})?;
Ok(idx)
})
.collect::<Result<Vec<_>>>()?;
Ok(if *is_primary {
Constraint::PrimaryKey(indices)
} else {
Constraint::Unique(indices)
})
Ok(Constraint::Unique(indices))
}
TableConstraint::PrimaryKey { columns, .. } => {
let field_names = df_schema.field_names();
// Get primary key indices in the schema:
let indices = columns
.iter()
.map(|pk| {
let idx = field_names
.iter()
.position(|item| *item == pk.value)
.ok_or_else(|| {
DataFusionError::Execution(format!(
"Column for primary key not found in schema: {}",
pk.value
))
})?;
Ok(idx)
})
.collect::<Result<Vec<_>>>()?;
Ok(Constraint::PrimaryKey(indices))
}
TableConstraint::ForeignKey { .. } => {
_plan_err!("Foreign key constraints are not currently supported")
Expand Down
1 change: 1 addition & 0 deletions datafusion/sql/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {

SQLExpr::MapAccess { column, keys } => {
if let SQLExpr::Identifier(id) = *column {
let keys = keys.into_iter().map(|mak| mak.key).collect();
self.plan_indexed(
col(self.normalizer.normalize(id)),
keys,
Expand Down
8 changes: 6 additions & 2 deletions datafusion/sql/src/expr/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,17 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
return not_impl_err!("Unsupported interval operator: {op:?}");
}
};
match (interval.leading_field, left.as_ref(), right.as_ref()) {
match (
interval.leading_field.as_ref(),
left.as_ref(),
right.as_ref(),
) {
(_, _, SQLExpr::Value(_)) => {
let left_expr = self.sql_interval_to_expr(
negative,
Interval {
value: left,
leading_field: interval.leading_field,
leading_field: interval.leading_field.clone(),
leading_precision: None,
last_field: None,
fractional_seconds_precision: None,
Expand Down
22 changes: 20 additions & 2 deletions datafusion/sql/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,27 @@ fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConst
for ast::ColumnOptionDef { name, option } in &column.options {
match option {
ast::ColumnOption::Unique {
is_primary,
is_primary: false,
characteristics,
} => constraints.push(ast::TableConstraint::Unique {
name: name.clone(),
columns: vec![column.name.clone()],
is_primary: *is_primary,
characteristics: *characteristics,
index_name: None,
index_type_display: ast::KeyOrIndexDisplay::None,
index_type: None,
index_options: vec![],
}),
ast::ColumnOption::Unique {
is_primary: true,
characteristics,
} => constraints.push(ast::TableConstraint::PrimaryKey {
name: name.clone(),
columns: vec![column.name.clone()],
characteristics: *characteristics,
index_name: None,
index_type: None,
index_options: vec![],
}),
ast::ColumnOption::ForeignKey {
foreign_table,
Expand Down Expand Up @@ -465,6 +479,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
table_alias,
replace_into,
priority,
insert_alias,
} => {
if or.is_some() {
plan_err!("Inserts with or clauses not supported")?;
Expand Down Expand Up @@ -503,6 +518,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
"Inserts with a `PRIORITY` clause not supported: {priority:?}"
)?
};
if insert_alias.is_some() {
plan_err!("Inserts with an alias not supported")?;
}
let _ = into; // optional keyword doesn't change behavior
self.insert_to_plan(table_name, columns, source, overwrite)
}
Expand Down

0 comments on commit fc34dac

Please sign in to comment.