@@ -33,7 +33,7 @@ pub use self::ddl::{
33
33
AlterColumnOperation , AlterIndexOperation , AlterTableOperation , ColumnDef , ColumnOption ,
34
34
ColumnOptionDef , GeneratedAs , GeneratedExpressionMode , IndexType , KeyOrIndexDisplay , Partition ,
35
35
ProcedureParam , ReferentialAction , TableConstraint , UserDefinedTypeCompositeAttributeDef ,
36
- UserDefinedTypeRepresentation ,
36
+ UserDefinedTypeRepresentation , ViewColumnDef ,
37
37
} ;
38
38
pub use self :: operator:: { BinaryOperator , UnaryOperator } ;
39
39
pub use self :: query:: {
@@ -1364,6 +1364,38 @@ pub enum Password {
1364
1364
NullPassword ,
1365
1365
}
1366
1366
1367
+ /// Sql options of a `CREATE TABLE` statement.
1368
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
1369
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1370
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1371
+ pub enum CreateTableOptions {
1372
+ None ,
1373
+ /// Options specified using the `WITH` keyword.
1374
+ /// e.g. `WITH (description = "123")`
1375
+ ///
1376
+ /// <https://www.postgresql.org/docs/current/sql-createtable.html>
1377
+ With ( Vec < SqlOption > ) ,
1378
+ /// Options specified using the `OPTIONS` keyword.
1379
+ /// e.g. `OPTIONS (description = "123")`
1380
+ ///
1381
+ /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#table_option_list>
1382
+ Options ( Vec < SqlOption > ) ,
1383
+ }
1384
+
1385
+ impl fmt:: Display for CreateTableOptions {
1386
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1387
+ match self {
1388
+ CreateTableOptions :: With ( with_options) => {
1389
+ write ! ( f, "WITH ({})" , display_comma_separated( with_options) )
1390
+ }
1391
+ CreateTableOptions :: Options ( options) => {
1392
+ write ! ( f, "OPTIONS ({})" , display_comma_separated( options) )
1393
+ }
1394
+ CreateTableOptions :: None => Ok ( ( ) ) ,
1395
+ }
1396
+ }
1397
+ }
1398
+
1367
1399
/// A top-level statement (SELECT, INSERT, CREATE, etc.)
1368
1400
#[ allow( clippy:: large_enum_variant) ]
1369
1401
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
@@ -1512,9 +1544,9 @@ pub enum Statement {
1512
1544
materialized : bool ,
1513
1545
/// View name
1514
1546
name : ObjectName ,
1515
- columns : Vec < Ident > ,
1547
+ columns : Vec < ViewColumnDef > ,
1516
1548
query : Box < Query > ,
1517
- with_options : Vec < SqlOption > ,
1549
+ options : CreateTableOptions ,
1518
1550
cluster_by : Vec < Ident > ,
1519
1551
/// if true, has RedShift [`WITH NO SCHEMA BINDING`] clause <https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_VIEW.html>
1520
1552
with_no_schema_binding : bool ,
@@ -1560,6 +1592,9 @@ pub enum Statement {
1560
1592
/// than empty (represented as ()), the latter meaning "no sorting".
1561
1593
/// <https://clickhouse.com/docs/en/sql-reference/statements/create/table/>
1562
1594
order_by : Option < Vec < Ident > > ,
1595
+ /// BigQuery specific configuration during table creation.
1596
+ /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_table_statement>
1597
+ big_query_config : Option < Box < BigQueryCreateTableConfiguration > > ,
1563
1598
/// SQLite "STRICT" clause.
1564
1599
/// if the "STRICT" table-option keyword is added to the end, after the closing ")",
1565
1600
/// then strict typing rules apply to that table.
@@ -2499,7 +2534,7 @@ impl fmt::Display for Statement {
2499
2534
columns,
2500
2535
query,
2501
2536
materialized,
2502
- with_options ,
2537
+ options ,
2503
2538
cluster_by,
2504
2539
with_no_schema_binding,
2505
2540
if_not_exists,
@@ -2514,15 +2549,18 @@ impl fmt::Display for Statement {
2514
2549
temporary = if * temporary { "TEMPORARY " } else { "" } ,
2515
2550
if_not_exists = if * if_not_exists { "IF NOT EXISTS " } else { "" }
2516
2551
) ?;
2517
- if !with_options . is_empty ( ) {
2518
- write ! ( f, " WITH ({})" , display_comma_separated ( with_options ) ) ?;
2552
+ if matches ! ( options , CreateTableOptions :: With ( _ ) ) {
2553
+ write ! ( f, " {options}" ) ?;
2519
2554
}
2520
2555
if !columns. is_empty ( ) {
2521
2556
write ! ( f, " ({})" , display_comma_separated( columns) ) ?;
2522
2557
}
2523
2558
if !cluster_by. is_empty ( ) {
2524
2559
write ! ( f, " CLUSTER BY ({})" , display_comma_separated( cluster_by) ) ?;
2525
2560
}
2561
+ if matches ! ( options, CreateTableOptions :: Options ( _) ) {
2562
+ write ! ( f, " {options}" ) ?;
2563
+ }
2526
2564
write ! ( f, " AS {query}" ) ?;
2527
2565
if * with_no_schema_binding {
2528
2566
write ! ( f, " WITH NO SCHEMA BINDING" ) ?;
@@ -2557,6 +2595,7 @@ impl fmt::Display for Statement {
2557
2595
on_commit,
2558
2596
on_cluster,
2559
2597
order_by,
2598
+ big_query_config,
2560
2599
strict,
2561
2600
} => {
2562
2601
// We want to allow the following options
@@ -2713,6 +2752,25 @@ impl fmt::Display for Statement {
2713
2752
if let Some ( order_by) = order_by {
2714
2753
write ! ( f, " ORDER BY ({})" , display_comma_separated( order_by) ) ?;
2715
2754
}
2755
+ if let Some ( bigquery_config) = big_query_config {
2756
+ if let Some ( partition_by) = bigquery_config. partition_by . as_ref ( ) {
2757
+ write ! ( f, " PARTITION BY {partition_by}" ) ?;
2758
+ }
2759
+ if let Some ( cluster_by) = bigquery_config. cluster_by . as_ref ( ) {
2760
+ write ! (
2761
+ f,
2762
+ " CLUSTER BY {}" ,
2763
+ display_comma_separated( cluster_by. as_slice( ) )
2764
+ ) ?;
2765
+ }
2766
+ if let Some ( options) = bigquery_config. options . as_ref ( ) {
2767
+ write ! (
2768
+ f,
2769
+ " OPTIONS({})" ,
2770
+ display_comma_separated( options. as_slice( ) )
2771
+ ) ?;
2772
+ }
2773
+ }
2716
2774
if let Some ( query) = query {
2717
2775
write ! ( f, " AS {query}" ) ?;
2718
2776
}
@@ -4220,12 +4278,31 @@ pub struct HiveFormat {
4220
4278
pub location : Option < String > ,
4221
4279
}
4222
4280
4281
+ /// Represents BigQuery specific configuration like partitioning, clustering
4282
+ /// information during table creation.
4283
+ ///
4284
+ /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_table_statement>
4285
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
4286
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
4287
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
4288
+ pub struct BigQueryCreateTableConfiguration {
4289
+ /// A partition expression for the table.
4290
+ /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#partition_expression>
4291
+ pub partition_by : Option < Expr > ,
4292
+ /// Table clustering column list.
4293
+ /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#table_option_list>
4294
+ pub cluster_by : Option < Vec < Ident > > ,
4295
+ /// Table options list.
4296
+ /// <https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#table_option_list>
4297
+ pub options : Option < Vec < SqlOption > > ,
4298
+ }
4299
+
4223
4300
#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
4224
4301
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
4225
4302
#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
4226
4303
pub struct SqlOption {
4227
4304
pub name : Ident ,
4228
- pub value : Value ,
4305
+ pub value : Expr ,
4229
4306
}
4230
4307
4231
4308
impl fmt:: Display for SqlOption {
0 commit comments