alamb commented on code in PR #7160:
URL: https://github.com/apache/arrow-datafusion/pull/7160#discussion_r1281104732
##########
datafusion/sql/src/statement.rs:
##########
@@ -132,75 +132,93 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
if_not_exists,
or_replace,
..
- } if table_properties.is_empty() && with_options.is_empty() =>
match query {
- Some(query) => {
- let plan = self.query_to_plan(*query, planner_context)?;
- let input_schema = plan.schema();
-
- let plan = if !columns.is_empty() {
- let schema =
self.build_schema(columns)?.to_dfschema_ref()?;
- if schema.fields().len() !=
input_schema.fields().len() {
- return Err(DataFusionError::Plan(format!(
+ } if table_properties.is_empty() && with_options.is_empty() => {
+ let mut constraints = constraints;
+ for column in &columns {
+ for option in &column.options {
+ if let ast::ColumnOption::Unique { is_primary } =
option.option {
+ constraints.push(ast::TableConstraint::Unique {
+ name: None,
+ columns: vec![column.name.clone()],
+ is_primary,
+ })
+ }
+ // TODO (parkma99) handle ForeignKey etc.
Review Comment:
Can you please add code here that returns a
`Err(DataFusionError::NotImplemented)` for other types of constraints -- I
think this code will silently ignore them
Maybe it could be something like
```rust
match option.option {
ast::ColumnOption::Unique { is_primary } => ...
option => return Err(DataFusionError::NotImplemented(format!("Constraint
{} not implemented", option))),
}
```
##########
datafusion/sql/src/statement.rs:
##########
@@ -132,75 +132,93 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
if_not_exists,
or_replace,
..
- } if table_properties.is_empty() && with_options.is_empty() =>
match query {
- Some(query) => {
- let plan = self.query_to_plan(*query, planner_context)?;
- let input_schema = plan.schema();
-
- let plan = if !columns.is_empty() {
- let schema =
self.build_schema(columns)?.to_dfschema_ref()?;
- if schema.fields().len() !=
input_schema.fields().len() {
- return Err(DataFusionError::Plan(format!(
+ } if table_properties.is_empty() && with_options.is_empty() => {
+ let mut constraints = constraints;
+ for column in &columns {
+ for option in &column.options {
+ if let ast::ColumnOption::Unique { is_primary } =
option.option {
+ constraints.push(ast::TableConstraint::Unique {
+ name: None,
+ columns: vec![column.name.clone()],
+ is_primary,
+ })
+ }
+ // TODO (parkma99) handle ForeignKey etc.
Review Comment:
However, given that the current code will also ignore such errors I don't
think this change is required
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]