@@ -504,8 +504,8 @@ impl CreateTableBuilder {
504504 self . require_user = require_user;
505505 self
506506 }
507- /// Consume the builder and produce a `Statement:: CreateTable`.
508- pub fn build ( self ) -> Statement {
507+ /// Consume the builder and produce a `CreateTable`.
508+ pub fn build ( self ) -> CreateTable {
509509 CreateTable {
510510 or_replace : self . or_replace ,
511511 temporary : self . temporary ,
@@ -561,7 +561,6 @@ impl CreateTableBuilder {
561561 initialize : self . initialize ,
562562 require_user : self . require_user ,
563563 }
564- . into ( )
565564 }
566565}
567566
@@ -572,122 +571,74 @@ impl TryFrom<Statement> for CreateTableBuilder {
572571 // ownership.
573572 fn try_from ( stmt : Statement ) -> Result < Self , Self :: Error > {
574573 match stmt {
575- Statement :: CreateTable ( CreateTable {
576- or_replace,
577- temporary,
578- external,
579- global,
580- if_not_exists,
581- transient,
582- volatile,
583- iceberg,
584- dynamic,
585- name,
586- columns,
587- constraints,
588- hive_distribution,
589- hive_formats,
590- file_format,
591- location,
592- query,
593- without_rowid,
594- like,
595- clone,
596- version,
597- comment,
598- on_commit,
599- on_cluster,
600- primary_key,
601- order_by,
602- partition_by,
603- cluster_by,
604- clustered_by,
605- inherits,
606- partition_of,
607- for_values,
608- strict,
609- copy_grants,
610- enable_schema_evolution,
611- change_tracking,
612- data_retention_time_in_days,
613- max_data_extension_time_in_days,
614- default_ddl_collation,
615- with_aggregation_policy,
616- with_row_access_policy,
617- with_tags,
618- base_location,
619- external_volume,
620- catalog,
621- catalog_sync,
622- storage_serialization_policy,
623- table_options,
624- target_lag,
625- warehouse,
626- refresh_mode,
627- initialize,
628- require_user,
629- } ) => Ok ( Self {
630- or_replace,
631- temporary,
632- external,
633- global,
634- if_not_exists,
635- transient,
636- dynamic,
637- name,
638- columns,
639- constraints,
640- hive_distribution,
641- hive_formats,
642- file_format,
643- location,
644- query,
645- without_rowid,
646- like,
647- clone,
648- version,
649- comment,
650- on_commit,
651- on_cluster,
652- primary_key,
653- order_by,
654- partition_by,
655- cluster_by,
656- clustered_by,
657- inherits,
658- partition_of,
659- for_values,
660- strict,
661- iceberg,
662- copy_grants,
663- enable_schema_evolution,
664- change_tracking,
665- data_retention_time_in_days,
666- max_data_extension_time_in_days,
667- default_ddl_collation,
668- with_aggregation_policy,
669- with_row_access_policy,
670- with_tags,
671- volatile,
672- base_location,
673- external_volume,
674- catalog,
675- catalog_sync,
676- storage_serialization_policy,
677- table_options,
678- target_lag,
679- warehouse,
680- refresh_mode,
681- initialize,
682- require_user,
683- } ) ,
574+ Statement :: CreateTable ( create_table) => Ok ( create_table. into ( ) ) ,
684575 _ => Err ( ParserError :: ParserError ( format ! (
685576 "Expected create table statement, but received: {stmt}"
686577 ) ) ) ,
687578 }
688579 }
689580}
690581
582+ impl From < CreateTable > for CreateTableBuilder {
583+ fn from ( table : CreateTable ) -> Self {
584+ Self {
585+ or_replace : table. or_replace ,
586+ temporary : table. temporary ,
587+ external : table. external ,
588+ global : table. global ,
589+ if_not_exists : table. if_not_exists ,
590+ transient : table. transient ,
591+ volatile : table. volatile ,
592+ iceberg : table. iceberg ,
593+ dynamic : table. dynamic ,
594+ name : table. name ,
595+ columns : table. columns ,
596+ constraints : table. constraints ,
597+ hive_distribution : table. hive_distribution ,
598+ hive_formats : table. hive_formats ,
599+ file_format : table. file_format ,
600+ location : table. location ,
601+ query : table. query ,
602+ without_rowid : table. without_rowid ,
603+ like : table. like ,
604+ clone : table. clone ,
605+ version : table. version ,
606+ comment : table. comment ,
607+ on_commit : table. on_commit ,
608+ on_cluster : table. on_cluster ,
609+ primary_key : table. primary_key ,
610+ order_by : table. order_by ,
611+ partition_by : table. partition_by ,
612+ cluster_by : table. cluster_by ,
613+ clustered_by : table. clustered_by ,
614+ inherits : table. inherits ,
615+ partition_of : table. partition_of ,
616+ for_values : table. for_values ,
617+ strict : table. strict ,
618+ copy_grants : table. copy_grants ,
619+ enable_schema_evolution : table. enable_schema_evolution ,
620+ change_tracking : table. change_tracking ,
621+ data_retention_time_in_days : table. data_retention_time_in_days ,
622+ max_data_extension_time_in_days : table. max_data_extension_time_in_days ,
623+ default_ddl_collation : table. default_ddl_collation ,
624+ with_aggregation_policy : table. with_aggregation_policy ,
625+ with_row_access_policy : table. with_row_access_policy ,
626+ with_tags : table. with_tags ,
627+ base_location : table. base_location ,
628+ external_volume : table. external_volume ,
629+ catalog : table. catalog ,
630+ catalog_sync : table. catalog_sync ,
631+ storage_serialization_policy : table. storage_serialization_policy ,
632+ table_options : table. table_options ,
633+ target_lag : table. target_lag ,
634+ warehouse : table. warehouse ,
635+ refresh_mode : table. refresh_mode ,
636+ initialize : table. initialize ,
637+ require_user : table. require_user ,
638+ }
639+ }
640+ }
641+
691642/// Helper return type when parsing configuration for a `CREATE TABLE` statement.
692643#[ derive( Default ) ]
693644pub ( crate ) struct CreateTableConfiguration {
@@ -707,7 +658,8 @@ mod tests {
707658 pub fn test_from_valid_statement ( ) {
708659 let builder = CreateTableBuilder :: new ( ObjectName :: from ( vec ! [ Ident :: new( "table_name" ) ] ) ) ;
709660
710- let stmt = builder. clone ( ) . build ( ) ;
661+ let create_table = builder. clone ( ) . build ( ) ;
662+ let stmt: Statement = create_table. into ( ) ;
711663
712664 assert_eq ! ( builder, CreateTableBuilder :: try_from( stmt) . unwrap( ) ) ;
713665 }
0 commit comments