Skip to content

Commit 23dd7c2

Browse files
committed
Rebase and code review comments
1 parent c45d605 commit 23dd7c2

File tree

5 files changed

+71
-518
lines changed

5 files changed

+71
-518
lines changed

src/ast/ddl.rs

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@ use sqlparser_derive::{Visit, VisitMut};
3030

3131
use crate::ast::value::escape_single_quote_string;
3232
use crate::ast::{
33-
display_comma_separated, display_separated, ArgMode, CommentDef, CreateFunctionBody,
34-
CreateFunctionUsing, CreateTableLikeKind, CreateTableOptions, DataType, Expr, FileFormat,
35-
FunctionBehavior, FunctionCalledOnNull, FunctionDeterminismSpecifier, FunctionParallel,
36-
HiveDistributionStyle, HiveFormat, HiveIOFormat, HiveRowFormat, Ident, MySQLColumnPosition,
37-
ObjectName, OnCommit, OneOrManyWithParens, OperateFunctionArg, OrderByExpr, ProjectionSelect,
38-
Query, RowAccessPolicy, SequenceOptions, Spanned, SqlOption, StorageSerializationPolicy, Tag,
39-
Value, ValueWithSpan, WrappedCollection,
33+
display_comma_separated, display_separated, ArgMode, CommentDef, CreateFunctionBody, CreateFunctionUsing, CreateTableLikeKind, CreateTableOptions, DataType, Expr, FileFormat, FunctionBehavior, FunctionCalledOnNull, FunctionDeterminismSpecifier, FunctionParallel, HiveDistributionStyle, HiveFormat, HiveIOFormat, HiveRowFormat, Ident, InitializeKind, MySQLColumnPosition, ObjectName, OnCommit, OneOrManyWithParens, OperateFunctionArg, OrderByExpr, ProjectionSelect, Query, RefreshModeKind, RowAccessPolicy, SequenceOptions, Spanned, SqlOption, StorageSerializationPolicy, TableVersion, Tag, Value, ValueWithSpan, WrappedCollection
4034
};
4135
use crate::display_utils::{DisplayCommaSeparated, Indent, NewLine, SpaceOrNewline};
4236
use crate::keywords::Keyword;
@@ -2428,6 +2422,7 @@ pub struct CreateTable {
24282422
pub or_replace: bool,
24292423
pub temporary: bool,
24302424
pub external: bool,
2425+
pub dynamic: bool,
24312426
pub global: Option<bool>,
24322427
pub if_not_exists: bool,
24332428
pub transient: bool,
@@ -2448,6 +2443,7 @@ pub struct CreateTable {
24482443
pub without_rowid: bool,
24492444
pub like: Option<CreateTableLikeKind>,
24502445
pub clone: Option<ObjectName>,
2446+
pub version: Option<TableVersion>,
24512447
// For Hive dialect, the table comment is after the column definitions without `=`,
24522448
// so the `comment` field is optional and different than the comment field in the general options list.
24532449
// [Hive](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTable)
@@ -2525,6 +2521,21 @@ pub struct CreateTable {
25252521
/// Snowflake "STORAGE_SERIALIZATION_POLICY" clause for Iceberg tables
25262522
/// <https://docs.snowflake.com/en/sql-reference/sql/create-iceberg-table>
25272523
pub storage_serialization_policy: Option<StorageSerializationPolicy>,
2524+
/// Snowflake "TARGET_LAG" clause for dybamic tables
2525+
/// <https://docs.snowflake.com/en/sql-reference/sql/create-dynamic-table>
2526+
pub target_lag: Option<String>,
2527+
/// Snowflake "WAREHOUSE" clause for dybamic tables
2528+
/// <https://docs.snowflake.com/en/sql-reference/sql/create-dynamic-table>
2529+
pub warehouse: Option<Ident>,
2530+
/// Snowflake "REFRESH_MODE" clause for dybamic tables
2531+
/// <https://docs.snowflake.com/en/sql-reference/sql/create-dynamic-table>
2532+
pub refresh_mode: Option<RefreshModeKind>,
2533+
/// Snowflake "INITIALIZE" clause for dybamic tables
2534+
/// <https://docs.snowflake.com/en/sql-reference/sql/create-dynamic-table>
2535+
pub initialize: Option<InitializeKind>,
2536+
/// Snowflake "REQUIRE USER" clause for dybamic tables
2537+
/// <https://docs.snowflake.com/en/sql-reference/sql/create-dynamic-table>
2538+
pub require_user: bool,
25282539
}
25292540

25302541
impl fmt::Display for CreateTable {
@@ -2538,7 +2549,7 @@ impl fmt::Display for CreateTable {
25382549
// `CREATE TABLE t (a INT) AS SELECT a from t2`
25392550
write!(
25402551
f,
2541-
"CREATE {or_replace}{external}{global}{temporary}{transient}{volatile}{iceberg}TABLE {if_not_exists}{name}",
2552+
"CREATE {or_replace}{external}{global}{temporary}{transient}{volatile}{dynamic}{iceberg}TABLE {if_not_exists}{name}",
25422553
or_replace = if self.or_replace { "OR REPLACE " } else { "" },
25432554
external = if self.external { "EXTERNAL " } else { "" },
25442555
global = self.global
@@ -2556,6 +2567,7 @@ impl fmt::Display for CreateTable {
25562567
volatile = if self.volatile { "VOLATILE " } else { "" },
25572568
// Only for Snowflake
25582569
iceberg = if self.iceberg { "ICEBERG " } else { "" },
2570+
dynamic = if self.dynamic { "DYNAMIC " } else { "" },
25592571
name = self.name,
25602572
)?;
25612573
if let Some(on_cluster) = &self.on_cluster {
@@ -2598,6 +2610,10 @@ impl fmt::Display for CreateTable {
25982610
write!(f, " CLONE {c}")?;
25992611
}
26002612

2613+
if let Some(version) = &self.version {
2614+
write!(f, " {version}")?;
2615+
}
2616+
26012617
match &self.hive_distribution {
26022618
HiveDistributionStyle::PARTITIONED { columns } => {
26032619
write!(f, " PARTITIONED BY ({})", display_comma_separated(columns))?;
@@ -2700,27 +2716,27 @@ impl fmt::Display for CreateTable {
27002716
write!(f, " {options}")?;
27012717
}
27022718
if let Some(external_volume) = self.external_volume.as_ref() {
2703-
write!(f, " EXTERNAL_VOLUME = '{external_volume}'")?;
2719+
write!(f, " EXTERNAL_VOLUME='{external_volume}'")?;
27042720
}
27052721

27062722
if let Some(catalog) = self.catalog.as_ref() {
2707-
write!(f, " CATALOG = '{catalog}'")?;
2723+
write!(f, " CATALOG='{catalog}'")?;
27082724
}
27092725

27102726
if self.iceberg {
27112727
if let Some(base_location) = self.base_location.as_ref() {
2712-
write!(f, " BASE_LOCATION = '{base_location}'")?;
2728+
write!(f, " BASE_LOCATION='{base_location}'")?;
27132729
}
27142730
}
27152731

27162732
if let Some(catalog_sync) = self.catalog_sync.as_ref() {
2717-
write!(f, " CATALOG_SYNC = '{catalog_sync}'")?;
2733+
write!(f, " CATALOG_SYNC='{catalog_sync}'")?;
27182734
}
27192735

27202736
if let Some(storage_serialization_policy) = self.storage_serialization_policy.as_ref() {
27212737
write!(
27222738
f,
2723-
" STORAGE_SERIALIZATION_POLICY = {storage_serialization_policy}"
2739+
" STORAGE_SERIALIZATION_POLICY={storage_serialization_policy}"
27242740
)?;
27252741
}
27262742

@@ -2774,6 +2790,26 @@ impl fmt::Display for CreateTable {
27742790
write!(f, " WITH TAG ({})", display_comma_separated(tag.as_slice()))?;
27752791
}
27762792

2793+
if let Some(target_lag) = &self.target_lag {
2794+
write!(f, " TARGET_LAG='{target_lag}'")?;
2795+
}
2796+
2797+
if let Some(warehouse) = &self.warehouse {
2798+
write!(f, " WAREHOUSE={warehouse}")?;
2799+
}
2800+
2801+
if let Some(refresh_mode) = &self.refresh_mode {
2802+
write!(f, " REFRESH_MODE={refresh_mode}")?;
2803+
}
2804+
2805+
if let Some(initialize) = &self.initialize {
2806+
write!(f, " INITIALIZE={initialize}")?;
2807+
}
2808+
2809+
if self.require_user {
2810+
write!(f, " REQUIRE USER")?;
2811+
}
2812+
27772813
if self.on_commit.is_some() {
27782814
let on_commit = match self.on_commit {
27792815
Some(OnCommit::DeleteRows) => "ON COMMIT DELETE ROWS",

0 commit comments

Comments
 (0)