1#[cfg(not(feature = "std"))]
19use alloc::{boxed::Box, format, string::String, vec, vec::Vec};
20
21#[cfg(feature = "serde")]
22use serde::{Deserialize, Serialize};
23
24#[cfg(feature = "visitor")]
25use sqlparser_derive::{Visit, VisitMut};
26
27use crate::ast::{
28 ClusteredBy, ColumnDef, CommentDef, CreateTable, CreateTableLikeKind, CreateTableOptions, Expr,
29 FileFormat, ForValues, HiveDistributionStyle, HiveFormat, Ident, InitializeKind, ObjectName,
30 OnCommit, OneOrManyWithParens, Query, RefreshModeKind, RowAccessPolicy, Statement,
31 StorageSerializationPolicy, TableConstraint, TableVersion, Tag, WrappedCollection,
32};
33
34use crate::parser::ParserError;
35
36#[derive(#[automatically_derived]
impl ::core::fmt::Debug for CreateTableBuilder {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["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"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.or_replace, &self.temporary, &self.external, &self.global,
&self.if_not_exists, &self.transient, &self.volatile,
&self.iceberg, &self.dynamic, &self.name, &self.columns,
&self.constraints, &self.hive_distribution,
&self.hive_formats, &self.file_format, &self.location,
&self.query, &self.without_rowid, &self.like, &self.clone,
&self.version, &self.comment, &self.on_commit,
&self.on_cluster, &self.primary_key, &self.order_by,
&self.partition_by, &self.cluster_by, &self.clustered_by,
&self.inherits, &self.partition_of, &self.for_values,
&self.strict, &self.copy_grants,
&self.enable_schema_evolution, &self.change_tracking,
&self.data_retention_time_in_days,
&self.max_data_extension_time_in_days,
&self.default_ddl_collation, &self.with_aggregation_policy,
&self.with_row_access_policy, &self.with_tags,
&self.base_location, &self.external_volume, &self.catalog,
&self.catalog_sync, &self.storage_serialization_policy,
&self.table_options, &self.target_lag, &self.warehouse,
&self.refresh_mode, &self.initialize, &&self.require_user];
::core::fmt::Formatter::debug_struct_fields_finish(f,
"CreateTableBuilder", names, values)
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for CreateTableBuilder {
#[inline]
fn clone(&self) -> CreateTableBuilder {
CreateTableBuilder {
or_replace: ::core::clone::Clone::clone(&self.or_replace),
temporary: ::core::clone::Clone::clone(&self.temporary),
external: ::core::clone::Clone::clone(&self.external),
global: ::core::clone::Clone::clone(&self.global),
if_not_exists: ::core::clone::Clone::clone(&self.if_not_exists),
transient: ::core::clone::Clone::clone(&self.transient),
volatile: ::core::clone::Clone::clone(&self.volatile),
iceberg: ::core::clone::Clone::clone(&self.iceberg),
dynamic: ::core::clone::Clone::clone(&self.dynamic),
name: ::core::clone::Clone::clone(&self.name),
columns: ::core::clone::Clone::clone(&self.columns),
constraints: ::core::clone::Clone::clone(&self.constraints),
hive_distribution: ::core::clone::Clone::clone(&self.hive_distribution),
hive_formats: ::core::clone::Clone::clone(&self.hive_formats),
file_format: ::core::clone::Clone::clone(&self.file_format),
location: ::core::clone::Clone::clone(&self.location),
query: ::core::clone::Clone::clone(&self.query),
without_rowid: ::core::clone::Clone::clone(&self.without_rowid),
like: ::core::clone::Clone::clone(&self.like),
clone: ::core::clone::Clone::clone(&self.clone),
version: ::core::clone::Clone::clone(&self.version),
comment: ::core::clone::Clone::clone(&self.comment),
on_commit: ::core::clone::Clone::clone(&self.on_commit),
on_cluster: ::core::clone::Clone::clone(&self.on_cluster),
primary_key: ::core::clone::Clone::clone(&self.primary_key),
order_by: ::core::clone::Clone::clone(&self.order_by),
partition_by: ::core::clone::Clone::clone(&self.partition_by),
cluster_by: ::core::clone::Clone::clone(&self.cluster_by),
clustered_by: ::core::clone::Clone::clone(&self.clustered_by),
inherits: ::core::clone::Clone::clone(&self.inherits),
partition_of: ::core::clone::Clone::clone(&self.partition_of),
for_values: ::core::clone::Clone::clone(&self.for_values),
strict: ::core::clone::Clone::clone(&self.strict),
copy_grants: ::core::clone::Clone::clone(&self.copy_grants),
enable_schema_evolution: ::core::clone::Clone::clone(&self.enable_schema_evolution),
change_tracking: ::core::clone::Clone::clone(&self.change_tracking),
data_retention_time_in_days: ::core::clone::Clone::clone(&self.data_retention_time_in_days),
max_data_extension_time_in_days: ::core::clone::Clone::clone(&self.max_data_extension_time_in_days),
default_ddl_collation: ::core::clone::Clone::clone(&self.default_ddl_collation),
with_aggregation_policy: ::core::clone::Clone::clone(&self.with_aggregation_policy),
with_row_access_policy: ::core::clone::Clone::clone(&self.with_row_access_policy),
with_tags: ::core::clone::Clone::clone(&self.with_tags),
base_location: ::core::clone::Clone::clone(&self.base_location),
external_volume: ::core::clone::Clone::clone(&self.external_volume),
catalog: ::core::clone::Clone::clone(&self.catalog),
catalog_sync: ::core::clone::Clone::clone(&self.catalog_sync),
storage_serialization_policy: ::core::clone::Clone::clone(&self.storage_serialization_policy),
table_options: ::core::clone::Clone::clone(&self.table_options),
target_lag: ::core::clone::Clone::clone(&self.target_lag),
warehouse: ::core::clone::Clone::clone(&self.warehouse),
refresh_mode: ::core::clone::Clone::clone(&self.refresh_mode),
initialize: ::core::clone::Clone::clone(&self.initialize),
require_user: ::core::clone::Clone::clone(&self.require_user),
}
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for CreateTableBuilder {
#[inline]
fn eq(&self, other: &CreateTableBuilder) -> bool {
self.or_replace == other.or_replace &&
self.temporary == other.temporary &&
self.external == other.external &&
self.if_not_exists == other.if_not_exists &&
self.transient == other.transient &&
self.volatile == other.volatile &&
self.iceberg == other.iceberg &&
self.dynamic == other.dynamic &&
self.without_rowid == other.without_rowid &&
self.strict == other.strict &&
self.copy_grants == other.copy_grants &&
self.require_user == other.require_user &&
self.global == other.global && self.name == other.name &&
self.columns == other.columns &&
self.constraints == other.constraints &&
self.hive_distribution == other.hive_distribution &&
self.hive_formats == other.hive_formats &&
self.file_format == other.file_format &&
self.location == other.location && self.query == other.query
&& self.like == other.like && self.clone == other.clone &&
self.version == other.version &&
self.comment == other.comment &&
self.on_commit == other.on_commit &&
self.on_cluster == other.on_cluster &&
self.primary_key == other.primary_key &&
self.order_by == other.order_by &&
self.partition_by == other.partition_by &&
self.cluster_by == other.cluster_by &&
self.clustered_by == other.clustered_by &&
self.inherits == other.inherits &&
self.partition_of == other.partition_of &&
self.for_values == other.for_values &&
self.enable_schema_evolution ==
other.enable_schema_evolution &&
self.change_tracking == other.change_tracking &&
self.data_retention_time_in_days ==
other.data_retention_time_in_days &&
self.max_data_extension_time_in_days ==
other.max_data_extension_time_in_days &&
self.default_ddl_collation == other.default_ddl_collation &&
self.with_aggregation_policy ==
other.with_aggregation_policy &&
self.with_row_access_policy == other.with_row_access_policy
&& self.with_tags == other.with_tags &&
self.base_location == other.base_location &&
self.external_volume == other.external_volume &&
self.catalog == other.catalog &&
self.catalog_sync == other.catalog_sync &&
self.storage_serialization_policy ==
other.storage_serialization_policy &&
self.table_options == other.table_options &&
self.target_lag == other.target_lag &&
self.warehouse == other.warehouse &&
self.refresh_mode == other.refresh_mode &&
self.initialize == other.initialize
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for CreateTableBuilder {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<Option<bool>>;
let _: ::core::cmp::AssertParamIsEq<ObjectName>;
let _: ::core::cmp::AssertParamIsEq<Vec<ColumnDef>>;
let _: ::core::cmp::AssertParamIsEq<Vec<TableConstraint>>;
let _: ::core::cmp::AssertParamIsEq<HiveDistributionStyle>;
let _: ::core::cmp::AssertParamIsEq<Option<HiveFormat>>;
let _: ::core::cmp::AssertParamIsEq<Option<FileFormat>>;
let _: ::core::cmp::AssertParamIsEq<Option<String>>;
let _: ::core::cmp::AssertParamIsEq<Option<Box<Query>>>;
let _: ::core::cmp::AssertParamIsEq<Option<CreateTableLikeKind>>;
let _: ::core::cmp::AssertParamIsEq<Option<ObjectName>>;
let _: ::core::cmp::AssertParamIsEq<Option<TableVersion>>;
let _: ::core::cmp::AssertParamIsEq<Option<CommentDef>>;
let _: ::core::cmp::AssertParamIsEq<Option<OnCommit>>;
let _: ::core::cmp::AssertParamIsEq<Option<Ident>>;
let _: ::core::cmp::AssertParamIsEq<Option<Box<Expr>>>;
let _:
::core::cmp::AssertParamIsEq<Option<OneOrManyWithParens<Expr>>>;
let _: ::core::cmp::AssertParamIsEq<Option<Box<Expr>>>;
let _:
::core::cmp::AssertParamIsEq<Option<WrappedCollection<Vec<Expr>>>>;
let _: ::core::cmp::AssertParamIsEq<Option<ClusteredBy>>;
let _: ::core::cmp::AssertParamIsEq<Option<Vec<ObjectName>>>;
let _: ::core::cmp::AssertParamIsEq<Option<ObjectName>>;
let _: ::core::cmp::AssertParamIsEq<Option<ForValues>>;
let _: ::core::cmp::AssertParamIsEq<Option<bool>>;
let _: ::core::cmp::AssertParamIsEq<Option<bool>>;
let _: ::core::cmp::AssertParamIsEq<Option<u64>>;
let _: ::core::cmp::AssertParamIsEq<Option<u64>>;
let _: ::core::cmp::AssertParamIsEq<Option<String>>;
let _: ::core::cmp::AssertParamIsEq<Option<ObjectName>>;
let _: ::core::cmp::AssertParamIsEq<Option<RowAccessPolicy>>;
let _: ::core::cmp::AssertParamIsEq<Option<Vec<Tag>>>;
let _: ::core::cmp::AssertParamIsEq<Option<String>>;
let _: ::core::cmp::AssertParamIsEq<Option<String>>;
let _: ::core::cmp::AssertParamIsEq<Option<String>>;
let _: ::core::cmp::AssertParamIsEq<Option<String>>;
let _:
::core::cmp::AssertParamIsEq<Option<StorageSerializationPolicy>>;
let _: ::core::cmp::AssertParamIsEq<CreateTableOptions>;
let _: ::core::cmp::AssertParamIsEq<Option<String>>;
let _: ::core::cmp::AssertParamIsEq<Option<Ident>>;
let _: ::core::cmp::AssertParamIsEq<Option<RefreshModeKind>>;
let _: ::core::cmp::AssertParamIsEq<Option<InitializeKind>>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for CreateTableBuilder {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.or_replace, state);
::core::hash::Hash::hash(&self.temporary, state);
::core::hash::Hash::hash(&self.external, state);
::core::hash::Hash::hash(&self.global, state);
::core::hash::Hash::hash(&self.if_not_exists, state);
::core::hash::Hash::hash(&self.transient, state);
::core::hash::Hash::hash(&self.volatile, state);
::core::hash::Hash::hash(&self.iceberg, state);
::core::hash::Hash::hash(&self.dynamic, state);
::core::hash::Hash::hash(&self.name, state);
::core::hash::Hash::hash(&self.columns, state);
::core::hash::Hash::hash(&self.constraints, state);
::core::hash::Hash::hash(&self.hive_distribution, state);
::core::hash::Hash::hash(&self.hive_formats, state);
::core::hash::Hash::hash(&self.file_format, state);
::core::hash::Hash::hash(&self.location, state);
::core::hash::Hash::hash(&self.query, state);
::core::hash::Hash::hash(&self.without_rowid, state);
::core::hash::Hash::hash(&self.like, state);
::core::hash::Hash::hash(&self.clone, state);
::core::hash::Hash::hash(&self.version, state);
::core::hash::Hash::hash(&self.comment, state);
::core::hash::Hash::hash(&self.on_commit, state);
::core::hash::Hash::hash(&self.on_cluster, state);
::core::hash::Hash::hash(&self.primary_key, state);
::core::hash::Hash::hash(&self.order_by, state);
::core::hash::Hash::hash(&self.partition_by, state);
::core::hash::Hash::hash(&self.cluster_by, state);
::core::hash::Hash::hash(&self.clustered_by, state);
::core::hash::Hash::hash(&self.inherits, state);
::core::hash::Hash::hash(&self.partition_of, state);
::core::hash::Hash::hash(&self.for_values, state);
::core::hash::Hash::hash(&self.strict, state);
::core::hash::Hash::hash(&self.copy_grants, state);
::core::hash::Hash::hash(&self.enable_schema_evolution, state);
::core::hash::Hash::hash(&self.change_tracking, state);
::core::hash::Hash::hash(&self.data_retention_time_in_days, state);
::core::hash::Hash::hash(&self.max_data_extension_time_in_days,
state);
::core::hash::Hash::hash(&self.default_ddl_collation, state);
::core::hash::Hash::hash(&self.with_aggregation_policy, state);
::core::hash::Hash::hash(&self.with_row_access_policy, state);
::core::hash::Hash::hash(&self.with_tags, state);
::core::hash::Hash::hash(&self.base_location, state);
::core::hash::Hash::hash(&self.external_volume, state);
::core::hash::Hash::hash(&self.catalog, state);
::core::hash::Hash::hash(&self.catalog_sync, state);
::core::hash::Hash::hash(&self.storage_serialization_policy, state);
::core::hash::Hash::hash(&self.table_options, state);
::core::hash::Hash::hash(&self.target_lag, state);
::core::hash::Hash::hash(&self.warehouse, state);
::core::hash::Hash::hash(&self.refresh_mode, state);
::core::hash::Hash::hash(&self.initialize, state);
::core::hash::Hash::hash(&self.require_user, state)
}
}Hash)]
64#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
65#[cfg_attr(feature = "visitor", derive(impl sqlparser::ast::Visit for CreateTableBuilder {
fn visit<V: sqlparser::ast::Visitor>(&self, visitor: &mut V)
-> ::std::ops::ControlFlow<V::Break> {
::recursive::__impl::stacker::maybe_grow(::recursive::get_minimum_stack_size(),
::recursive::get_stack_allocation_size(),
move || -> ::std::ops::ControlFlow<V::Break>
{
{
sqlparser::ast::Visit::visit(&self.or_replace, visitor)?;
sqlparser::ast::Visit::visit(&self.temporary, visitor)?;
sqlparser::ast::Visit::visit(&self.external, visitor)?;
sqlparser::ast::Visit::visit(&self.global, visitor)?;
sqlparser::ast::Visit::visit(&self.if_not_exists, visitor)?;
sqlparser::ast::Visit::visit(&self.transient, visitor)?;
sqlparser::ast::Visit::visit(&self.volatile, visitor)?;
sqlparser::ast::Visit::visit(&self.iceberg, visitor)?;
sqlparser::ast::Visit::visit(&self.dynamic, visitor)?;
sqlparser::ast::Visit::visit(&self.name, visitor)?;
sqlparser::ast::Visit::visit(&self.columns, visitor)?;
sqlparser::ast::Visit::visit(&self.constraints, visitor)?;
sqlparser::ast::Visit::visit(&self.hive_distribution,
visitor)?;
sqlparser::ast::Visit::visit(&self.hive_formats, visitor)?;
sqlparser::ast::Visit::visit(&self.file_format, visitor)?;
sqlparser::ast::Visit::visit(&self.location, visitor)?;
sqlparser::ast::Visit::visit(&self.query, visitor)?;
sqlparser::ast::Visit::visit(&self.without_rowid, visitor)?;
sqlparser::ast::Visit::visit(&self.like, visitor)?;
sqlparser::ast::Visit::visit(&self.clone, visitor)?;
sqlparser::ast::Visit::visit(&self.version, visitor)?;
sqlparser::ast::Visit::visit(&self.comment, visitor)?;
sqlparser::ast::Visit::visit(&self.on_commit, visitor)?;
sqlparser::ast::Visit::visit(&self.on_cluster, visitor)?;
sqlparser::ast::Visit::visit(&self.primary_key, visitor)?;
sqlparser::ast::Visit::visit(&self.order_by, visitor)?;
sqlparser::ast::Visit::visit(&self.partition_by, visitor)?;
sqlparser::ast::Visit::visit(&self.cluster_by, visitor)?;
sqlparser::ast::Visit::visit(&self.clustered_by, visitor)?;
sqlparser::ast::Visit::visit(&self.inherits, visitor)?;
sqlparser::ast::Visit::visit(&self.partition_of, visitor)?;
sqlparser::ast::Visit::visit(&self.for_values, visitor)?;
sqlparser::ast::Visit::visit(&self.strict, visitor)?;
sqlparser::ast::Visit::visit(&self.copy_grants, visitor)?;
sqlparser::ast::Visit::visit(&self.enable_schema_evolution,
visitor)?;
sqlparser::ast::Visit::visit(&self.change_tracking,
visitor)?;
sqlparser::ast::Visit::visit(&self.data_retention_time_in_days,
visitor)?;
sqlparser::ast::Visit::visit(&self.max_data_extension_time_in_days,
visitor)?;
sqlparser::ast::Visit::visit(&self.default_ddl_collation,
visitor)?;
sqlparser::ast::Visit::visit(&self.with_aggregation_policy,
visitor)?;
sqlparser::ast::Visit::visit(&self.with_row_access_policy,
visitor)?;
sqlparser::ast::Visit::visit(&self.with_tags, visitor)?;
sqlparser::ast::Visit::visit(&self.base_location, visitor)?;
sqlparser::ast::Visit::visit(&self.external_volume,
visitor)?;
sqlparser::ast::Visit::visit(&self.catalog, visitor)?;
sqlparser::ast::Visit::visit(&self.catalog_sync, visitor)?;
sqlparser::ast::Visit::visit(&self.storage_serialization_policy,
visitor)?;
sqlparser::ast::Visit::visit(&self.table_options, visitor)?;
sqlparser::ast::Visit::visit(&self.target_lag, visitor)?;
sqlparser::ast::Visit::visit(&self.warehouse, visitor)?;
sqlparser::ast::Visit::visit(&self.refresh_mode, visitor)?;
sqlparser::ast::Visit::visit(&self.initialize, visitor)?;
sqlparser::ast::Visit::visit(&self.require_user, visitor)?;
::std::ops::ControlFlow::Continue(())
}
})
}
}Visit, impl sqlparser::ast::VisitMut for CreateTableBuilder {
fn visit<V: sqlparser::ast::VisitorMut>(&mut self, visitor: &mut V)
-> ::std::ops::ControlFlow<V::Break> {
::recursive::__impl::stacker::maybe_grow(::recursive::get_minimum_stack_size(),
::recursive::get_stack_allocation_size(),
move || -> ::std::ops::ControlFlow<V::Break>
{
{
sqlparser::ast::VisitMut::visit(&mut self.or_replace,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.temporary,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.external,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.global, visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.if_not_exists,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.transient,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.volatile,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.iceberg,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.dynamic,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.name, visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.columns,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.constraints,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.hive_distribution,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.hive_formats,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.file_format,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.location,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.query, visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.without_rowid,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.like, visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.clone, visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.version,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.comment,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.on_commit,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.on_cluster,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.primary_key,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.order_by,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.partition_by,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.cluster_by,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.clustered_by,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.inherits,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.partition_of,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.for_values,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.strict, visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.copy_grants,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.enable_schema_evolution,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.change_tracking,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.data_retention_time_in_days,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.max_data_extension_time_in_days,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.default_ddl_collation,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.with_aggregation_policy,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.with_row_access_policy,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.with_tags,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.base_location,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.external_volume,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.catalog,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.catalog_sync,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.storage_serialization_policy,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.table_options,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.target_lag,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.warehouse,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.refresh_mode,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.initialize,
visitor)?;
sqlparser::ast::VisitMut::visit(&mut self.require_user,
visitor)?;
::std::ops::ControlFlow::Continue(())
}
})
}
}VisitMut))]
66pub struct CreateTableBuilder {
67 pub or_replace: bool,
69 pub temporary: bool,
71 pub external: bool,
73 pub global: Option<bool>,
75 pub if_not_exists: bool,
77 pub transient: bool,
79 pub volatile: bool,
81 pub iceberg: bool,
83 pub dynamic: bool,
85 pub name: ObjectName,
87 pub columns: Vec<ColumnDef>,
89 pub constraints: Vec<TableConstraint>,
91 pub hive_distribution: HiveDistributionStyle,
93 pub hive_formats: Option<HiveFormat>,
95 pub file_format: Option<FileFormat>,
97 pub location: Option<String>,
99 pub query: Option<Box<Query>>,
101 pub without_rowid: bool,
103 pub like: Option<CreateTableLikeKind>,
105 pub clone: Option<ObjectName>,
107 pub version: Option<TableVersion>,
109 pub comment: Option<CommentDef>,
111 pub on_commit: Option<OnCommit>,
113 pub on_cluster: Option<Ident>,
115 pub primary_key: Option<Box<Expr>>,
117 pub order_by: Option<OneOrManyWithParens<Expr>>,
119 pub partition_by: Option<Box<Expr>>,
121 pub cluster_by: Option<WrappedCollection<Vec<Expr>>>,
123 pub clustered_by: Option<ClusteredBy>,
125 pub inherits: Option<Vec<ObjectName>>,
127 pub partition_of: Option<ObjectName>,
129 pub for_values: Option<ForValues>,
131 pub strict: bool,
133 pub copy_grants: bool,
135 pub enable_schema_evolution: Option<bool>,
137 pub change_tracking: Option<bool>,
139 pub data_retention_time_in_days: Option<u64>,
141 pub max_data_extension_time_in_days: Option<u64>,
143 pub default_ddl_collation: Option<String>,
145 pub with_aggregation_policy: Option<ObjectName>,
147 pub with_row_access_policy: Option<RowAccessPolicy>,
149 pub with_tags: Option<Vec<Tag>>,
151 pub base_location: Option<String>,
153 pub external_volume: Option<String>,
155 pub catalog: Option<String>,
157 pub catalog_sync: Option<String>,
159 pub storage_serialization_policy: Option<StorageSerializationPolicy>,
161 pub table_options: CreateTableOptions,
163 pub target_lag: Option<String>,
165 pub warehouse: Option<Ident>,
167 pub refresh_mode: Option<RefreshModeKind>,
169 pub initialize: Option<InitializeKind>,
171 pub require_user: bool,
173}
174
175impl CreateTableBuilder {
176 pub fn new(name: ObjectName) -> Self {
178 Self {
179 or_replace: false,
180 temporary: false,
181 external: false,
182 global: None,
183 if_not_exists: false,
184 transient: false,
185 volatile: false,
186 iceberg: false,
187 dynamic: false,
188 name,
189 columns: ::alloc::vec::Vec::new()vec![],
190 constraints: ::alloc::vec::Vec::new()vec![],
191 hive_distribution: HiveDistributionStyle::NONE,
192 hive_formats: None,
193 file_format: None,
194 location: None,
195 query: None,
196 without_rowid: false,
197 like: None,
198 clone: None,
199 version: None,
200 comment: None,
201 on_commit: None,
202 on_cluster: None,
203 primary_key: None,
204 order_by: None,
205 partition_by: None,
206 cluster_by: None,
207 clustered_by: None,
208 inherits: None,
209 partition_of: None,
210 for_values: None,
211 strict: false,
212 copy_grants: false,
213 enable_schema_evolution: None,
214 change_tracking: None,
215 data_retention_time_in_days: None,
216 max_data_extension_time_in_days: None,
217 default_ddl_collation: None,
218 with_aggregation_policy: None,
219 with_row_access_policy: None,
220 with_tags: None,
221 base_location: None,
222 external_volume: None,
223 catalog: None,
224 catalog_sync: None,
225 storage_serialization_policy: None,
226 table_options: CreateTableOptions::None,
227 target_lag: None,
228 warehouse: None,
229 refresh_mode: None,
230 initialize: None,
231 require_user: false,
232 }
233 }
234 pub fn or_replace(mut self, or_replace: bool) -> Self {
236 self.or_replace = or_replace;
237 self
238 }
239 pub fn temporary(mut self, temporary: bool) -> Self {
241 self.temporary = temporary;
242 self
243 }
244 pub fn external(mut self, external: bool) -> Self {
246 self.external = external;
247 self
248 }
249 pub fn global(mut self, global: Option<bool>) -> Self {
251 self.global = global;
252 self
253 }
254 pub fn if_not_exists(mut self, if_not_exists: bool) -> Self {
256 self.if_not_exists = if_not_exists;
257 self
258 }
259 pub fn transient(mut self, transient: bool) -> Self {
261 self.transient = transient;
262 self
263 }
264 pub fn volatile(mut self, volatile: bool) -> Self {
266 self.volatile = volatile;
267 self
268 }
269 pub fn iceberg(mut self, iceberg: bool) -> Self {
271 self.iceberg = iceberg;
272 self
273 }
274 pub fn dynamic(mut self, dynamic: bool) -> Self {
276 self.dynamic = dynamic;
277 self
278 }
279 pub fn columns(mut self, columns: Vec<ColumnDef>) -> Self {
281 self.columns = columns;
282 self
283 }
284 pub fn constraints(mut self, constraints: Vec<TableConstraint>) -> Self {
286 self.constraints = constraints;
287 self
288 }
289 pub fn hive_distribution(mut self, hive_distribution: HiveDistributionStyle) -> Self {
291 self.hive_distribution = hive_distribution;
292 self
293 }
294 pub fn hive_formats(mut self, hive_formats: Option<HiveFormat>) -> Self {
296 self.hive_formats = hive_formats;
297 self
298 }
299 pub fn file_format(mut self, file_format: Option<FileFormat>) -> Self {
301 self.file_format = file_format;
302 self
303 }
304 pub fn location(mut self, location: Option<String>) -> Self {
306 self.location = location;
307 self
308 }
309 pub fn query(mut self, query: Option<Box<Query>>) -> Self {
311 self.query = query;
312 self
313 }
314 pub fn without_rowid(mut self, without_rowid: bool) -> Self {
316 self.without_rowid = without_rowid;
317 self
318 }
319 pub fn like(mut self, like: Option<CreateTableLikeKind>) -> Self {
321 self.like = like;
322 self
323 }
324 pub fn clone_clause(mut self, clone: Option<ObjectName>) -> Self {
327 self.clone = clone;
328 self
329 }
330 pub fn version(mut self, version: Option<TableVersion>) -> Self {
332 self.version = version;
333 self
334 }
335 pub fn comment_after_column_def(mut self, comment: Option<CommentDef>) -> Self {
337 self.comment = comment;
338 self
339 }
340 pub fn on_commit(mut self, on_commit: Option<OnCommit>) -> Self {
342 self.on_commit = on_commit;
343 self
344 }
345 pub fn on_cluster(mut self, on_cluster: Option<Ident>) -> Self {
347 self.on_cluster = on_cluster;
348 self
349 }
350 pub fn primary_key(mut self, primary_key: Option<Box<Expr>>) -> Self {
352 self.primary_key = primary_key;
353 self
354 }
355 pub fn order_by(mut self, order_by: Option<OneOrManyWithParens<Expr>>) -> Self {
357 self.order_by = order_by;
358 self
359 }
360 pub fn partition_by(mut self, partition_by: Option<Box<Expr>>) -> Self {
362 self.partition_by = partition_by;
363 self
364 }
365 pub fn cluster_by(mut self, cluster_by: Option<WrappedCollection<Vec<Expr>>>) -> Self {
367 self.cluster_by = cluster_by;
368 self
369 }
370 pub fn clustered_by(mut self, clustered_by: Option<ClusteredBy>) -> Self {
372 self.clustered_by = clustered_by;
373 self
374 }
375 pub fn inherits(mut self, inherits: Option<Vec<ObjectName>>) -> Self {
377 self.inherits = inherits;
378 self
379 }
380
381 pub fn partition_of(mut self, partition_of: Option<ObjectName>) -> Self {
383 self.partition_of = partition_of;
384 self
385 }
386
387 pub fn for_values(mut self, for_values: Option<ForValues>) -> Self {
389 self.for_values = for_values;
390 self
391 }
392
393 pub fn strict(mut self, strict: bool) -> Self {
395 self.strict = strict;
396 self
397 }
398 pub fn copy_grants(mut self, copy_grants: bool) -> Self {
400 self.copy_grants = copy_grants;
401 self
402 }
403 pub fn enable_schema_evolution(mut self, enable_schema_evolution: Option<bool>) -> Self {
405 self.enable_schema_evolution = enable_schema_evolution;
406 self
407 }
408 pub fn change_tracking(mut self, change_tracking: Option<bool>) -> Self {
410 self.change_tracking = change_tracking;
411 self
412 }
413 pub fn data_retention_time_in_days(mut self, data_retention_time_in_days: Option<u64>) -> Self {
415 self.data_retention_time_in_days = data_retention_time_in_days;
416 self
417 }
418 pub fn max_data_extension_time_in_days(
420 mut self,
421 max_data_extension_time_in_days: Option<u64>,
422 ) -> Self {
423 self.max_data_extension_time_in_days = max_data_extension_time_in_days;
424 self
425 }
426 pub fn default_ddl_collation(mut self, default_ddl_collation: Option<String>) -> Self {
428 self.default_ddl_collation = default_ddl_collation;
429 self
430 }
431 pub fn with_aggregation_policy(mut self, with_aggregation_policy: Option<ObjectName>) -> Self {
433 self.with_aggregation_policy = with_aggregation_policy;
434 self
435 }
436 pub fn with_row_access_policy(
438 mut self,
439 with_row_access_policy: Option<RowAccessPolicy>,
440 ) -> Self {
441 self.with_row_access_policy = with_row_access_policy;
442 self
443 }
444 pub fn with_tags(mut self, with_tags: Option<Vec<Tag>>) -> Self {
446 self.with_tags = with_tags;
447 self
448 }
449 pub fn base_location(mut self, base_location: Option<String>) -> Self {
451 self.base_location = base_location;
452 self
453 }
454 pub fn external_volume(mut self, external_volume: Option<String>) -> Self {
456 self.external_volume = external_volume;
457 self
458 }
459 pub fn catalog(mut self, catalog: Option<String>) -> Self {
461 self.catalog = catalog;
462 self
463 }
464 pub fn catalog_sync(mut self, catalog_sync: Option<String>) -> Self {
466 self.catalog_sync = catalog_sync;
467 self
468 }
469 pub fn storage_serialization_policy(
471 mut self,
472 storage_serialization_policy: Option<StorageSerializationPolicy>,
473 ) -> Self {
474 self.storage_serialization_policy = storage_serialization_policy;
475 self
476 }
477 pub fn table_options(mut self, table_options: CreateTableOptions) -> Self {
479 self.table_options = table_options;
480 self
481 }
482 pub fn target_lag(mut self, target_lag: Option<String>) -> Self {
484 self.target_lag = target_lag;
485 self
486 }
487 pub fn warehouse(mut self, warehouse: Option<Ident>) -> Self {
489 self.warehouse = warehouse;
490 self
491 }
492 pub fn refresh_mode(mut self, refresh_mode: Option<RefreshModeKind>) -> Self {
494 self.refresh_mode = refresh_mode;
495 self
496 }
497 pub fn initialize(mut self, initialize: Option<InitializeKind>) -> Self {
499 self.initialize = initialize;
500 self
501 }
502 pub fn require_user(mut self, require_user: bool) -> Self {
504 self.require_user = require_user;
505 self
506 }
507 pub fn build(self) -> CreateTable {
509 CreateTable {
510 or_replace: self.or_replace,
511 temporary: self.temporary,
512 external: self.external,
513 global: self.global,
514 if_not_exists: self.if_not_exists,
515 transient: self.transient,
516 volatile: self.volatile,
517 iceberg: self.iceberg,
518 dynamic: self.dynamic,
519 name: self.name,
520 columns: self.columns,
521 constraints: self.constraints,
522 hive_distribution: self.hive_distribution,
523 hive_formats: self.hive_formats,
524 file_format: self.file_format,
525 location: self.location,
526 query: self.query,
527 without_rowid: self.without_rowid,
528 like: self.like,
529 clone: self.clone,
530 version: self.version,
531 comment: self.comment,
532 on_commit: self.on_commit,
533 on_cluster: self.on_cluster,
534 primary_key: self.primary_key,
535 order_by: self.order_by,
536 partition_by: self.partition_by,
537 cluster_by: self.cluster_by,
538 clustered_by: self.clustered_by,
539 inherits: self.inherits,
540 partition_of: self.partition_of,
541 for_values: self.for_values,
542 strict: self.strict,
543 copy_grants: self.copy_grants,
544 enable_schema_evolution: self.enable_schema_evolution,
545 change_tracking: self.change_tracking,
546 data_retention_time_in_days: self.data_retention_time_in_days,
547 max_data_extension_time_in_days: self.max_data_extension_time_in_days,
548 default_ddl_collation: self.default_ddl_collation,
549 with_aggregation_policy: self.with_aggregation_policy,
550 with_row_access_policy: self.with_row_access_policy,
551 with_tags: self.with_tags,
552 base_location: self.base_location,
553 external_volume: self.external_volume,
554 catalog: self.catalog,
555 catalog_sync: self.catalog_sync,
556 storage_serialization_policy: self.storage_serialization_policy,
557 table_options: self.table_options,
558 target_lag: self.target_lag,
559 warehouse: self.warehouse,
560 refresh_mode: self.refresh_mode,
561 initialize: self.initialize,
562 require_user: self.require_user,
563 }
564 }
565}
566
567impl TryFrom<Statement> for CreateTableBuilder {
568 type Error = ParserError;
569
570 fn try_from(stmt: Statement) -> Result<Self, Self::Error> {
573 match stmt {
574 Statement::CreateTable(create_table) => Ok(create_table.into()),
575 _ => Err(ParserError::ParserError(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Expected create table statement, but received: {0}",
stmt))
})format!(
576 "Expected create table statement, but received: {stmt}"
577 ))),
578 }
579 }
580}
581
582impl From<CreateTable> for CreateTableBuilder {
583 fn from(table: CreateTable) -> Self {
584 Self {
585 or_replace: table.or_replace,
586 temporary: table.temporary,
587 external: table.external,
588 global: table.global,
589 if_not_exists: table.if_not_exists,
590 transient: table.transient,
591 volatile: table.volatile,
592 iceberg: table.iceberg,
593 dynamic: table.dynamic,
594 name: table.name,
595 columns: table.columns,
596 constraints: table.constraints,
597 hive_distribution: table.hive_distribution,
598 hive_formats: table.hive_formats,
599 file_format: table.file_format,
600 location: table.location,
601 query: table.query,
602 without_rowid: table.without_rowid,
603 like: table.like,
604 clone: table.clone,
605 version: table.version,
606 comment: table.comment,
607 on_commit: table.on_commit,
608 on_cluster: table.on_cluster,
609 primary_key: table.primary_key,
610 order_by: table.order_by,
611 partition_by: table.partition_by,
612 cluster_by: table.cluster_by,
613 clustered_by: table.clustered_by,
614 inherits: table.inherits,
615 partition_of: table.partition_of,
616 for_values: table.for_values,
617 strict: table.strict,
618 copy_grants: table.copy_grants,
619 enable_schema_evolution: table.enable_schema_evolution,
620 change_tracking: table.change_tracking,
621 data_retention_time_in_days: table.data_retention_time_in_days,
622 max_data_extension_time_in_days: table.max_data_extension_time_in_days,
623 default_ddl_collation: table.default_ddl_collation,
624 with_aggregation_policy: table.with_aggregation_policy,
625 with_row_access_policy: table.with_row_access_policy,
626 with_tags: table.with_tags,
627 base_location: table.base_location,
628 external_volume: table.external_volume,
629 catalog: table.catalog,
630 catalog_sync: table.catalog_sync,
631 storage_serialization_policy: table.storage_serialization_policy,
632 table_options: table.table_options,
633 target_lag: table.target_lag,
634 warehouse: table.warehouse,
635 refresh_mode: table.refresh_mode,
636 initialize: table.initialize,
637 require_user: table.require_user,
638 }
639 }
640}
641
642#[derive(#[automatically_derived]
impl ::core::default::Default for CreateTableConfiguration {
#[inline]
fn default() -> CreateTableConfiguration {
CreateTableConfiguration {
partition_by: ::core::default::Default::default(),
cluster_by: ::core::default::Default::default(),
inherits: ::core::default::Default::default(),
table_options: ::core::default::Default::default(),
}
}
}Default)]
644pub(crate) struct CreateTableConfiguration {
645 pub partition_by: Option<Box<Expr>>,
646 pub cluster_by: Option<WrappedCollection<Vec<Expr>>>,
647 pub inherits: Option<Vec<ObjectName>>,
648 pub table_options: CreateTableOptions,
649}
650
651#[cfg(test)]
652mod tests {
653 use crate::ast::helpers::stmt_create_table::CreateTableBuilder;
654 use crate::ast::{Ident, ObjectName, Statement};
655 use crate::parser::ParserError;
656
657 #[test]
658 pub fn test_from_valid_statement() {
659 let builder = CreateTableBuilder::new(ObjectName::from(vec![Ident::new("table_name")]));
660
661 let create_table = builder.clone().build();
662 let stmt: Statement = create_table.into();
663
664 assert_eq!(builder, CreateTableBuilder::try_from(stmt).unwrap());
665 }
666
667 #[test]
668 pub fn test_from_invalid_statement() {
669 let stmt = Statement::Commit {
670 chain: false,
671 end: false,
672 modifier: None,
673 };
674
675 assert_eq!(
676 CreateTableBuilder::try_from(stmt).unwrap_err(),
677 ParserError::ParserError(
678 "Expected create table statement, but received: COMMIT".to_owned()
679 )
680 );
681 }
682}