Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3024,6 +3024,9 @@ pub struct CreateTable {
/// Snowflake "BASE_LOCATION" clause for Iceberg tables
/// <https://docs.snowflake.com/en/sql-reference/sql/create-iceberg-table>
pub base_location: Option<String>,
/// Snowflake "ICEBERG_VERSION" clause for Iceberg tables.
/// <https://docs.snowflake.com/en/sql-reference/sql/create-iceberg-table-snowflake>
pub iceberg_version: Option<u64>,
/// Snowflake "CATALOG" clause for Iceberg tables
/// <https://docs.snowflake.com/en/sql-reference/sql/create-iceberg-table>
pub catalog: Option<String>,
Expand Down Expand Up @@ -3265,6 +3268,9 @@ impl fmt::Display for CreateTable {
if let Some(base_location) = self.base_location.as_ref() {
write!(f, " BASE_LOCATION='{base_location}'")?;
}
if let Some(iceberg_version) = self.iceberg_version {
write!(f, " ICEBERG_VERSION={iceberg_version}")?;
}
}

if let Some(catalog_sync) = self.catalog_sync.as_ref() {
Expand Down
5 changes: 5 additions & 0 deletions src/ast/helpers/stmt_create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ pub struct CreateTableBuilder {
pub with_tags: Option<Vec<Tag>>,
/// Optional base location for staged data.
pub base_location: Option<String>,
/// Optional Iceberg format version.
pub iceberg_version: Option<u64>,
/// Optional external volume identifier.
pub external_volume: Option<String>,
/// Optional catalog name.
Expand Down Expand Up @@ -234,6 +236,7 @@ impl CreateTableBuilder {
with_storage_lifecycle_policy: None,
with_tags: None,
base_location: None,
iceberg_version: None,
external_volume: None,
catalog: None,
catalog_sync: None,
Expand Down Expand Up @@ -604,6 +607,7 @@ impl CreateTableBuilder {
with_storage_lifecycle_policy: self.with_storage_lifecycle_policy,
with_tags: self.with_tags,
base_location: self.base_location,
iceberg_version: self.iceberg_version,
external_volume: self.external_volume,
catalog: self.catalog,
catalog_sync: self.catalog_sync,
Expand Down Expand Up @@ -685,6 +689,7 @@ impl From<CreateTable> for CreateTableBuilder {
with_storage_lifecycle_policy: table.with_storage_lifecycle_policy,
with_tags: table.with_tags,
base_location: table.base_location,
iceberg_version: table.iceberg_version,
external_volume: table.external_volume,
catalog: table.catalog,
catalog_sync: table.catalog_sync,
Expand Down
1 change: 1 addition & 0 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ impl Spanned for CreateTable {
with_tags: _, // todo, Snowflake specific
external_volume: _, // todo, Snowflake specific
base_location: _, // todo, Snowflake specific
iceberg_version: _, // u64, no span
catalog: _, // todo, Snowflake specific
catalog_sync: _, // todo, Snowflake specific
storage_serialization_policy: _,
Expand Down
10 changes: 4 additions & 6 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,10 @@ pub fn parse_create_table(
parser.expect_token(&Token::Eq)?;
builder.base_location = Some(parser.parse_literal_string()?);
}
Keyword::ICEBERG_VERSION if iceberg => {
parser.expect_token(&Token::Eq)?;
builder.iceberg_version = Some(parser.parse_literal_uint()?);
}
Keyword::CATALOG_SYNC => {
parser.expect_token(&Token::Eq)?;
builder.catalog_sync = Some(parser.parse_literal_string()?);
Expand Down Expand Up @@ -1131,12 +1135,6 @@ pub fn parse_create_table(

builder = builder.table_options(table_options);

if iceberg && builder.base_location.is_none() {
return Err(ParserError::ParserError(
"BASE_LOCATION is required for ICEBERG tables".to_string(),
));
}

Ok(builder.build())
}

Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ define_keywords!(
HUGEINT,
IAM_ROLE,
ICEBERG,
ICEBERG_VERSION,
ID,
IDENTIFIED,
IDENTITY,
Expand Down
1 change: 1 addition & 0 deletions tests/sqlparser_duckdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ fn test_duckdb_union_datatype() {
with_storage_lifecycle_policy: Default::default(),
with_tags: Default::default(),
base_location: Default::default(),
iceberg_version: Default::default(),
external_volume: Default::default(),
catalog: Default::default(),
catalog_sync: Default::default(),
Expand Down
2 changes: 2 additions & 0 deletions tests/sqlparser_mssql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,7 @@ fn parse_create_table_with_valid_options() {
with_storage_lifecycle_policy: None,
with_tags: None,
base_location: None,
iceberg_version: None,
external_volume: None,
catalog: None,
catalog_sync: None,
Expand Down Expand Up @@ -2177,6 +2178,7 @@ fn parse_create_table_with_identity_column() {
with_storage_lifecycle_policy: None,
with_tags: None,
base_location: None,
iceberg_version: None,
external_volume: None,
catalog: None,
catalog_sync: None,
Expand Down
1 change: 1 addition & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6702,6 +6702,7 @@ fn parse_trigger_related_functions() {
with_storage_lifecycle_policy: None,
with_tags: None,
base_location: None,
iceberg_version: None,
external_volume: None,
catalog: None,
catalog_sync: None,
Expand Down
28 changes: 23 additions & 5 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,11 +1070,29 @@ fn test_snowflake_create_iceberg_table() {

#[test]
fn test_snowflake_create_iceberg_table_without_location() {
let res = snowflake().parse_sql_statements("CREATE ICEBERG TABLE my_table (a INT)");
assert_eq!(
ParserError::ParserError("BASE_LOCATION is required for ICEBERG tables".to_string()),
res.unwrap_err()
);
match snowflake().verified_stmt("CREATE ICEBERG TABLE my_table (a INT)") {
Statement::CreateTable(table) => assert_eq!(table.base_location, None),
_ => unreachable!(),
}
}

#[test]
fn test_snowflake_create_iceberg_table_version() {
for version in [2, 3] {
let sql = format!(
"CREATE ICEBERG TABLE my_table (a INT) EXTERNAL_VOLUME='SNOWFLAKE_MANAGED' CATALOG='SNOWFLAKE' ICEBERG_VERSION={version}"
);
match snowflake().verified_stmt(&sql) {
Statement::CreateTable(table) => {
assert_eq!(table.iceberg_version, Some(version));
assert_eq!(table.base_location, None);
}
_ => unreachable!(),
}
}
assert!(snowflake()
.parse_sql_statements("CREATE TABLE my_table (a INT) ICEBERG_VERSION=3")
.is_err());
}

#[test]
Expand Down
Loading