Skip to main content

sqlparser/ast/helpers/
stmt_create_table.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18#[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/// Builder for create table statement variant ([1]).
37///
38/// This structure helps building and accessing a create table with more ease, without needing to:
39/// - Match the enum itself a lot of times; or
40/// - Moving a lot of variables around the code.
41///
42/// # Example
43/// ```rust
44/// use sqlparser::ast::helpers::stmt_create_table::CreateTableBuilder;
45/// use sqlparser::ast::{ColumnDef, DataType, Ident, ObjectName};
46/// let builder = CreateTableBuilder::new(ObjectName::from(vec![Ident::new("table_name")]))
47///    .if_not_exists(true)
48///    .columns(vec![ColumnDef {
49///        name: Ident::new("c1"),
50///        data_type: DataType::Int(None),
51///        options: vec![],
52/// }]);
53/// // You can access internal elements with ease
54/// assert!(builder.if_not_exists);
55/// // Convert to a statement
56/// assert_eq!(
57///    builder.build().to_string(),
58///    "CREATE TABLE IF NOT EXISTS table_name (c1 INT)"
59/// )
60/// ```
61///
62/// [1]: crate::ast::Statement::CreateTable
63#[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    /// Whether the statement uses `OR REPLACE`.
68    pub or_replace: bool,
69    /// Whether the table is `TEMPORARY`.
70    pub temporary: bool,
71    /// Whether the table is `EXTERNAL`.
72    pub external: bool,
73    /// Optional `GLOBAL` flag for dialects that support it.
74    pub global: Option<bool>,
75    /// Whether `IF NOT EXISTS` was specified.
76    pub if_not_exists: bool,
77    /// Whether `TRANSIENT` was specified.
78    pub transient: bool,
79    /// Whether `VOLATILE` was specified.
80    pub volatile: bool,
81    /// Iceberg-specific table flag.
82    pub iceberg: bool,
83    /// Whether `DYNAMIC` table option is set.
84    pub dynamic: bool,
85    /// The table name.
86    pub name: ObjectName,
87    /// Column definitions for the table.
88    pub columns: Vec<ColumnDef>,
89    /// Table-level constraints.
90    pub constraints: Vec<TableConstraint>,
91    /// Hive distribution style.
92    pub hive_distribution: HiveDistributionStyle,
93    /// Optional Hive format settings.
94    pub hive_formats: Option<HiveFormat>,
95    /// Optional file format for storage.
96    pub file_format: Option<FileFormat>,
97    /// Optional storage location.
98    pub location: Option<String>,
99    /// Optional `AS SELECT` query for the table.
100    pub query: Option<Box<Query>>,
101    /// Whether `WITHOUT ROWID` is set.
102    pub without_rowid: bool,
103    /// Optional `LIKE` clause kind.
104    pub like: Option<CreateTableLikeKind>,
105    /// Optional `CLONE` source object name.
106    pub clone: Option<ObjectName>,
107    /// Optional table version.
108    pub version: Option<TableVersion>,
109    /// Optional table comment.
110    pub comment: Option<CommentDef>,
111    /// Optional `ON COMMIT` behavior.
112    pub on_commit: Option<OnCommit>,
113    /// Optional cluster identifier.
114    pub on_cluster: Option<Ident>,
115    /// Optional primary key expression.
116    pub primary_key: Option<Box<Expr>>,
117    /// Optional `ORDER BY` for clustering/sorting.
118    pub order_by: Option<OneOrManyWithParens<Expr>>,
119    /// Optional `PARTITION BY` expression.
120    pub partition_by: Option<Box<Expr>>,
121    /// Optional `CLUSTER BY` expressions.
122    pub cluster_by: Option<WrappedCollection<Vec<Expr>>>,
123    /// Optional `CLUSTERED BY` clause.
124    pub clustered_by: Option<ClusteredBy>,
125    /// Optional parent tables (`INHERITS`).
126    pub inherits: Option<Vec<ObjectName>>,
127    /// Optional partitioned table (`PARTITION OF`)
128    pub partition_of: Option<ObjectName>,
129    /// Range of values associated with the partition (`FOR VALUES`)
130    pub for_values: Option<ForValues>,
131    /// `STRICT` table flag.
132    pub strict: bool,
133    /// Whether to copy grants from the source.
134    pub copy_grants: bool,
135    /// Optional flag for schema evolution support.
136    pub enable_schema_evolution: Option<bool>,
137    /// Optional change tracking flag.
138    pub change_tracking: Option<bool>,
139    /// Optional data retention time in days.
140    pub data_retention_time_in_days: Option<u64>,
141    /// Optional max data extension time in days.
142    pub max_data_extension_time_in_days: Option<u64>,
143    /// Optional default DDL collation.
144    pub default_ddl_collation: Option<String>,
145    /// Optional aggregation policy object name.
146    pub with_aggregation_policy: Option<ObjectName>,
147    /// Optional row access policy applied to the table.
148    pub with_row_access_policy: Option<RowAccessPolicy>,
149    /// Optional tags/labels attached to the table metadata.
150    pub with_tags: Option<Vec<Tag>>,
151    /// Optional base location for staged data.
152    pub base_location: Option<String>,
153    /// Optional external volume identifier.
154    pub external_volume: Option<String>,
155    /// Optional catalog name.
156    pub catalog: Option<String>,
157    /// Optional catalog synchronization option.
158    pub catalog_sync: Option<String>,
159    /// Optional storage serialization policy.
160    pub storage_serialization_policy: Option<StorageSerializationPolicy>,
161    /// Parsed table options from the statement.
162    pub table_options: CreateTableOptions,
163    /// Optional target lag configuration.
164    pub target_lag: Option<String>,
165    /// Optional warehouse identifier.
166    pub warehouse: Option<Ident>,
167    /// Optional refresh mode for materialized tables.
168    pub refresh_mode: Option<RefreshModeKind>,
169    /// Optional initialization kind for the table.
170    pub initialize: Option<InitializeKind>,
171    /// Whether operations require a user identity.
172    pub require_user: bool,
173}
174
175impl CreateTableBuilder {
176    /// Create a new `CreateTableBuilder` for the given table name.
177    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    /// Set `OR REPLACE` for the CREATE TABLE statement.
235    pub fn or_replace(mut self, or_replace: bool) -> Self {
236        self.or_replace = or_replace;
237        self
238    }
239    /// Mark the table as `TEMPORARY`.
240    pub fn temporary(mut self, temporary: bool) -> Self {
241        self.temporary = temporary;
242        self
243    }
244    /// Mark the table as `EXTERNAL`.
245    pub fn external(mut self, external: bool) -> Self {
246        self.external = external;
247        self
248    }
249    /// Set optional `GLOBAL` flag (dialect-specific).
250    pub fn global(mut self, global: Option<bool>) -> Self {
251        self.global = global;
252        self
253    }
254    /// Set `IF NOT EXISTS`.
255    pub fn if_not_exists(mut self, if_not_exists: bool) -> Self {
256        self.if_not_exists = if_not_exists;
257        self
258    }
259    /// Set `TRANSIENT` flag.
260    pub fn transient(mut self, transient: bool) -> Self {
261        self.transient = transient;
262        self
263    }
264    /// Set `VOLATILE` flag.
265    pub fn volatile(mut self, volatile: bool) -> Self {
266        self.volatile = volatile;
267        self
268    }
269    /// Enable Iceberg table semantics.
270    pub fn iceberg(mut self, iceberg: bool) -> Self {
271        self.iceberg = iceberg;
272        self
273    }
274    /// Set `DYNAMIC` table option.
275    pub fn dynamic(mut self, dynamic: bool) -> Self {
276        self.dynamic = dynamic;
277        self
278    }
279    /// Set the table column definitions.
280    pub fn columns(mut self, columns: Vec<ColumnDef>) -> Self {
281        self.columns = columns;
282        self
283    }
284    /// Set table-level constraints.
285    pub fn constraints(mut self, constraints: Vec<TableConstraint>) -> Self {
286        self.constraints = constraints;
287        self
288    }
289    /// Set Hive distribution style.
290    pub fn hive_distribution(mut self, hive_distribution: HiveDistributionStyle) -> Self {
291        self.hive_distribution = hive_distribution;
292        self
293    }
294    /// Set Hive-specific formats.
295    pub fn hive_formats(mut self, hive_formats: Option<HiveFormat>) -> Self {
296        self.hive_formats = hive_formats;
297        self
298    }
299    /// Set file format for the table (e.g., PARQUET).
300    pub fn file_format(mut self, file_format: Option<FileFormat>) -> Self {
301        self.file_format = file_format;
302        self
303    }
304    /// Set storage `location` for the table.
305    pub fn location(mut self, location: Option<String>) -> Self {
306        self.location = location;
307        self
308    }
309    /// Set an underlying `AS SELECT` query for the table.
310    pub fn query(mut self, query: Option<Box<Query>>) -> Self {
311        self.query = query;
312        self
313    }
314    /// Set `WITHOUT ROWID` option.
315    pub fn without_rowid(mut self, without_rowid: bool) -> Self {
316        self.without_rowid = without_rowid;
317        self
318    }
319    /// Set `LIKE` clause for the table.
320    pub fn like(mut self, like: Option<CreateTableLikeKind>) -> Self {
321        self.like = like;
322        self
323    }
324    // Different name to allow the object to be cloned
325    /// Set `CLONE` source object name.
326    pub fn clone_clause(mut self, clone: Option<ObjectName>) -> Self {
327        self.clone = clone;
328        self
329    }
330    /// Set table `VERSION`.
331    pub fn version(mut self, version: Option<TableVersion>) -> Self {
332        self.version = version;
333        self
334    }
335    /// Set a comment for the table or following column definitions.
336    pub fn comment_after_column_def(mut self, comment: Option<CommentDef>) -> Self {
337        self.comment = comment;
338        self
339    }
340    /// Set `ON COMMIT` behavior for temporary tables.
341    pub fn on_commit(mut self, on_commit: Option<OnCommit>) -> Self {
342        self.on_commit = on_commit;
343        self
344    }
345    /// Set cluster identifier for the table.
346    pub fn on_cluster(mut self, on_cluster: Option<Ident>) -> Self {
347        self.on_cluster = on_cluster;
348        self
349    }
350    /// Set a primary key expression for the table.
351    pub fn primary_key(mut self, primary_key: Option<Box<Expr>>) -> Self {
352        self.primary_key = primary_key;
353        self
354    }
355    /// Set `ORDER BY` clause for clustered/sorted tables.
356    pub fn order_by(mut self, order_by: Option<OneOrManyWithParens<Expr>>) -> Self {
357        self.order_by = order_by;
358        self
359    }
360    /// Set `PARTITION BY` expression.
361    pub fn partition_by(mut self, partition_by: Option<Box<Expr>>) -> Self {
362        self.partition_by = partition_by;
363        self
364    }
365    /// Set `CLUSTER BY` expression(s).
366    pub fn cluster_by(mut self, cluster_by: Option<WrappedCollection<Vec<Expr>>>) -> Self {
367        self.cluster_by = cluster_by;
368        self
369    }
370    /// Set `CLUSTERED BY` clause.
371    pub fn clustered_by(mut self, clustered_by: Option<ClusteredBy>) -> Self {
372        self.clustered_by = clustered_by;
373        self
374    }
375    /// Set parent tables via `INHERITS`.
376    pub fn inherits(mut self, inherits: Option<Vec<ObjectName>>) -> Self {
377        self.inherits = inherits;
378        self
379    }
380
381    /// Sets the table which is partitioned to create the current table.
382    pub fn partition_of(mut self, partition_of: Option<ObjectName>) -> Self {
383        self.partition_of = partition_of;
384        self
385    }
386
387    /// Sets the range of values associated with the partition.
388    pub fn for_values(mut self, for_values: Option<ForValues>) -> Self {
389        self.for_values = for_values;
390        self
391    }
392
393    /// Set `STRICT` option.
394    pub fn strict(mut self, strict: bool) -> Self {
395        self.strict = strict;
396        self
397    }
398    /// Enable copying grants from source object.
399    pub fn copy_grants(mut self, copy_grants: bool) -> Self {
400        self.copy_grants = copy_grants;
401        self
402    }
403    /// Enable or disable schema evolution features.
404    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    /// Enable or disable change tracking.
409    pub fn change_tracking(mut self, change_tracking: Option<bool>) -> Self {
410        self.change_tracking = change_tracking;
411        self
412    }
413    /// Set data retention time (in days).
414    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    /// Set maximum data extension time (in days).
419    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    /// Set default DDL collation.
427    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    /// Set aggregation policy object.
432    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    /// Attach a row access policy to the table.
437    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    /// Attach tags/labels to the table metadata.
445    pub fn with_tags(mut self, with_tags: Option<Vec<Tag>>) -> Self {
446        self.with_tags = with_tags;
447        self
448    }
449    /// Set a base storage location for staged data.
450    pub fn base_location(mut self, base_location: Option<String>) -> Self {
451        self.base_location = base_location;
452        self
453    }
454    /// Set an external volume identifier.
455    pub fn external_volume(mut self, external_volume: Option<String>) -> Self {
456        self.external_volume = external_volume;
457        self
458    }
459    /// Set the catalog name for the table.
460    pub fn catalog(mut self, catalog: Option<String>) -> Self {
461        self.catalog = catalog;
462        self
463    }
464    /// Set catalog synchronization option.
465    pub fn catalog_sync(mut self, catalog_sync: Option<String>) -> Self {
466        self.catalog_sync = catalog_sync;
467        self
468    }
469    /// Set a storage serialization policy.
470    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    /// Set arbitrary table options parsed from the statement.
478    pub fn table_options(mut self, table_options: CreateTableOptions) -> Self {
479        self.table_options = table_options;
480        self
481    }
482    /// Set a target lag configuration (dialect-specific).
483    pub fn target_lag(mut self, target_lag: Option<String>) -> Self {
484        self.target_lag = target_lag;
485        self
486    }
487    /// Associate the table with a warehouse identifier.
488    pub fn warehouse(mut self, warehouse: Option<Ident>) -> Self {
489        self.warehouse = warehouse;
490        self
491    }
492    /// Set refresh mode for materialized/managed tables.
493    pub fn refresh_mode(mut self, refresh_mode: Option<RefreshModeKind>) -> Self {
494        self.refresh_mode = refresh_mode;
495        self
496    }
497    /// Set initialization mode for the table.
498    pub fn initialize(mut self, initialize: Option<InitializeKind>) -> Self {
499        self.initialize = initialize;
500        self
501    }
502    /// Require a user identity for table operations.
503    pub fn require_user(mut self, require_user: bool) -> Self {
504        self.require_user = require_user;
505        self
506    }
507    /// Consume the builder and produce a `CreateTable`.
508    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    // As the builder can be transformed back to a statement, it shouldn't be a problem to take the
571    // ownership.
572    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/// Helper return type when parsing configuration for a `CREATE TABLE` statement.
643#[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}