Skip to content

Commit 1d977d1

Browse files
committed
Fix comments
1 parent 7654a49 commit 1d977d1

File tree

7 files changed

+191
-201
lines changed

7 files changed

+191
-201
lines changed

src/ast/ddl.rs

Lines changed: 5 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ use sqlparser_derive::{Visit, VisitMut};
3030

3131
use crate::ast::value::escape_single_quote_string;
3232
use crate::ast::{
33-
display_comma_separated, display_separated, ArgMode, CatalogSyncNamespaceMode, CommentDef,
34-
ContactEntry, CreateFunctionBody, CreateFunctionUsing, DataType, Expr, FunctionBehavior,
35-
FunctionCalledOnNull, FunctionDeterminismSpecifier, FunctionParallel, Ident, IndexColumn,
36-
MySQLColumnPosition, ObjectName, OperateFunctionArg, OrderByExpr, ProjectionSelect,
37-
SequenceOptions, SqlOption, StorageSerializationPolicy, Tag, Value, ValueWithSpan,
33+
display_comma_separated, display_separated, ArgMode, CommentDef, CreateFunctionBody,
34+
CreateFunctionUsing, DataType, Expr, FunctionBehavior, FunctionCalledOnNull,
35+
FunctionDeterminismSpecifier, FunctionParallel, Ident, IndexColumn, MySQLColumnPosition,
36+
ObjectName, OperateFunctionArg, OrderByExpr, ProjectionSelect, SequenceOptions, SqlOption, Tag,
37+
Value, ValueWithSpan,
3838
};
3939
use crate::keywords::Keyword;
4040
use crate::tokenizer::Token;
@@ -2524,104 +2524,3 @@ impl fmt::Display for CreateConnector {
25242524
Ok(())
25252525
}
25262526
}
2527-
2528-
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2529-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2530-
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2531-
pub struct CreateSnowflakeDatabase {
2532-
pub or_replace: bool,
2533-
pub transient: bool,
2534-
pub if_not_exists: bool,
2535-
pub name: ObjectName,
2536-
pub clone: Option<ObjectName>,
2537-
pub data_retention_time_in_days: Option<u64>,
2538-
pub max_data_extension_time_in_days: Option<u64>,
2539-
pub external_volume: Option<String>,
2540-
pub catalog: Option<String>,
2541-
pub replace_invalid_characters: Option<bool>,
2542-
pub default_ddl_collation: Option<String>,
2543-
pub storage_serialization_policy: Option<StorageSerializationPolicy>,
2544-
pub comment: Option<String>,
2545-
pub catalog_sync: Option<String>,
2546-
pub catalog_sync_namespace_mode: Option<CatalogSyncNamespaceMode>,
2547-
pub catalog_sync_namespace_flatten_delimiter: Option<String>,
2548-
pub with_tags: Option<Vec<Tag>>,
2549-
pub with_contacts: Option<Vec<ContactEntry>>,
2550-
}
2551-
2552-
impl fmt::Display for CreateSnowflakeDatabase {
2553-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2554-
write!(
2555-
f,
2556-
"CREATE {or_replace}{transient}DATABASE {if_not_exists}{name}",
2557-
or_replace = if self.or_replace { "OR REPLACE " } else { "" },
2558-
transient = if self.transient { "TRANSIENT " } else { "" },
2559-
if_not_exists = if self.if_not_exists {
2560-
"IF NOT EXISTS "
2561-
} else {
2562-
""
2563-
},
2564-
name = self.name,
2565-
)?;
2566-
2567-
if let Some(clone) = &self.clone {
2568-
write!(f, " CLONE {clone}")?;
2569-
}
2570-
2571-
if let Some(value) = self.data_retention_time_in_days {
2572-
write!(f, " DATA_RETENTION_TIME_IN_DAYS = {value}")?;
2573-
}
2574-
2575-
if let Some(value) = self.max_data_extension_time_in_days {
2576-
write!(f, " MAX_DATA_EXTENSION_TIME_IN_DAYS = {value}")?;
2577-
}
2578-
2579-
if let Some(vol) = &self.external_volume {
2580-
write!(f, " EXTERNAL_VOLUME = '{vol}'")?;
2581-
}
2582-
2583-
if let Some(cat) = &self.catalog {
2584-
write!(f, " CATALOG = '{cat}'")?;
2585-
}
2586-
2587-
if let Some(true) = self.replace_invalid_characters {
2588-
write!(f, " REPLACE_INVALID_CHARACTERS = TRUE")?;
2589-
} else if let Some(false) = self.replace_invalid_characters {
2590-
write!(f, " REPLACE_INVALID_CHARACTERS = FALSE")?;
2591-
}
2592-
2593-
if let Some(collation) = &self.default_ddl_collation {
2594-
write!(f, " DEFAULT_DDL_COLLATION = '{collation}'")?;
2595-
}
2596-
2597-
if let Some(policy) = &self.storage_serialization_policy {
2598-
write!(f, " STORAGE_SERIALIZATION_POLICY = {policy}")?;
2599-
}
2600-
2601-
if let Some(comment) = &self.comment {
2602-
write!(f, " COMMENT = '{comment}'")?;
2603-
}
2604-
2605-
if let Some(sync) = &self.catalog_sync {
2606-
write!(f, " CATALOG_SYNC = '{sync}'")?;
2607-
}
2608-
2609-
if let Some(mode) = &self.catalog_sync_namespace_mode {
2610-
write!(f, " CATALOG_SYNC_NAMESPACE_MODE = {mode}")?;
2611-
}
2612-
2613-
if let Some(delim) = &self.catalog_sync_namespace_flatten_delimiter {
2614-
write!(f, " CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER = '{delim}'")?;
2615-
}
2616-
2617-
if let Some(tags) = &self.with_tags {
2618-
write!(f, " WITH TAG ({})", display_comma_separated(tags))?;
2619-
}
2620-
2621-
if let Some(contacts) = &self.with_contacts {
2622-
write!(f, " WITH CONTACT ({})", display_comma_separated(contacts))?;
2623-
}
2624-
2625-
Ok(())
2626-
}
2627-
}

src/ast/helpers/stmt_create_database.rs

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use serde::{Deserialize, Serialize};
2424
#[cfg(feature = "visitor")]
2525
use sqlparser_derive::{Visit, VisitMut};
2626

27-
use crate::ast::ddl::CreateSnowflakeDatabase;
2827
use crate::ast::{
2928
CatalogSyncNamespaceMode, ContactEntry, ObjectName, Statement, StorageSerializationPolicy, Tag,
3029
};
@@ -51,15 +50,17 @@ use crate::parser::ParserError;
5150
/// )
5251
/// ```
5352
///
54-
/// [1]: Statement::CreateSnowflakeDatabase
53+
/// [1]: Statement::CreateDatabase
5554
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
5655
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5756
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5857
pub struct CreateDatabaseBuilder {
58+
pub db_name: ObjectName,
59+
pub if_not_exists: bool,
60+
pub location: Option<String>,
61+
pub managed_location: Option<String>,
5962
pub or_replace: bool,
6063
pub transient: bool,
61-
pub if_not_exists: bool,
62-
pub name: ObjectName,
6364
pub clone: Option<ObjectName>,
6465
pub data_retention_time_in_days: Option<u64>,
6566
pub max_data_extension_time_in_days: Option<u64>,
@@ -79,10 +80,12 @@ pub struct CreateDatabaseBuilder {
7980
impl CreateDatabaseBuilder {
8081
pub fn new(name: ObjectName) -> Self {
8182
Self {
83+
db_name: name,
84+
if_not_exists: false,
85+
location: None,
86+
managed_location: None,
8287
or_replace: false,
8388
transient: false,
84-
if_not_exists: false,
85-
name,
8689
clone: None,
8790
data_retention_time_in_days: None,
8891
max_data_extension_time_in_days: None,
@@ -100,6 +103,16 @@ impl CreateDatabaseBuilder {
100103
}
101104
}
102105

106+
pub fn location(mut self, location: Option<String>) -> Self {
107+
self.location = location;
108+
self
109+
}
110+
111+
pub fn managed_location(mut self, managed_location: Option<String>) -> Self {
112+
self.managed_location = managed_location;
113+
self
114+
}
115+
103116
pub fn or_replace(mut self, or_replace: bool) -> Self {
104117
self.or_replace = or_replace;
105118
self
@@ -198,11 +211,13 @@ impl CreateDatabaseBuilder {
198211
}
199212

200213
pub fn build(self) -> Statement {
201-
Statement::CreateSnowflakeDatabase(CreateSnowflakeDatabase {
214+
Statement::CreateDatabase {
215+
db_name: self.db_name,
216+
if_not_exists: self.if_not_exists,
217+
managed_location: self.managed_location,
218+
location: self.location,
202219
or_replace: self.or_replace,
203220
transient: self.transient,
204-
if_not_exists: self.if_not_exists,
205-
name: self.name,
206221
clone: self.clone,
207222
data_retention_time_in_days: self.data_retention_time_in_days,
208223
max_data_extension_time_in_days: self.max_data_extension_time_in_days,
@@ -217,7 +232,7 @@ impl CreateDatabaseBuilder {
217232
catalog_sync_namespace_flatten_delimiter: self.catalog_sync_namespace_flatten_delimiter,
218233
with_tags: self.with_tags,
219234
with_contacts: self.with_contacts,
220-
})
235+
}
221236
}
222237
}
223238

@@ -226,11 +241,13 @@ impl TryFrom<Statement> for CreateDatabaseBuilder {
226241

227242
fn try_from(stmt: Statement) -> Result<Self, Self::Error> {
228243
match stmt {
229-
Statement::CreateSnowflakeDatabase(CreateSnowflakeDatabase {
244+
Statement::CreateDatabase {
245+
db_name,
246+
if_not_exists,
247+
location,
248+
managed_location,
230249
or_replace,
231250
transient,
232-
if_not_exists,
233-
name,
234251
clone,
235252
data_retention_time_in_days,
236253
max_data_extension_time_in_days,
@@ -245,11 +262,13 @@ impl TryFrom<Statement> for CreateDatabaseBuilder {
245262
catalog_sync_namespace_flatten_delimiter,
246263
with_tags,
247264
with_contacts,
248-
}) => Ok(Self {
265+
} => Ok(Self {
266+
db_name,
267+
if_not_exists,
268+
location,
269+
managed_location,
249270
or_replace,
250271
transient,
251-
if_not_exists,
252-
name,
253272
clone,
254273
data_retention_time_in_days,
255274
max_data_extension_time_in_days,

0 commit comments

Comments
 (0)