Jefffrey commented on code in PR #19672:
URL: https://github.com/apache/datafusion/pull/19672#discussion_r2674590026


##########
datafusion/sql/src/statement.rs:
##########
@@ -102,38 +103,17 @@ fn get_schema_name(schema_name: &SchemaName) -> String {
 /// Construct `TableConstraint`(s) for the given columns by iterating over
 /// `columns` and extracting individual inline constraint definitions.
 fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> 
Vec<TableConstraint> {
-    let mut constraints = vec![];
+    let mut constraints: Vec<TableConstraint> = vec![];
     for column in columns {
         for ast::ColumnOptionDef { name, option } in &column.options {
             match option {
-                ast::ColumnOption::Unique {
-                    is_primary: false,
-                    characteristics,
-                } => constraints.push(TableConstraint::Unique {
+                ast::ColumnOption::Unique(UniqueConstraint {
+                    characteristics, ..

Review Comment:
   We should be destructuring this not ignoring the fields with `..`



##########
datafusion/sql/src/statement.rs:
##########
@@ -145,35 +125,60 @@ fn calc_inline_constraints_from_columns(columns: 
&[ColumnDef]) -> Vec<TableConst
                         },
                         operator_class: None,
                     }],
-                    characteristics: *characteristics,
-                    index_name: None,
-                    index_type: None,
                     index_options: vec![],
-                }),
-                ast::ColumnOption::ForeignKey {
+                    characteristics: *characteristics,
+                    nulls_distinct: NullsDistinctOption::None,
+                })),
+                ast::ColumnOption::PrimaryKey(PrimaryKeyConstraint {
+                    characteristics,
+                    ..

Review Comment:
   We're still ignoring fields here with the usage of `..`



##########
datafusion/sql/src/statement.rs:
##########
@@ -1064,6 +1074,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
                 from,
                 order_by,
                 limit,
+                ..

Review Comment:
   We should be destructuring this not ignoring the fields with `..`



##########
datafusion/sql/src/statement.rs:
##########
@@ -145,35 +125,60 @@ fn calc_inline_constraints_from_columns(columns: 
&[ColumnDef]) -> Vec<TableConst
                         },
                         operator_class: None,
                     }],
-                    characteristics: *characteristics,
-                    index_name: None,
-                    index_type: None,
                     index_options: vec![],
-                }),
-                ast::ColumnOption::ForeignKey {
+                    characteristics: *characteristics,
+                    nulls_distinct: NullsDistinctOption::None,
+                })),
+                ast::ColumnOption::PrimaryKey(PrimaryKeyConstraint {
+                    characteristics,
+                    ..
+                }) => {
+                    
constraints.push(TableConstraint::PrimaryKey(PrimaryKeyConstraint {
+                        name: name.clone(),
+                        index_name: None,
+                        index_type: None,
+                        columns: vec![IndexColumn {
+                            column: OrderByExpr {
+                                expr: SQLExpr::Identifier(column.name.clone()),
+                                options: OrderByOptions {
+                                    asc: None,
+                                    nulls_first: None,
+                                },
+                                with_fill: None,
+                            },
+                            operator_class: None,
+                        }],
+                        index_options: vec![],
+                        characteristics: *characteristics,
+                    }))
+                }
+                ast::ColumnOption::ForeignKey(ForeignKeyConstraint {
                     foreign_table,
                     referred_columns,
                     on_delete,
                     on_update,
                     characteristics,
-                } => constraints.push(TableConstraint::ForeignKey {
-                    name: name.clone(),
-                    columns: vec![],
-                    foreign_table: foreign_table.clone(),
-                    referred_columns: referred_columns.to_vec(),
-                    on_delete: *on_delete,
-                    on_update: *on_update,
-                    characteristics: *characteristics,
-                    index_name: None,
-                }),
-                ast::ColumnOption::Check(expr) => {
-                    constraints.push(TableConstraint::Check {
+                    ..
+                }) => {
+                    
constraints.push(TableConstraint::ForeignKey(ForeignKeyConstraint {
+                        name: name.clone(),
+                        index_name: None,
+                        columns: vec![],
+                        foreign_table: foreign_table.clone(),
+                        referred_columns: referred_columns.clone(),
+                        on_delete: on_delete.clone(),
+                        on_update: on_update.clone(),
+                        match_kind: None,
+                        characteristics: *characteristics,
+                    }))
+                }
+                ast::ColumnOption::Check(CheckConstraint { name, expr, .. }) 
=> {

Review Comment:
   We should be destructuring this not ignoring the fields with `..`



##########
datafusion/expr/src/expr.rs:
##########
@@ -1403,7 +1403,9 @@ pub struct PlannedReplaceSelectItem {
 impl Display for PlannedReplaceSelectItem {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
         write!(f, "REPLACE")?;
-        write!(f, " ({})", display_comma_separated(&self.items))?;
+        for item in &self.items {
+            write!(f, " ({item})")?;
+        }

Review Comment:
   We should just reuse this function by removing its cfg guard:
   
   
https://github.com/apache/datafusion/blob/a55b77e7defe021175fb050d236e91f0fbeeaab7/datafusion/expr/src/expr.rs#L1271-L1278



##########
datafusion/sql/src/query.rs:
##########
@@ -170,6 +170,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
                     name: alias,
                     // Apply to all fields
                     columns: vec![],
+                    explicit: true,

Review Comment:
   This code seems related to the pipe operator syntax, could you test against 
that too?



##########
datafusion/sql/src/statement.rs:
##########
@@ -1025,15 +1034,16 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
                 let _ = has_table_keyword;
                 self.insert_to_plan(table_name, columns, source, overwrite, 
replace_into)
             }
-            Statement::Update {
+            Statement::Update(Update {
                 table,
                 assignments,
                 from,
                 selection,
                 returning,
                 or,
                 limit,
-            } => {
+                ..

Review Comment:
   We should be destructuring this not ignoring the fields with `..`



##########
datafusion/sql/src/statement.rs:
##########
@@ -1338,22 +1350,18 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
 
                 Ok(LogicalPlan::Ddl(statement))
             }
-            Statement::DropFunction {
-                if_exists,
-                func_desc,
-                ..
-            } => {
+            Statement::DropFunction(func) => {

Review Comment:
   We should be destructuring this like so
   
   ```rust
   Statement::DropFunction(DropFunction {
       if_exists,
       func_desc,
       drop_behaviour,
   })
   ```



##########
datafusion/sql/src/statement.rs:
##########
@@ -145,35 +125,60 @@ fn calc_inline_constraints_from_columns(columns: 
&[ColumnDef]) -> Vec<TableConst
                         },
                         operator_class: None,
                     }],
-                    characteristics: *characteristics,
-                    index_name: None,
-                    index_type: None,
                     index_options: vec![],
-                }),
-                ast::ColumnOption::ForeignKey {
+                    characteristics: *characteristics,
+                    nulls_distinct: NullsDistinctOption::None,
+                })),
+                ast::ColumnOption::PrimaryKey(PrimaryKeyConstraint {
+                    characteristics,
+                    ..
+                }) => {
+                    
constraints.push(TableConstraint::PrimaryKey(PrimaryKeyConstraint {
+                        name: name.clone(),
+                        index_name: None,
+                        index_type: None,
+                        columns: vec![IndexColumn {
+                            column: OrderByExpr {
+                                expr: SQLExpr::Identifier(column.name.clone()),
+                                options: OrderByOptions {
+                                    asc: None,
+                                    nulls_first: None,
+                                },
+                                with_fill: None,
+                            },
+                            operator_class: None,
+                        }],
+                        index_options: vec![],
+                        characteristics: *characteristics,
+                    }))
+                }
+                ast::ColumnOption::ForeignKey(ForeignKeyConstraint {
                     foreign_table,
                     referred_columns,
                     on_delete,
                     on_update,
                     characteristics,
-                } => constraints.push(TableConstraint::ForeignKey {
-                    name: name.clone(),
-                    columns: vec![],
-                    foreign_table: foreign_table.clone(),
-                    referred_columns: referred_columns.to_vec(),
-                    on_delete: *on_delete,
-                    on_update: *on_update,
-                    characteristics: *characteristics,
-                    index_name: None,
-                }),
-                ast::ColumnOption::Check(expr) => {
-                    constraints.push(TableConstraint::Check {
+                    ..

Review Comment:
   We should be destructuring this not ignoring the fields with `..`



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to