@@ -33,11 +33,11 @@ pub use super::ddl::{ColumnDef, TableConstraint};
33
33
34
34
use super :: {
35
35
display_comma_separated, display_separated, query:: InputFormatClause , Assignment , ClusteredBy ,
36
- CommentDef , Expr , FileFormat , FromTable , HiveDistributionStyle , HiveFormat , HiveIOFormat ,
37
- HiveRowFormat , Ident , IndexType , InsertAliases , MysqlInsertPriority , ObjectName , OnCommit ,
38
- OnInsert , OneOrManyWithParens , OrderByExpr , Query , RowAccessPolicy , SelectItem , Setting ,
39
- SqlOption , SqliteOnConflict , StorageSerializationPolicy , TableEngine , TableObject ,
40
- TableWithJoins , Tag , WrappedCollection ,
36
+ CommentDef , CreateTableOptions , Expr , FileFormat , FromTable , HiveDistributionStyle , HiveFormat ,
37
+ HiveIOFormat , HiveRowFormat , Ident , IndexType , InsertAliases , MysqlInsertPriority , ObjectName ,
38
+ OnCommit , OnInsert , OneOrManyWithParens , OrderByExpr , Query , RowAccessPolicy , SelectItem ,
39
+ Setting , SqliteOnConflict , StorageSerializationPolicy , TableObject , TableWithJoins , Tag ,
40
+ WrappedCollection ,
41
41
} ;
42
42
43
43
/// Index column type.
@@ -146,19 +146,17 @@ pub struct CreateTable {
146
146
pub constraints : Vec < TableConstraint > ,
147
147
pub hive_distribution : HiveDistributionStyle ,
148
148
pub hive_formats : Option < HiveFormat > ,
149
- pub table_properties : Vec < SqlOption > ,
150
- pub with_options : Vec < SqlOption > ,
149
+ pub table_options : CreateTableOptions ,
151
150
pub file_format : Option < FileFormat > ,
152
151
pub location : Option < String > ,
153
152
pub query : Option < Box < Query > > ,
154
153
pub without_rowid : bool ,
155
154
pub like : Option < ObjectName > ,
156
155
pub clone : Option < ObjectName > ,
157
- pub engine : Option < TableEngine > ,
156
+ // For Hive dialect, the table comment is after the column definitions without `=`,
157
+ // so the `comment` field is optional and different than the comment field in the general options list.
158
+ // [Hive](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTable)
158
159
pub comment : Option < CommentDef > ,
159
- pub auto_increment_offset : Option < u32 > ,
160
- pub default_charset : Option < String > ,
161
- pub collation : Option < String > ,
162
160
pub on_commit : Option < OnCommit > ,
163
161
/// ClickHouse "ON CLUSTER" clause:
164
162
/// <https://clickhouse.com/docs/en/sql-reference/distributed-ddl/>
@@ -179,9 +177,6 @@ pub struct CreateTable {
179
177
/// Hive: Table clustering column list.
180
178
/// <https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTable>
181
179
pub clustered_by : Option < ClusteredBy > ,
182
- /// BigQuery: Table options list.
183
- /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#table_option_list>
184
- pub options : Option < Vec < SqlOption > > ,
185
180
/// Postgres `INHERITs` clause, which contains the list of tables from which
186
181
/// the new table inherits.
187
182
/// <https://www.postgresql.org/docs/current/ddl-inherit.html>
@@ -282,7 +277,7 @@ impl Display for CreateTable {
282
277
283
278
// Hive table comment should be after column definitions, please refer to:
284
279
// [Hive](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTable)
285
- if let Some ( CommentDef :: AfterColumnDefsWithoutEq ( comment) ) = & self . comment {
280
+ if let Some ( comment) = & self . comment {
286
281
write ! ( f, " COMMENT '{comment}'" ) ?;
287
282
}
288
283
@@ -375,35 +370,14 @@ impl Display for CreateTable {
375
370
}
376
371
write ! ( f, " LOCATION '{}'" , self . location. as_ref( ) . unwrap( ) ) ?;
377
372
}
378
- if !self . table_properties . is_empty ( ) {
379
- write ! (
380
- f,
381
- " TBLPROPERTIES ({})" ,
382
- display_comma_separated( & self . table_properties)
383
- ) ?;
384
- }
385
- if !self . with_options . is_empty ( ) {
386
- write ! ( f, " WITH ({})" , display_comma_separated( & self . with_options) ) ?;
387
- }
388
- if let Some ( engine) = & self . engine {
389
- write ! ( f, " ENGINE={engine}" ) ?;
390
- }
391
- if let Some ( comment_def) = & self . comment {
392
- match comment_def {
393
- CommentDef :: WithEq ( comment) => {
394
- write ! ( f, " COMMENT = '{comment}'" ) ?;
395
- }
396
- CommentDef :: WithoutEq ( comment) => {
397
- write ! ( f, " COMMENT '{comment}'" ) ?;
398
- }
399
- // For CommentDef::AfterColumnDefsWithoutEq will be displayed after column definition
400
- CommentDef :: AfterColumnDefsWithoutEq ( _) => ( ) ,
401
- }
402
- }
403
373
404
- if let Some ( auto_increment_offset) = self . auto_increment_offset {
405
- write ! ( f, " AUTO_INCREMENT {auto_increment_offset}" ) ?;
374
+ match & self . table_options {
375
+ options @ CreateTableOptions :: With ( _)
376
+ | options @ CreateTableOptions :: Plain ( _)
377
+ | options @ CreateTableOptions :: TableProperties ( _) => write ! ( f, " {}" , options) ?,
378
+ _ => ( ) ,
406
379
}
380
+
407
381
if let Some ( primary_key) = & self . primary_key {
408
382
write ! ( f, " PRIMARY KEY {}" , primary_key) ?;
409
383
}
@@ -419,15 +393,9 @@ impl Display for CreateTable {
419
393
if let Some ( cluster_by) = self . cluster_by . as_ref ( ) {
420
394
write ! ( f, " CLUSTER BY {cluster_by}" ) ?;
421
395
}
422
-
423
- if let Some ( options) = self . options . as_ref ( ) {
424
- write ! (
425
- f,
426
- " OPTIONS({})" ,
427
- display_comma_separated( options. as_slice( ) )
428
- ) ?;
396
+ if let options @ CreateTableOptions :: Options ( _) = & self . table_options {
397
+ write ! ( f, " {}" , options) ?;
429
398
}
430
-
431
399
if let Some ( external_volume) = self . external_volume . as_ref ( ) {
432
400
write ! ( f, " EXTERNAL_VOLUME = '{external_volume}'" ) ?;
433
401
}
@@ -503,13 +471,6 @@ impl Display for CreateTable {
503
471
write ! ( f, " WITH TAG ({})" , display_comma_separated( tag. as_slice( ) ) ) ?;
504
472
}
505
473
506
- if let Some ( default_charset) = & self . default_charset {
507
- write ! ( f, " DEFAULT CHARSET={default_charset}" ) ?;
508
- }
509
- if let Some ( collation) = & self . collation {
510
- write ! ( f, " COLLATE={collation}" ) ?;
511
- }
512
-
513
474
if self . on_commit . is_some ( ) {
514
475
let on_commit = match self . on_commit {
515
476
Some ( OnCommit :: DeleteRows ) => "ON COMMIT DELETE ROWS" ,
0 commit comments