Skip to content

Commit 4cac0a2

Browse files
committed
enhance: explicitly destructur tableconstraints
Signed-off-by: StandingMan <jmtangcs@gmail.com>
1 parent 5d0fed6 commit 4cac0a2

File tree

3 files changed

+46
-28
lines changed

3 files changed

+46
-28
lines changed

datafusion/expr/src/expr.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,6 @@ impl Display for ExceptSelectItem {
12681268
}
12691269
}
12701270

1271-
#[cfg(not(feature = "sql"))]
12721271
pub fn display_comma_separated<T>(slice: &[T]) -> String
12731272
where
12741273
T: Display,
@@ -1402,14 +1401,8 @@ pub struct PlannedReplaceSelectItem {
14021401

14031402
impl Display for PlannedReplaceSelectItem {
14041403
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
1405-
write!(f, "REPLACE (")?;
1406-
for (i, item) in self.items.iter().enumerate() {
1407-
if i > 0 {
1408-
write!(f, ", ")?;
1409-
}
1410-
write!(f, "{item}")?;
1411-
}
1412-
write!(f, ")")?;
1404+
write!(f, "REPLACE")?;
1405+
write!(f, " ({})", display_comma_separated(&self.items))?;
14131406
Ok(())
14141407
}
14151408
}

datafusion/sql/src/statement.rs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,14 @@ fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConst
108108
for ast::ColumnOptionDef { name, option } in &column.options {
109109
match option {
110110
ast::ColumnOption::Unique(UniqueConstraint {
111-
characteristics, ..
111+
characteristics,
112+
name,
113+
index_name: _index_name,
114+
index_type_display: _index_type_display,
115+
index_type: _index_type,
116+
columns: _column,
117+
index_options: _index_options,
118+
nulls_distinct: _nulls_distinct,
112119
}) => constraints.push(TableConstraint::Unique(UniqueConstraint {
113120
name: name.clone(),
114121
index_name: None,
@@ -131,7 +138,11 @@ fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConst
131138
})),
132139
ast::ColumnOption::PrimaryKey(PrimaryKeyConstraint {
133140
characteristics,
134-
..
141+
name: _name,
142+
index_name: _index_name,
143+
index_type: _index_type,
144+
columns: _columns,
145+
index_options: _index_options,
135146
}) => {
136147
constraints.push(TableConstraint::PrimaryKey(PrimaryKeyConstraint {
137148
name: name.clone(),
@@ -158,27 +169,32 @@ fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConst
158169
on_delete,
159170
on_update,
160171
characteristics,
161-
..
172+
name: _name,
173+
index_name: _index_name,
174+
columns: _columns,
175+
match_kind: _match_kind,
162176
}) => {
163177
constraints.push(TableConstraint::ForeignKey(ForeignKeyConstraint {
164178
name: name.clone(),
165179
index_name: None,
166180
columns: vec![],
167181
foreign_table: foreign_table.clone(),
168182
referred_columns: referred_columns.clone(),
169-
on_delete: on_delete.clone(),
170-
on_update: on_update.clone(),
183+
on_delete: *on_delete,
184+
on_update: *on_update,
171185
match_kind: None,
172186
characteristics: *characteristics,
173187
}))
174188
}
175-
ast::ColumnOption::Check(CheckConstraint { name, expr, .. }) => {
176-
constraints.push(TableConstraint::Check(CheckConstraint {
177-
name: name.clone(),
178-
expr: expr.clone(),
179-
enforced: None,
180-
}))
181-
}
189+
ast::ColumnOption::Check(CheckConstraint {
190+
name,
191+
expr,
192+
enforced: _enforced,
193+
}) => constraints.push(TableConstraint::Check(CheckConstraint {
194+
name: name.clone(),
195+
expr: expr.clone(),
196+
enforced: None,
197+
})),
182198
ast::ColumnOption::Default(_)
183199
| ast::ColumnOption::Null
184200
| ast::ColumnOption::NotNull
@@ -1042,7 +1058,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
10421058
returning,
10431059
or,
10441060
limit,
1045-
..
1061+
update_token: _,
10461062
}) => {
10471063
let from_clauses =
10481064
from.map(|update_table_from_kind| match update_table_from_kind {
@@ -1074,7 +1090,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
10741090
from,
10751091
order_by,
10761092
limit,
1077-
..
1093+
delete_token: _,
10781094
}) => {
10791095
if !tables.is_empty() {
10801096
plan_err!("DELETE <TABLE> not supported")?;
@@ -1350,18 +1366,22 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
13501366

13511367
Ok(LogicalPlan::Ddl(statement))
13521368
}
1353-
Statement::DropFunction(func) => {
1369+
Statement::DropFunction(ast::DropFunction {
1370+
if_exists,
1371+
func_desc,
1372+
drop_behavior: _,
1373+
}) => {
13541374
// According to postgresql documentation it can be only one function
13551375
// specified in drop statement
1356-
if let Some(desc) = func.func_desc.first() {
1376+
if let Some(desc) = func_desc.first() {
13571377
// At the moment functions can't be qualified `schema.name`
13581378
let name = match &desc.name.0[..] {
13591379
[] => exec_err!("Function should have name")?,
13601380
[n] => n.as_ident().unwrap().value.clone(),
13611381
[..] => not_impl_err!("Qualified functions are not supported")?,
13621382
};
13631383
let statement = DdlStatement::DropFunction(DropFunction {
1364-
if_exists: func.if_exists,
1384+
if_exists,
13651385
name,
13661386
schema: DFSchemaRef::new(DFSchema::empty()),
13671387
});

datafusion/sql/src/values.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use std::sync::Arc;
1919

2020
use crate::planner::{ContextProvider, PlannerContext, SqlToRel};
21-
use datafusion_common::{DFSchema, Result};
21+
use datafusion_common::{DFSchema, Result, not_impl_err};
2222
use datafusion_expr::{LogicalPlan, LogicalPlanBuilder};
2323
use sqlparser::ast::Values as SQLValues;
2424

@@ -31,8 +31,13 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
3131
let SQLValues {
3232
explicit_row: _,
3333
rows,
34-
value_keyword: _,
34+
value_keyword,
3535
} = values;
36+
if value_keyword {
37+
return not_impl_err!(
38+
"`VALUE` keyword does not support inserting multiple values."
39+
)?;
40+
}
3641

3742
let empty_schema = Arc::new(DFSchema::empty());
3843
let values = rows

0 commit comments

Comments
 (0)