@@ -27,9 +27,9 @@ use sqlparser_derive::{Visit, VisitMut};
27
27
use super :: super :: dml:: CreateTable ;
28
28
use crate :: ast:: {
29
29
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 ,
33
33
} ;
34
34
35
35
use crate :: parser:: ParserError ;
@@ -73,6 +73,7 @@ pub struct CreateTableBuilder {
73
73
pub transient : bool ,
74
74
pub volatile : bool ,
75
75
pub iceberg : bool ,
76
+ pub dynamic : bool ,
76
77
pub name : ObjectName ,
77
78
pub columns : Vec < ColumnDef > ,
78
79
pub constraints : Vec < TableConstraint > ,
@@ -84,6 +85,7 @@ pub struct CreateTableBuilder {
84
85
pub without_rowid : bool ,
85
86
pub like : Option < ObjectName > ,
86
87
pub clone : Option < ObjectName > ,
88
+ pub version : Option < TableVersion > ,
87
89
pub comment : Option < CommentDef > ,
88
90
pub on_commit : Option < OnCommit > ,
89
91
pub on_cluster : Option < Ident > ,
@@ -109,6 +111,11 @@ pub struct CreateTableBuilder {
109
111
pub catalog_sync : Option < String > ,
110
112
pub storage_serialization_policy : Option < StorageSerializationPolicy > ,
111
113
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 ,
112
119
}
113
120
114
121
impl CreateTableBuilder {
@@ -122,6 +129,7 @@ impl CreateTableBuilder {
122
129
transient : false ,
123
130
volatile : false ,
124
131
iceberg : false ,
132
+ dynamic : false ,
125
133
name,
126
134
columns : vec ! [ ] ,
127
135
constraints : vec ! [ ] ,
@@ -133,6 +141,7 @@ impl CreateTableBuilder {
133
141
without_rowid : false ,
134
142
like : None ,
135
143
clone : None ,
144
+ version : None ,
136
145
comment : None ,
137
146
on_commit : None ,
138
147
on_cluster : None ,
@@ -158,6 +167,11 @@ impl CreateTableBuilder {
158
167
catalog_sync : None ,
159
168
storage_serialization_policy : None ,
160
169
table_options : CreateTableOptions :: None ,
170
+ target_lag : None ,
171
+ warehouse : None ,
172
+ refresh_mode : None ,
173
+ initialize : None ,
174
+ require_user : false ,
161
175
}
162
176
}
163
177
pub fn or_replace ( mut self , or_replace : bool ) -> Self {
@@ -200,6 +214,11 @@ impl CreateTableBuilder {
200
214
self
201
215
}
202
216
217
+ pub fn dynamic ( mut self , dynamic : bool ) -> Self {
218
+ self . dynamic = dynamic;
219
+ self
220
+ }
221
+
203
222
pub fn columns ( mut self , columns : Vec < ColumnDef > ) -> Self {
204
223
self . columns = columns;
205
224
self
@@ -249,6 +268,11 @@ impl CreateTableBuilder {
249
268
self
250
269
}
251
270
271
+ pub fn version ( mut self , version : Option < TableVersion > ) -> Self {
272
+ self . version = version;
273
+ self
274
+ }
275
+
252
276
pub fn comment_after_column_def ( mut self , comment : Option < CommentDef > ) -> Self {
253
277
self . comment = comment;
254
278
self
@@ -383,24 +407,29 @@ impl CreateTableBuilder {
383
407
self
384
408
}
385
409
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
+ }
402
419
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
404
433
}
405
434
406
435
pub fn build ( self ) -> Statement {
@@ -413,6 +442,7 @@ impl CreateTableBuilder {
413
442
transient : self . transient ,
414
443
volatile : self . volatile ,
415
444
iceberg : self . iceberg ,
445
+ dynamic : self . dynamic ,
416
446
name : self . name ,
417
447
columns : self . columns ,
418
448
constraints : self . constraints ,
@@ -424,6 +454,7 @@ impl CreateTableBuilder {
424
454
without_rowid : self . without_rowid ,
425
455
like : self . like ,
426
456
clone : self . clone ,
457
+ version : self . version ,
427
458
comment : self . comment ,
428
459
on_commit : self . on_commit ,
429
460
on_cluster : self . on_cluster ,
@@ -449,6 +480,11 @@ impl CreateTableBuilder {
449
480
catalog_sync : self . catalog_sync ,
450
481
storage_serialization_policy : self . storage_serialization_policy ,
451
482
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 ,
452
488
} )
453
489
}
454
490
}
@@ -469,6 +505,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
469
505
transient,
470
506
volatile,
471
507
iceberg,
508
+ dynamic,
472
509
name,
473
510
columns,
474
511
constraints,
@@ -480,6 +517,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
480
517
without_rowid,
481
518
like,
482
519
clone,
520
+ version,
483
521
comment,
484
522
on_commit,
485
523
on_cluster,
@@ -505,13 +543,19 @@ impl TryFrom<Statement> for CreateTableBuilder {
505
543
catalog_sync,
506
544
storage_serialization_policy,
507
545
table_options,
546
+ target_lag,
547
+ warehouse,
548
+ refresh_mode,
549
+ initialize,
550
+ require_user,
508
551
} ) => Ok ( Self {
509
552
or_replace,
510
553
temporary,
511
554
external,
512
555
global,
513
556
if_not_exists,
514
557
transient,
558
+ dynamic,
515
559
name,
516
560
columns,
517
561
constraints,
@@ -523,6 +567,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
523
567
without_rowid,
524
568
like,
525
569
clone,
570
+ version,
526
571
comment,
527
572
on_commit,
528
573
on_cluster,
@@ -550,6 +595,11 @@ impl TryFrom<Statement> for CreateTableBuilder {
550
595
catalog_sync,
551
596
storage_serialization_policy,
552
597
table_options,
598
+ target_lag,
599
+ warehouse,
600
+ refresh_mode,
601
+ initialize,
602
+ require_user,
553
603
} ) ,
554
604
_ => Err ( ParserError :: ParserError ( format ! (
555
605
"Expected create table statement, but received: {stmt}"
0 commit comments