Skip to content
Open
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
178 changes: 65 additions & 113 deletions src/ast/helpers/stmt_create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ impl CreateTableBuilder {
self.require_user = require_user;
self
}
/// Consume the builder and produce a `Statement::CreateTable`.
pub fn build(self) -> Statement {
/// Consume the builder and produce a `CreateTable`.
pub fn build(self) -> CreateTable {
CreateTable {
or_replace: self.or_replace,
temporary: self.temporary,
Expand Down Expand Up @@ -561,7 +561,6 @@ impl CreateTableBuilder {
initialize: self.initialize,
require_user: self.require_user,
}
.into()
}
}

Expand All @@ -572,122 +571,74 @@ impl TryFrom<Statement> for CreateTableBuilder {
// ownership.
fn try_from(stmt: Statement) -> Result<Self, Self::Error> {
match stmt {
Statement::CreateTable(CreateTable {
or_replace,
temporary,
external,
global,
if_not_exists,
transient,
volatile,
iceberg,
dynamic,
name,
columns,
constraints,
hive_distribution,
hive_formats,
file_format,
location,
query,
without_rowid,
like,
clone,
version,
comment,
on_commit,
on_cluster,
primary_key,
order_by,
partition_by,
cluster_by,
clustered_by,
inherits,
partition_of,
for_values,
strict,
copy_grants,
enable_schema_evolution,
change_tracking,
data_retention_time_in_days,
max_data_extension_time_in_days,
default_ddl_collation,
with_aggregation_policy,
with_row_access_policy,
with_tags,
base_location,
external_volume,
catalog,
catalog_sync,
storage_serialization_policy,
table_options,
target_lag,
warehouse,
refresh_mode,
initialize,
require_user,
}) => Ok(Self {
or_replace,
temporary,
external,
global,
if_not_exists,
transient,
dynamic,
name,
columns,
constraints,
hive_distribution,
hive_formats,
file_format,
location,
query,
without_rowid,
like,
clone,
version,
comment,
on_commit,
on_cluster,
primary_key,
order_by,
partition_by,
cluster_by,
clustered_by,
inherits,
partition_of,
for_values,
strict,
iceberg,
copy_grants,
enable_schema_evolution,
change_tracking,
data_retention_time_in_days,
max_data_extension_time_in_days,
default_ddl_collation,
with_aggregation_policy,
with_row_access_policy,
with_tags,
volatile,
base_location,
external_volume,
catalog,
catalog_sync,
storage_serialization_policy,
table_options,
target_lag,
warehouse,
refresh_mode,
initialize,
require_user,
}),
Statement::CreateTable(create_table) => Ok(create_table.into()),
_ => Err(ParserError::ParserError(format!(
"Expected create table statement, but received: {stmt}"
))),
}
}
}

impl From<CreateTable> for CreateTableBuilder {
fn from(table: CreateTable) -> Self {
Self {
or_replace: table.or_replace,
temporary: table.temporary,
external: table.external,
global: table.global,
if_not_exists: table.if_not_exists,
transient: table.transient,
volatile: table.volatile,
iceberg: table.iceberg,
dynamic: table.dynamic,
name: table.name,
columns: table.columns,
constraints: table.constraints,
hive_distribution: table.hive_distribution,
hive_formats: table.hive_formats,
file_format: table.file_format,
location: table.location,
query: table.query,
without_rowid: table.without_rowid,
like: table.like,
clone: table.clone,
version: table.version,
comment: table.comment,
on_commit: table.on_commit,
on_cluster: table.on_cluster,
primary_key: table.primary_key,
order_by: table.order_by,
partition_by: table.partition_by,
cluster_by: table.cluster_by,
clustered_by: table.clustered_by,
inherits: table.inherits,
partition_of: table.partition_of,
for_values: table.for_values,
strict: table.strict,
copy_grants: table.copy_grants,
enable_schema_evolution: table.enable_schema_evolution,
change_tracking: table.change_tracking,
data_retention_time_in_days: table.data_retention_time_in_days,
max_data_extension_time_in_days: table.max_data_extension_time_in_days,
default_ddl_collation: table.default_ddl_collation,
with_aggregation_policy: table.with_aggregation_policy,
with_row_access_policy: table.with_row_access_policy,
with_tags: table.with_tags,
base_location: table.base_location,
external_volume: table.external_volume,
catalog: table.catalog,
catalog_sync: table.catalog_sync,
storage_serialization_policy: table.storage_serialization_policy,
table_options: table.table_options,
target_lag: table.target_lag,
warehouse: table.warehouse,
refresh_mode: table.refresh_mode,
initialize: table.initialize,
require_user: table.require_user,
}
}
}

/// Helper return type when parsing configuration for a `CREATE TABLE` statement.
#[derive(Default)]
pub(crate) struct CreateTableConfiguration {
Expand All @@ -707,7 +658,8 @@ mod tests {
pub fn test_from_valid_statement() {
let builder = CreateTableBuilder::new(ObjectName::from(vec![Ident::new("table_name")]));

let stmt = builder.clone().build();
let create_table = builder.clone().build();
let stmt: Statement = create_table.into();

assert_eq!(builder, CreateTableBuilder::try_from(stmt).unwrap());
}
Expand Down
66 changes: 66 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11774,6 +11774,24 @@ impl From<CreateConnector> for Statement {
}
}

impl From<CreateOperator> for Statement {
fn from(c: CreateOperator) -> Self {
Self::CreateOperator(c)
}
}

impl From<CreateOperatorFamily> for Statement {
fn from(c: CreateOperatorFamily) -> Self {
Self::CreateOperatorFamily(c)
}
}

impl From<CreateOperatorClass> for Statement {
fn from(c: CreateOperatorClass) -> Self {
Self::CreateOperatorClass(c)
}
}

impl From<AlterSchema> for Statement {
fn from(a: AlterSchema) -> Self {
Self::AlterSchema(a)
Expand All @@ -11786,6 +11804,36 @@ impl From<AlterType> for Statement {
}
}

impl From<AlterOperator> for Statement {
fn from(a: AlterOperator) -> Self {
Self::AlterOperator(a)
}
}

impl From<AlterOperatorFamily> for Statement {
fn from(a: AlterOperatorFamily) -> Self {
Self::AlterOperatorFamily(a)
}
}

impl From<AlterOperatorClass> for Statement {
fn from(a: AlterOperatorClass) -> Self {
Self::AlterOperatorClass(a)
}
}

impl From<Merge> for Statement {
fn from(m: Merge) -> Self {
Self::Merge(m)
}
}

impl From<AlterUser> for Statement {
fn from(a: AlterUser) -> Self {
Self::AlterUser(a)
}
}

impl From<DropDomain> for Statement {
fn from(d: DropDomain) -> Self {
Self::DropDomain(d)
Expand Down Expand Up @@ -11828,6 +11876,24 @@ impl From<DropTrigger> for Statement {
}
}

impl From<DropOperator> for Statement {
fn from(d: DropOperator) -> Self {
Self::DropOperator(d)
}
}

impl From<DropOperatorFamily> for Statement {
fn from(d: DropOperatorFamily) -> Self {
Self::DropOperatorFamily(d)
}
}

impl From<DropOperatorClass> for Statement {
fn from(d: DropOperatorClass) -> Self {
Self::DropOperatorClass(d)
}
}

impl From<DenyStatement> for Statement {
fn from(d: DenyStatement) -> Self {
Self::Deny(d)
Expand Down
22 changes: 13 additions & 9 deletions src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ use crate::ast::helpers::stmt_data_loading::{
};
use crate::ast::{
AlterTable, AlterTableOperation, AlterTableType, CatalogSyncNamespaceMode, ColumnOption,
ColumnPolicy, ColumnPolicyProperty, ContactEntry, CopyIntoSnowflakeKind, CreateTableLikeKind,
DollarQuotedString, Ident, IdentityParameters, IdentityProperty, IdentityPropertyFormatKind,
IdentityPropertyKind, IdentityPropertyOrder, InitializeKind, ObjectName, ObjectNamePart,
RefreshModeKind, RowAccessPolicy, ShowObjects, SqlOption, Statement,
StorageSerializationPolicy, TagsColumnOption, Value, WrappedCollection,
ColumnPolicy, ColumnPolicyProperty, ContactEntry, CopyIntoSnowflakeKind, CreateTable,
CreateTableLikeKind, DollarQuotedString, Ident, IdentityParameters, IdentityProperty,
IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder, InitializeKind,
ObjectName, ObjectNamePart, RefreshModeKind, RowAccessPolicy, ShowObjects, SqlOption,
Statement, StorageSerializationPolicy, TagsColumnOption, Value, WrappedCollection,
};
use crate::dialect::{Dialect, Precedence};
use crate::keywords::Keyword;
Expand Down Expand Up @@ -272,9 +272,13 @@ impl Dialect for SnowflakeDialect {
// OK - this is CREATE STAGE statement
return Some(parse_create_stage(or_replace, temporary, parser));
} else if parser.parse_keyword(Keyword::TABLE) {
return Some(parse_create_table(
or_replace, global, temporary, volatile, transient, iceberg, dynamic, parser,
));
return Some(
parse_create_table(
or_replace, global, temporary, volatile, transient, iceberg, dynamic,
parser,
)
.map(Into::into),
);
} else if parser.parse_keyword(Keyword::DATABASE) {
return Some(parse_create_database(or_replace, transient, parser));
} else {
Expand Down Expand Up @@ -719,7 +723,7 @@ pub fn parse_create_table(
iceberg: bool,
dynamic: bool,
parser: &mut Parser,
) -> Result<Statement, ParserError> {
) -> Result<CreateTable, ParserError> {
let if_not_exists = parser.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
let table_name = parser.parse_object_name(false)?;

Expand Down
6 changes: 3 additions & 3 deletions src/parser/alter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl Parser<'_> {
/// ```sql
/// ALTER USER [ IF EXISTS ] [ <name> ] [ OPTIONS ]
/// ```
pub fn parse_alter_user(&mut self) -> Result<Statement, ParserError> {
pub fn parse_alter_user(&mut self) -> Result<AlterUser, ParserError> {
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
let name = self.parse_identifier()?;
let _ = self.parse_keyword(Keyword::WITH);
Expand Down Expand Up @@ -309,7 +309,7 @@ impl Parser<'_> {
None
};

Ok(Statement::AlterUser(AlterUser {
Ok(AlterUser {
if_exists,
name,
rename_to,
Expand All @@ -329,7 +329,7 @@ impl Parser<'_> {
set_props,
unset_props,
password,
}))
})
}

fn parse_mfa_method(&mut self) -> Result<MfaMethodKind, ParserError> {
Expand Down
Loading