findepi commented on code in PR #13517:
URL: https://github.com/apache/datafusion/pull/13517#discussion_r1853493794


##########
datafusion/expr/src/logical_plan/ddl.rs:
##########
@@ -288,8 +290,234 @@ impl PartialOrd for CreateExternalTable {
     }
 }
 
+impl CreateExternalTable {
+    pub fn new(fields: CreateExternalTableFields) -> Result<Self> {
+        let CreateExternalTableFields {
+            name,
+            schema,
+            location,
+            file_type,
+            table_partition_cols,
+            if_not_exists,
+            temporary,
+            definition,
+            order_exprs,
+            unbounded,
+            options,
+            constraints,
+            column_defaults,
+        } = fields;
+        check_fields_unique(&schema)?;
+        Ok(Self {
+            name,
+            schema,
+            location,
+            file_type,
+            table_partition_cols,
+            if_not_exists,
+            temporary,
+            definition,
+            order_exprs,
+            unbounded,
+            options,
+            constraints,
+            column_defaults,
+        })
+    }
+
+    pub fn into_fields(self) -> CreateExternalTableFields {
+        let Self {
+            name,
+            schema,
+            location,
+            file_type,
+            table_partition_cols,
+            if_not_exists,
+            temporary,
+            definition,
+            order_exprs,
+            unbounded,
+            options,
+            constraints,
+            column_defaults,
+        } = self;
+        CreateExternalTableFields {
+            name,
+            schema,
+            location,
+            file_type,
+            table_partition_cols,
+            if_not_exists,
+            temporary,
+            definition,
+            order_exprs,
+            unbounded,
+            options,
+            constraints,
+            column_defaults,
+        }
+    }
+
+    pub fn builder() -> CreateExternalTableBuilder {
+        CreateExternalTableBuilder::new()
+    }
+}
+
+/// A struct with same fields as [`CreateExternalTable`] struct so that the 
DDL can be conveniently
+/// destructed with validation that each field is handled, while still 
requiring that all
+/// construction goes through the [`CreateExternalTable::new`] constructor or 
the builder.
+pub struct CreateExternalTableFields {
+    /// The table name
+    pub name: TableReference,
+    /// The table schema
+    pub schema: DFSchemaRef,
+    /// The physical location
+    pub location: String,
+    /// The file type of physical file
+    pub file_type: String,
+    /// Partition Columns
+    pub table_partition_cols: Vec<String>,
+    /// Option to not error if table already exists
+    pub if_not_exists: bool,
+    /// Whether the table is a temporary table
+    pub temporary: bool,
+    /// SQL used to create the table, if available
+    pub definition: Option<String>,
+    /// Order expressions supplied by user
+    pub order_exprs: Vec<Vec<Sort>>,
+    /// Whether the table is an infinite streams
+    pub unbounded: bool,
+    /// Table(provider) specific options
+    pub options: HashMap<String, String>,

Review Comment:
   Good idea. I don't know what these are yet. This is copied from 
CreateExternalTable. This whole struct allows public full destruction of 
CreateExternalTable, without allowing public construction of that struct, so 
that validation can take place. Would it help if i removed all these doc 
comments, so that documentation is checked at CreateExternalTable only?
   
   
   



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to