@@ -27,9 +27,9 @@ use sqlparser_derive::{Visit, VisitMut};
2727use super :: super :: dml:: CreateTable ;
2828use crate :: ast:: {
2929 ClusteredBy , ColumnDef , CommentDef , CreateTableOptions , Expr , FileFormat ,
30- HiveDistributionStyle , HiveFormat , Ident , ObjectName , OnCommit , OneOrManyWithParens , Query ,
31- RowAccessPolicy , Statement , StorageSerializationPolicy , TableConstraint , Tag ,
32- WrappedCollection ,
30+ HiveDistributionStyle , HiveFormat , Ident , InitializeKind , ObjectName , OnCommit ,
31+ OneOrManyWithParens , Query , RefreshModeKind , RowAccessPolicy , Statement ,
32+ StorageSerializationPolicy , TableConstraint , TableVersion , Tag , WrappedCollection ,
3333} ;
3434
3535use crate :: parser:: ParserError ;
@@ -73,6 +73,7 @@ pub struct CreateTableBuilder {
7373 pub transient : bool ,
7474 pub volatile : bool ,
7575 pub iceberg : bool ,
76+ pub dynamic : bool ,
7677 pub name : ObjectName ,
7778 pub columns : Vec < ColumnDef > ,
7879 pub constraints : Vec < TableConstraint > ,
@@ -84,6 +85,7 @@ pub struct CreateTableBuilder {
8485 pub without_rowid : bool ,
8586 pub like : Option < ObjectName > ,
8687 pub clone : Option < ObjectName > ,
88+ pub version : Option < TableVersion > ,
8789 pub comment : Option < CommentDef > ,
8890 pub on_commit : Option < OnCommit > ,
8991 pub on_cluster : Option < Ident > ,
@@ -109,6 +111,11 @@ pub struct CreateTableBuilder {
109111 pub catalog_sync : Option < String > ,
110112 pub storage_serialization_policy : Option < StorageSerializationPolicy > ,
111113 pub table_options : CreateTableOptions ,
114+ pub target_lag : Option < String > ,
115+ pub warehouse : Option < Ident > ,
116+ pub refresh_mode : Option < RefreshModeKind > ,
117+ pub initialize : Option < InitializeKind > ,
118+ pub require_user : bool ,
112119}
113120
114121impl CreateTableBuilder {
@@ -122,6 +129,7 @@ impl CreateTableBuilder {
122129 transient : false ,
123130 volatile : false ,
124131 iceberg : false ,
132+ dynamic : false ,
125133 name,
126134 columns : vec ! [ ] ,
127135 constraints : vec ! [ ] ,
@@ -133,6 +141,7 @@ impl CreateTableBuilder {
133141 without_rowid : false ,
134142 like : None ,
135143 clone : None ,
144+ version : None ,
136145 comment : None ,
137146 on_commit : None ,
138147 on_cluster : None ,
@@ -158,6 +167,11 @@ impl CreateTableBuilder {
158167 catalog_sync : None ,
159168 storage_serialization_policy : None ,
160169 table_options : CreateTableOptions :: None ,
170+ target_lag : None ,
171+ warehouse : None ,
172+ refresh_mode : None ,
173+ initialize : None ,
174+ require_user : false ,
161175 }
162176 }
163177 pub fn or_replace ( mut self , or_replace : bool ) -> Self {
@@ -200,6 +214,11 @@ impl CreateTableBuilder {
200214 self
201215 }
202216
217+ pub fn dynamic ( mut self , dynamic : bool ) -> Self {
218+ self . dynamic = dynamic;
219+ self
220+ }
221+
203222 pub fn columns ( mut self , columns : Vec < ColumnDef > ) -> Self {
204223 self . columns = columns;
205224 self
@@ -249,6 +268,11 @@ impl CreateTableBuilder {
249268 self
250269 }
251270
271+ pub fn version ( mut self , version : Option < TableVersion > ) -> Self {
272+ self . version = version;
273+ self
274+ }
275+
252276 pub fn comment_after_column_def ( mut self , comment : Option < CommentDef > ) -> Self {
253277 self . comment = comment;
254278 self
@@ -383,24 +407,29 @@ impl CreateTableBuilder {
383407 self
384408 }
385409
386- /// Returns true if the statement has exactly one source of info on the schema of the new table.
387- /// This is Snowflake-specific, some dialects allow more than one source.
388- pub ( crate ) fn validate_schema_info ( & self ) -> bool {
389- let mut sources = 0 ;
390- if !self . columns . is_empty ( ) {
391- sources += 1 ;
392- }
393- if self . query . is_some ( ) {
394- sources += 1 ;
395- }
396- if self . like . is_some ( ) {
397- sources += 1 ;
398- }
399- if self . clone . is_some ( ) {
400- sources += 1 ;
401- }
410+ pub fn target_lag ( mut self , target_lag : Option < String > ) -> Self {
411+ self . target_lag = target_lag;
412+ self
413+ }
414+
415+ pub fn warehouse ( mut self , warehouse : Option < Ident > ) -> Self {
416+ self . warehouse = warehouse;
417+ self
418+ }
402419
403- sources == 1
420+ pub fn refresh_mode ( mut self , refresh_mode : Option < RefreshModeKind > ) -> Self {
421+ self . refresh_mode = refresh_mode;
422+ self
423+ }
424+
425+ pub fn initialize ( mut self , initialize : Option < InitializeKind > ) -> Self {
426+ self . initialize = initialize;
427+ self
428+ }
429+
430+ pub fn require_user ( mut self , require_user : bool ) -> Self {
431+ self . require_user = require_user;
432+ self
404433 }
405434
406435 pub fn build ( self ) -> Statement {
@@ -413,6 +442,7 @@ impl CreateTableBuilder {
413442 transient : self . transient ,
414443 volatile : self . volatile ,
415444 iceberg : self . iceberg ,
445+ dynamic : self . dynamic ,
416446 name : self . name ,
417447 columns : self . columns ,
418448 constraints : self . constraints ,
@@ -424,6 +454,7 @@ impl CreateTableBuilder {
424454 without_rowid : self . without_rowid ,
425455 like : self . like ,
426456 clone : self . clone ,
457+ version : self . version ,
427458 comment : self . comment ,
428459 on_commit : self . on_commit ,
429460 on_cluster : self . on_cluster ,
@@ -449,6 +480,11 @@ impl CreateTableBuilder {
449480 catalog_sync : self . catalog_sync ,
450481 storage_serialization_policy : self . storage_serialization_policy ,
451482 table_options : self . table_options ,
483+ target_lag : self . target_lag ,
484+ warehouse : self . warehouse ,
485+ refresh_mode : self . refresh_mode ,
486+ initialize : self . initialize ,
487+ require_user : self . require_user ,
452488 } )
453489 }
454490}
@@ -469,6 +505,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
469505 transient,
470506 volatile,
471507 iceberg,
508+ dynamic,
472509 name,
473510 columns,
474511 constraints,
@@ -480,6 +517,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
480517 without_rowid,
481518 like,
482519 clone,
520+ version,
483521 comment,
484522 on_commit,
485523 on_cluster,
@@ -505,13 +543,19 @@ impl TryFrom<Statement> for CreateTableBuilder {
505543 catalog_sync,
506544 storage_serialization_policy,
507545 table_options,
546+ target_lag,
547+ warehouse,
548+ refresh_mode,
549+ initialize,
550+ require_user,
508551 } ) => Ok ( Self {
509552 or_replace,
510553 temporary,
511554 external,
512555 global,
513556 if_not_exists,
514557 transient,
558+ dynamic,
515559 name,
516560 columns,
517561 constraints,
@@ -523,6 +567,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
523567 without_rowid,
524568 like,
525569 clone,
570+ version,
526571 comment,
527572 on_commit,
528573 on_cluster,
@@ -550,6 +595,11 @@ impl TryFrom<Statement> for CreateTableBuilder {
550595 catalog_sync,
551596 storage_serialization_policy,
552597 table_options,
598+ target_lag,
599+ warehouse,
600+ refresh_mode,
601+ initialize,
602+ require_user,
553603 } ) ,
554604 _ => Err ( ParserError :: ParserError ( format ! (
555605 "Expected create table statement, but received: {stmt}"
0 commit comments