mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-31 19:27:21 +00:00
Fix comments
This commit is contained in:
parent
7654a49b50
commit
1d977d1947
7 changed files with 191 additions and 201 deletions
111
src/ast/ddl.rs
111
src/ast/ddl.rs
|
@ -30,11 +30,11 @@ use sqlparser_derive::{Visit, VisitMut};
|
|||
|
||||
use crate::ast::value::escape_single_quote_string;
|
||||
use crate::ast::{
|
||||
display_comma_separated, display_separated, ArgMode, CatalogSyncNamespaceMode, CommentDef,
|
||||
ContactEntry, CreateFunctionBody, CreateFunctionUsing, DataType, Expr, FunctionBehavior,
|
||||
FunctionCalledOnNull, FunctionDeterminismSpecifier, FunctionParallel, Ident, IndexColumn,
|
||||
MySQLColumnPosition, ObjectName, OperateFunctionArg, OrderByExpr, ProjectionSelect,
|
||||
SequenceOptions, SqlOption, StorageSerializationPolicy, Tag, Value, ValueWithSpan,
|
||||
display_comma_separated, display_separated, ArgMode, CommentDef, CreateFunctionBody,
|
||||
CreateFunctionUsing, DataType, Expr, FunctionBehavior, FunctionCalledOnNull,
|
||||
FunctionDeterminismSpecifier, FunctionParallel, Ident, IndexColumn, MySQLColumnPosition,
|
||||
ObjectName, OperateFunctionArg, OrderByExpr, ProjectionSelect, SequenceOptions, SqlOption, Tag,
|
||||
Value, ValueWithSpan,
|
||||
};
|
||||
use crate::keywords::Keyword;
|
||||
use crate::tokenizer::Token;
|
||||
|
@ -2524,104 +2524,3 @@ impl fmt::Display for CreateConnector {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub struct CreateSnowflakeDatabase {
|
||||
pub or_replace: bool,
|
||||
pub transient: bool,
|
||||
pub if_not_exists: bool,
|
||||
pub name: ObjectName,
|
||||
pub clone: Option<ObjectName>,
|
||||
pub data_retention_time_in_days: Option<u64>,
|
||||
pub max_data_extension_time_in_days: Option<u64>,
|
||||
pub external_volume: Option<String>,
|
||||
pub catalog: Option<String>,
|
||||
pub replace_invalid_characters: Option<bool>,
|
||||
pub default_ddl_collation: Option<String>,
|
||||
pub storage_serialization_policy: Option<StorageSerializationPolicy>,
|
||||
pub comment: Option<String>,
|
||||
pub catalog_sync: Option<String>,
|
||||
pub catalog_sync_namespace_mode: Option<CatalogSyncNamespaceMode>,
|
||||
pub catalog_sync_namespace_flatten_delimiter: Option<String>,
|
||||
pub with_tags: Option<Vec<Tag>>,
|
||||
pub with_contacts: Option<Vec<ContactEntry>>,
|
||||
}
|
||||
|
||||
impl fmt::Display for CreateSnowflakeDatabase {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"CREATE {or_replace}{transient}DATABASE {if_not_exists}{name}",
|
||||
or_replace = if self.or_replace { "OR REPLACE " } else { "" },
|
||||
transient = if self.transient { "TRANSIENT " } else { "" },
|
||||
if_not_exists = if self.if_not_exists {
|
||||
"IF NOT EXISTS "
|
||||
} else {
|
||||
""
|
||||
},
|
||||
name = self.name,
|
||||
)?;
|
||||
|
||||
if let Some(clone) = &self.clone {
|
||||
write!(f, " CLONE {clone}")?;
|
||||
}
|
||||
|
||||
if let Some(value) = self.data_retention_time_in_days {
|
||||
write!(f, " DATA_RETENTION_TIME_IN_DAYS = {value}")?;
|
||||
}
|
||||
|
||||
if let Some(value) = self.max_data_extension_time_in_days {
|
||||
write!(f, " MAX_DATA_EXTENSION_TIME_IN_DAYS = {value}")?;
|
||||
}
|
||||
|
||||
if let Some(vol) = &self.external_volume {
|
||||
write!(f, " EXTERNAL_VOLUME = '{vol}'")?;
|
||||
}
|
||||
|
||||
if let Some(cat) = &self.catalog {
|
||||
write!(f, " CATALOG = '{cat}'")?;
|
||||
}
|
||||
|
||||
if let Some(true) = self.replace_invalid_characters {
|
||||
write!(f, " REPLACE_INVALID_CHARACTERS = TRUE")?;
|
||||
} else if let Some(false) = self.replace_invalid_characters {
|
||||
write!(f, " REPLACE_INVALID_CHARACTERS = FALSE")?;
|
||||
}
|
||||
|
||||
if let Some(collation) = &self.default_ddl_collation {
|
||||
write!(f, " DEFAULT_DDL_COLLATION = '{collation}'")?;
|
||||
}
|
||||
|
||||
if let Some(policy) = &self.storage_serialization_policy {
|
||||
write!(f, " STORAGE_SERIALIZATION_POLICY = {policy}")?;
|
||||
}
|
||||
|
||||
if let Some(comment) = &self.comment {
|
||||
write!(f, " COMMENT = '{comment}'")?;
|
||||
}
|
||||
|
||||
if let Some(sync) = &self.catalog_sync {
|
||||
write!(f, " CATALOG_SYNC = '{sync}'")?;
|
||||
}
|
||||
|
||||
if let Some(mode) = &self.catalog_sync_namespace_mode {
|
||||
write!(f, " CATALOG_SYNC_NAMESPACE_MODE = {mode}")?;
|
||||
}
|
||||
|
||||
if let Some(delim) = &self.catalog_sync_namespace_flatten_delimiter {
|
||||
write!(f, " CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER = '{delim}'")?;
|
||||
}
|
||||
|
||||
if let Some(tags) = &self.with_tags {
|
||||
write!(f, " WITH TAG ({})", display_comma_separated(tags))?;
|
||||
}
|
||||
|
||||
if let Some(contacts) = &self.with_contacts {
|
||||
write!(f, " WITH CONTACT ({})", display_comma_separated(contacts))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ use serde::{Deserialize, Serialize};
|
|||
#[cfg(feature = "visitor")]
|
||||
use sqlparser_derive::{Visit, VisitMut};
|
||||
|
||||
use crate::ast::ddl::CreateSnowflakeDatabase;
|
||||
use crate::ast::{
|
||||
CatalogSyncNamespaceMode, ContactEntry, ObjectName, Statement, StorageSerializationPolicy, Tag,
|
||||
};
|
||||
|
@ -51,15 +50,17 @@ use crate::parser::ParserError;
|
|||
/// )
|
||||
/// ```
|
||||
///
|
||||
/// [1]: Statement::CreateSnowflakeDatabase
|
||||
/// [1]: Statement::CreateDatabase
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub struct CreateDatabaseBuilder {
|
||||
pub db_name: ObjectName,
|
||||
pub if_not_exists: bool,
|
||||
pub location: Option<String>,
|
||||
pub managed_location: Option<String>,
|
||||
pub or_replace: bool,
|
||||
pub transient: bool,
|
||||
pub if_not_exists: bool,
|
||||
pub name: ObjectName,
|
||||
pub clone: Option<ObjectName>,
|
||||
pub data_retention_time_in_days: Option<u64>,
|
||||
pub max_data_extension_time_in_days: Option<u64>,
|
||||
|
@ -79,10 +80,12 @@ pub struct CreateDatabaseBuilder {
|
|||
impl CreateDatabaseBuilder {
|
||||
pub fn new(name: ObjectName) -> Self {
|
||||
Self {
|
||||
db_name: name,
|
||||
if_not_exists: false,
|
||||
location: None,
|
||||
managed_location: None,
|
||||
or_replace: false,
|
||||
transient: false,
|
||||
if_not_exists: false,
|
||||
name,
|
||||
clone: None,
|
||||
data_retention_time_in_days: None,
|
||||
max_data_extension_time_in_days: None,
|
||||
|
@ -100,6 +103,16 @@ impl CreateDatabaseBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn location(mut self, location: Option<String>) -> Self {
|
||||
self.location = location;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn managed_location(mut self, managed_location: Option<String>) -> Self {
|
||||
self.managed_location = managed_location;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn or_replace(mut self, or_replace: bool) -> Self {
|
||||
self.or_replace = or_replace;
|
||||
self
|
||||
|
@ -198,11 +211,13 @@ impl CreateDatabaseBuilder {
|
|||
}
|
||||
|
||||
pub fn build(self) -> Statement {
|
||||
Statement::CreateSnowflakeDatabase(CreateSnowflakeDatabase {
|
||||
Statement::CreateDatabase {
|
||||
db_name: self.db_name,
|
||||
if_not_exists: self.if_not_exists,
|
||||
managed_location: self.managed_location,
|
||||
location: self.location,
|
||||
or_replace: self.or_replace,
|
||||
transient: self.transient,
|
||||
if_not_exists: self.if_not_exists,
|
||||
name: self.name,
|
||||
clone: self.clone,
|
||||
data_retention_time_in_days: self.data_retention_time_in_days,
|
||||
max_data_extension_time_in_days: self.max_data_extension_time_in_days,
|
||||
|
@ -217,7 +232,7 @@ impl CreateDatabaseBuilder {
|
|||
catalog_sync_namespace_flatten_delimiter: self.catalog_sync_namespace_flatten_delimiter,
|
||||
with_tags: self.with_tags,
|
||||
with_contacts: self.with_contacts,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,11 +241,13 @@ impl TryFrom<Statement> for CreateDatabaseBuilder {
|
|||
|
||||
fn try_from(stmt: Statement) -> Result<Self, Self::Error> {
|
||||
match stmt {
|
||||
Statement::CreateSnowflakeDatabase(CreateSnowflakeDatabase {
|
||||
Statement::CreateDatabase {
|
||||
db_name,
|
||||
if_not_exists,
|
||||
location,
|
||||
managed_location,
|
||||
or_replace,
|
||||
transient,
|
||||
if_not_exists,
|
||||
name,
|
||||
clone,
|
||||
data_retention_time_in_days,
|
||||
max_data_extension_time_in_days,
|
||||
|
@ -245,11 +262,13 @@ impl TryFrom<Statement> for CreateDatabaseBuilder {
|
|||
catalog_sync_namespace_flatten_delimiter,
|
||||
with_tags,
|
||||
with_contacts,
|
||||
}) => Ok(Self {
|
||||
} => Ok(Self {
|
||||
db_name,
|
||||
if_not_exists,
|
||||
location,
|
||||
managed_location,
|
||||
or_replace,
|
||||
transient,
|
||||
if_not_exists,
|
||||
name,
|
||||
clone,
|
||||
data_retention_time_in_days,
|
||||
max_data_extension_time_in_days,
|
||||
|
|
144
src/ast/mod.rs
144
src/ast/mod.rs
|
@ -63,12 +63,12 @@ pub use self::ddl::{
|
|||
AlterTypeAddValuePosition, AlterTypeOperation, AlterTypeRename, AlterTypeRenameValue,
|
||||
ClusteredBy, ColumnDef, ColumnOption, ColumnOptionDef, ColumnOptions, ColumnPolicy,
|
||||
ColumnPolicyProperty, ConstraintCharacteristics, CreateConnector, CreateDomain, CreateFunction,
|
||||
CreateSnowflakeDatabase, Deduplicate, DeferrableInitial, DropBehavior, GeneratedAs,
|
||||
GeneratedExpressionMode, IdentityParameters, IdentityProperty, IdentityPropertyFormatKind,
|
||||
IdentityPropertyKind, IdentityPropertyOrder, IndexOption, IndexType, KeyOrIndexDisplay,
|
||||
NullsDistinctOption, Owner, Partition, ProcedureParam, ReferentialAction, ReplicaIdentity,
|
||||
TableConstraint, TagsColumnOption, UserDefinedTypeCompositeAttributeDef,
|
||||
UserDefinedTypeRepresentation, ViewColumnDef,
|
||||
Deduplicate, DeferrableInitial, DropBehavior, GeneratedAs, GeneratedExpressionMode,
|
||||
IdentityParameters, IdentityProperty, IdentityPropertyFormatKind, IdentityPropertyKind,
|
||||
IdentityPropertyOrder, IndexOption, IndexType, KeyOrIndexDisplay, NullsDistinctOption, Owner,
|
||||
Partition, ProcedureParam, ReferentialAction, ReplicaIdentity, TableConstraint,
|
||||
TagsColumnOption, UserDefinedTypeCompositeAttributeDef, UserDefinedTypeRepresentation,
|
||||
ViewColumnDef,
|
||||
};
|
||||
pub use self::dml::{CreateIndex, CreateTable, Delete, IndexColumn, Insert};
|
||||
pub use self::operator::{BinaryOperator, UnaryOperator};
|
||||
|
@ -3850,38 +3850,31 @@ pub enum Statement {
|
|||
/// ```sql
|
||||
/// CREATE DATABASE
|
||||
/// ```
|
||||
/// See:
|
||||
/// <https://docs.snowflake.com/en/sql-reference/sql/create-database>
|
||||
CreateDatabase {
|
||||
db_name: ObjectName,
|
||||
if_not_exists: bool,
|
||||
location: Option<String>,
|
||||
managed_location: Option<String>,
|
||||
or_replace: bool,
|
||||
transient: bool,
|
||||
clone: Option<ObjectName>,
|
||||
data_retention_time_in_days: Option<u64>,
|
||||
max_data_extension_time_in_days: Option<u64>,
|
||||
external_volume: Option<String>,
|
||||
catalog: Option<String>,
|
||||
replace_invalid_characters: Option<bool>,
|
||||
default_ddl_collation: Option<String>,
|
||||
storage_serialization_policy: Option<StorageSerializationPolicy>,
|
||||
comment: Option<String>,
|
||||
catalog_sync: Option<String>,
|
||||
catalog_sync_namespace_mode: Option<CatalogSyncNamespaceMode>,
|
||||
catalog_sync_namespace_flatten_delimiter: Option<String>,
|
||||
with_tags: Option<Vec<Tag>>,
|
||||
with_contacts: Option<Vec<ContactEntry>>,
|
||||
},
|
||||
/// ```sql
|
||||
/// CREATE [ OR REPLACE ] [ TRANSIENT ] DATABASE [ IF NOT EXISTS ] <name>
|
||||
/// [ CLONE <source_schema>
|
||||
/// [ { AT | BEFORE } ( { TIMESTAMP => <timestamp> | OFFSET => <time_difference> | STATEMENT => <id> } ) ]
|
||||
/// [ IGNORE TABLES WITH INSUFFICIENT DATA RETENTION ]
|
||||
/// [ IGNORE HYBRID TABLES ] ]
|
||||
/// [ DATA_RETENTION_TIME_IN_DAYS = <integer> ]
|
||||
/// [ MAX_DATA_EXTENSION_TIME_IN_DAYS = <integer> ]
|
||||
/// [ EXTERNAL_VOLUME = <external_volume_name> ]
|
||||
/// [ CATALOG = <catalog_integration_name> ]
|
||||
/// [ REPLACE_INVALID_CHARACTERS = { TRUE | FALSE } ]
|
||||
/// [ DEFAULT_DDL_COLLATION = '<collation_specification>' ]
|
||||
/// [ STORAGE_SERIALIZATION_POLICY = { COMPATIBLE | OPTIMIZED } ]
|
||||
/// [ COMMENT = '<string_literal>' ]
|
||||
/// [ CATALOG_SYNC = '<snowflake_open_catalog_integration_name>' ]
|
||||
/// [ CATALOG_SYNC_NAMESPACE_MODE = { NEST | FLATTEN } ]
|
||||
/// [ CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER = '<string_literal>' ]
|
||||
/// [ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
|
||||
/// [ WITH CONTACT ( <purpose> = <contact_name> [ , <purpose> = <contact_name> ... ] ) ]
|
||||
/// ```
|
||||
/// See:
|
||||
/// <https://docs.snowflake.com/en/sql-reference/sql/create-database>
|
||||
///
|
||||
/// Creates a new database in the system.
|
||||
CreateSnowflakeDatabase(CreateSnowflakeDatabase),
|
||||
/// ```sql
|
||||
/// CREATE FUNCTION
|
||||
/// ```
|
||||
///
|
||||
|
@ -4816,21 +4809,98 @@ impl fmt::Display for Statement {
|
|||
if_not_exists,
|
||||
location,
|
||||
managed_location,
|
||||
or_replace,
|
||||
transient,
|
||||
clone,
|
||||
data_retention_time_in_days,
|
||||
max_data_extension_time_in_days,
|
||||
external_volume,
|
||||
catalog,
|
||||
replace_invalid_characters,
|
||||
default_ddl_collation,
|
||||
storage_serialization_policy,
|
||||
comment,
|
||||
catalog_sync,
|
||||
catalog_sync_namespace_mode,
|
||||
catalog_sync_namespace_flatten_delimiter,
|
||||
with_tags,
|
||||
with_contacts,
|
||||
} => {
|
||||
write!(f, "CREATE DATABASE")?;
|
||||
if *if_not_exists {
|
||||
write!(f, " IF NOT EXISTS")?;
|
||||
}
|
||||
write!(f, " {db_name}")?;
|
||||
write!(
|
||||
f,
|
||||
"CREATE {or_replace}{transient}DATABASE {if_not_exists}{name}",
|
||||
or_replace = if *or_replace { "OR REPLACE " } else { "" },
|
||||
transient = if *transient { "TRANSIENT " } else { "" },
|
||||
if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
|
||||
name = db_name,
|
||||
)?;
|
||||
|
||||
if let Some(l) = location {
|
||||
write!(f, " LOCATION '{l}'")?;
|
||||
}
|
||||
if let Some(ml) = managed_location {
|
||||
write!(f, " MANAGEDLOCATION '{ml}'")?;
|
||||
}
|
||||
if let Some(clone) = clone {
|
||||
write!(f, " CLONE {clone}")?;
|
||||
}
|
||||
|
||||
if let Some(value) = data_retention_time_in_days {
|
||||
write!(f, " DATA_RETENTION_TIME_IN_DAYS = {value}")?;
|
||||
}
|
||||
|
||||
if let Some(value) = max_data_extension_time_in_days {
|
||||
write!(f, " MAX_DATA_EXTENSION_TIME_IN_DAYS = {value}")?;
|
||||
}
|
||||
|
||||
if let Some(vol) = external_volume {
|
||||
write!(f, " EXTERNAL_VOLUME = '{vol}'")?;
|
||||
}
|
||||
|
||||
if let Some(cat) = catalog {
|
||||
write!(f, " CATALOG = '{cat}'")?;
|
||||
}
|
||||
|
||||
if let Some(true) = replace_invalid_characters {
|
||||
write!(f, " REPLACE_INVALID_CHARACTERS = TRUE")?;
|
||||
} else if let Some(false) = replace_invalid_characters {
|
||||
write!(f, " REPLACE_INVALID_CHARACTERS = FALSE")?;
|
||||
}
|
||||
|
||||
if let Some(collation) = default_ddl_collation {
|
||||
write!(f, " DEFAULT_DDL_COLLATION = '{collation}'")?;
|
||||
}
|
||||
|
||||
if let Some(policy) = storage_serialization_policy {
|
||||
write!(f, " STORAGE_SERIALIZATION_POLICY = {policy}")?;
|
||||
}
|
||||
|
||||
if let Some(comment) = comment {
|
||||
write!(f, " COMMENT = '{comment}'")?;
|
||||
}
|
||||
|
||||
if let Some(sync) = catalog_sync {
|
||||
write!(f, " CATALOG_SYNC = '{sync}'")?;
|
||||
}
|
||||
|
||||
if let Some(mode) = catalog_sync_namespace_mode {
|
||||
write!(f, " CATALOG_SYNC_NAMESPACE_MODE = {mode}")?;
|
||||
}
|
||||
|
||||
if let Some(delim) = catalog_sync_namespace_flatten_delimiter {
|
||||
write!(f, " CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER = '{delim}'")?;
|
||||
}
|
||||
|
||||
if let Some(tags) = with_tags {
|
||||
write!(f, " WITH TAG ({})", display_comma_separated(tags))?;
|
||||
}
|
||||
|
||||
if let Some(contacts) = with_contacts {
|
||||
write!(f, " WITH CONTACT ({})", display_comma_separated(contacts))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Statement::CreateSnowflakeDatabase(create_database) => create_database.fmt(f),
|
||||
Statement::CreateFunction(create_function) => create_function.fmt(f),
|
||||
Statement::CreateDomain(create_domain) => create_domain.fmt(f),
|
||||
Statement::CreateTrigger {
|
||||
|
|
|
@ -21,24 +21,24 @@ use core::iter;
|
|||
use crate::tokenizer::Span;
|
||||
|
||||
use super::{
|
||||
dcl::SecondaryRoles, ddl::CreateSnowflakeDatabase, value::ValueWithSpan, AccessExpr,
|
||||
AlterColumnOperation, AlterIndexOperation, AlterTableOperation, Array, Assignment,
|
||||
AssignmentTarget, AttachedToken, BeginEndStatements, CaseStatement, CloseCursor,
|
||||
ClusteredIndex, ColumnDef, ColumnOption, ColumnOptionDef, ConditionalStatementBlock,
|
||||
ConditionalStatements, ConflictTarget, ConnectBy, ConstraintCharacteristics, CopySource,
|
||||
CreateIndex, CreateTable, CreateTableOptions, Cte, Delete, DoUpdate, ExceptSelectItem,
|
||||
ExcludeSelectItem, Expr, ExprWithAlias, Fetch, FromTable, Function, FunctionArg,
|
||||
FunctionArgExpr, FunctionArgumentClause, FunctionArgumentList, FunctionArguments, GroupByExpr,
|
||||
HavingBound, IfStatement, IlikeSelectItem, IndexColumn, Insert, Interpolate, InterpolateExpr,
|
||||
Join, JoinConstraint, JoinOperator, JsonPath, JsonPathElem, LateralView, LimitClause,
|
||||
MatchRecognizePattern, Measure, NamedParenthesizedList, NamedWindowDefinition, ObjectName,
|
||||
ObjectNamePart, Offset, OnConflict, OnConflictAction, OnInsert, OpenStatement, OrderBy,
|
||||
OrderByExpr, OrderByKind, Partition, PivotValueSource, ProjectionSelect, Query, RaiseStatement,
|
||||
RaiseStatementValue, ReferentialAction, RenameSelectItem, ReplaceSelectElement,
|
||||
ReplaceSelectItem, Select, SelectInto, SelectItem, SetExpr, SqlOption, Statement, Subscript,
|
||||
SymbolDefinition, TableAlias, TableAliasColumnDef, TableConstraint, TableFactor, TableObject,
|
||||
TableOptionsClustered, TableWithJoins, UpdateTableFromKind, Use, Value, Values, ViewColumnDef,
|
||||
WhileStatement, WildcardAdditionalOptions, With, WithFill,
|
||||
dcl::SecondaryRoles, value::ValueWithSpan, AccessExpr, AlterColumnOperation,
|
||||
AlterIndexOperation, AlterTableOperation, Array, Assignment, AssignmentTarget, AttachedToken,
|
||||
BeginEndStatements, CaseStatement, CloseCursor, ClusteredIndex, ColumnDef, ColumnOption,
|
||||
ColumnOptionDef, ConditionalStatementBlock, ConditionalStatements, ConflictTarget, ConnectBy,
|
||||
ConstraintCharacteristics, CopySource, CreateIndex, CreateTable, CreateTableOptions, Cte,
|
||||
Delete, DoUpdate, ExceptSelectItem, ExcludeSelectItem, Expr, ExprWithAlias, Fetch, FromTable,
|
||||
Function, FunctionArg, FunctionArgExpr, FunctionArgumentClause, FunctionArgumentList,
|
||||
FunctionArguments, GroupByExpr, HavingBound, IfStatement, IlikeSelectItem, IndexColumn, Insert,
|
||||
Interpolate, InterpolateExpr, Join, JoinConstraint, JoinOperator, JsonPath, JsonPathElem,
|
||||
LateralView, LimitClause, MatchRecognizePattern, Measure, NamedParenthesizedList,
|
||||
NamedWindowDefinition, ObjectName, ObjectNamePart, Offset, OnConflict, OnConflictAction,
|
||||
OnInsert, OpenStatement, OrderBy, OrderByExpr, OrderByKind, Partition, PivotValueSource,
|
||||
ProjectionSelect, Query, RaiseStatement, RaiseStatementValue, ReferentialAction,
|
||||
RenameSelectItem, ReplaceSelectElement, ReplaceSelectItem, Select, SelectInto, SelectItem,
|
||||
SetExpr, SqlOption, Statement, Subscript, SymbolDefinition, TableAlias, TableAliasColumnDef,
|
||||
TableConstraint, TableFactor, TableObject, TableOptionsClustered, TableWithJoins,
|
||||
UpdateTableFromKind, Use, Value, Values, ViewColumnDef, WhileStatement,
|
||||
WildcardAdditionalOptions, With, WithFill,
|
||||
};
|
||||
|
||||
/// Given an iterator of spans, return the [Span::union] of all spans.
|
||||
|
@ -386,7 +386,6 @@ impl Spanned for Statement {
|
|||
.chain(returning.iter().flat_map(|i| i.iter().map(|k| k.span()))),
|
||||
),
|
||||
Statement::Delete(delete) => delete.span(),
|
||||
Statement::CreateSnowflakeDatabase(create_database) => create_database.span(),
|
||||
Statement::CreateView {
|
||||
or_alter: _,
|
||||
or_replace: _,
|
||||
|
@ -617,12 +616,6 @@ impl Spanned for CreateTable {
|
|||
}
|
||||
}
|
||||
|
||||
impl Spanned for CreateSnowflakeDatabase {
|
||||
fn span(&self) -> Span {
|
||||
union_spans(core::iter::once(self.name.span()).chain(self.clone.iter().map(|c| c.span())))
|
||||
}
|
||||
}
|
||||
|
||||
impl Spanned for ColumnDef {
|
||||
fn span(&self) -> Span {
|
||||
let ColumnDef {
|
||||
|
|
|
@ -4937,6 +4937,22 @@ impl<'a> Parser<'a> {
|
|||
if_not_exists: ine,
|
||||
location,
|
||||
managed_location,
|
||||
or_replace: false,
|
||||
transient: false,
|
||||
clone: None,
|
||||
data_retention_time_in_days: None,
|
||||
max_data_extension_time_in_days: None,
|
||||
external_volume: None,
|
||||
catalog: None,
|
||||
replace_invalid_characters: None,
|
||||
default_ddl_collation: None,
|
||||
storage_serialization_policy: None,
|
||||
comment: None,
|
||||
catalog_sync: None,
|
||||
catalog_sync_namespace_mode: None,
|
||||
catalog_sync_namespace_flatten_delimiter: None,
|
||||
with_tags: None,
|
||||
with_contacts: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -7898,12 +7898,13 @@ fn parse_exists_subquery() {
|
|||
#[test]
|
||||
fn parse_create_database() {
|
||||
let sql = "CREATE DATABASE mydb";
|
||||
match all_dialects_except(|d| d.is::<SnowflakeDialect>()).verified_stmt(sql) {
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateDatabase {
|
||||
db_name,
|
||||
if_not_exists,
|
||||
location,
|
||||
managed_location,
|
||||
..
|
||||
} => {
|
||||
assert_eq!("mydb", db_name.to_string());
|
||||
assert!(!if_not_exists);
|
||||
|
@ -7917,12 +7918,13 @@ fn parse_create_database() {
|
|||
#[test]
|
||||
fn parse_create_database_ine() {
|
||||
let sql = "CREATE DATABASE IF NOT EXISTS mydb";
|
||||
match all_dialects_except(|d| d.is::<SnowflakeDialect>()).verified_stmt(sql) {
|
||||
match verified_stmt(sql) {
|
||||
Statement::CreateDatabase {
|
||||
db_name,
|
||||
if_not_exists,
|
||||
location,
|
||||
managed_location,
|
||||
..
|
||||
} => {
|
||||
assert_eq!("mydb", db_name.to_string());
|
||||
assert!(if_not_exists);
|
||||
|
|
|
@ -4374,9 +4374,9 @@ fn test_snowflake_identifier_function() {
|
|||
|
||||
// Using IDENTIFIER to reference a database
|
||||
match snowflake().verified_stmt("CREATE DATABASE IDENTIFIER('tbl')") {
|
||||
Statement::CreateSnowflakeDatabase(CreateSnowflakeDatabase { name, .. }) => {
|
||||
Statement::CreateDatabase { db_name, .. } => {
|
||||
assert_eq!(
|
||||
name,
|
||||
db_name,
|
||||
ObjectName(vec![ObjectNamePart::Function(ObjectNamePartFunction {
|
||||
name: Ident::new("IDENTIFIER"),
|
||||
args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
|
||||
|
@ -4440,22 +4440,14 @@ fn test_snowflake_identifier_function() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_database_basic() {
|
||||
fn test_create_database() {
|
||||
snowflake().verified_stmt("CREATE DATABASE my_db");
|
||||
snowflake().verified_stmt("CREATE OR REPLACE DATABASE my_db");
|
||||
snowflake().verified_stmt("CREATE TRANSIENT DATABASE IF NOT EXISTS my_db");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_database_clone() {
|
||||
snowflake().verified_stmt("CREATE DATABASE my_db CLONE src_db");
|
||||
snowflake().verified_stmt(
|
||||
"CREATE OR REPLACE DATABASE my_db CLONE src_db DATA_RETENTION_TIME_IN_DAYS = 1",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_database_with_all_options() {
|
||||
snowflake().one_statement_parses_to(
|
||||
r#"
|
||||
CREATE OR REPLACE TRANSIENT DATABASE IF NOT EXISTS my_db
|
||||
|
@ -4469,6 +4461,7 @@ fn test_create_database_with_all_options() {
|
|||
STORAGE_SERIALIZATION_POLICY = COMPATIBLE
|
||||
COMMENT = 'This is my database'
|
||||
CATALOG_SYNC = 'sync_integration'
|
||||
CATALOG_SYNC_NAMESPACE_MODE = NEST
|
||||
CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER = '/'
|
||||
WITH TAG (env = 'prod', team = 'data')
|
||||
WITH CONTACT (owner = 'admin', dpo = 'compliance')
|
||||
|
@ -4478,14 +4471,12 @@ fn test_create_database_with_all_options() {
|
|||
EXTERNAL_VOLUME = 'volume1' CATALOG = 'my_catalog' \
|
||||
REPLACE_INVALID_CHARACTERS = TRUE DEFAULT_DDL_COLLATION = 'en-ci' \
|
||||
STORAGE_SERIALIZATION_POLICY = COMPATIBLE COMMENT = 'This is my database' \
|
||||
CATALOG_SYNC = 'sync_integration' CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER = '/' \
|
||||
CATALOG_SYNC = 'sync_integration' CATALOG_SYNC_NAMESPACE_MODE = NEST \
|
||||
CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER = '/' \
|
||||
WITH TAG (env='prod', team='data') \
|
||||
WITH CONTACT (owner = admin, dpo = compliance)",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_database_errors() {
|
||||
let err = snowflake()
|
||||
.parse_sql_statements("CREATE DATABASE")
|
||||
.unwrap_err()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue