jonahgao commented on code in PR #13489: URL: https://github.com/apache/datafusion/pull/13489#discussion_r1849701626
########## datafusion/expr/src/logical_plan/ddl.rs: ########## @@ -285,8 +288,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 { Review Comment: I think `non_exhaustive` discourages destructuring, but `CreateExternalTableFields` makes it possible again. `CreateExternalTableFields` and `CreateExternalTable` have the same fields, and I'm a bit worried that it introduces some code duplication 🤔. -- 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