Skip to content

Commit 695fe48

Browse files
osipovartemJanKaul
authored andcommitted
Snowflake create database (apache#1939)
1 parent 272c25e commit 695fe48

7 files changed

Lines changed: 2465 additions & 6884 deletions

File tree

src/ast/helpers/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,8 @@
1414
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
17-
18-
/// Helper utilities for attached tokens used by AST helpers.
1917
pub mod attached_token;
20-
/// Utilities for parsing key/value style options in helper statements.
2118
pub mod key_value_options;
22-
/// Helpers for `CREATE DATABASE` statement construction/parsing.
2319
pub mod stmt_create_database;
24-
/// Helpers for `CREATE TABLE` statement construction/parsing.
2520
pub mod stmt_create_table;
26-
/// Helpers for data loading/unloading related statements (stages, PUT, COPY INTO).
2721
pub mod stmt_data_loading;

src/ast/helpers/stmt_create_database.rs

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// under the License.
1717

1818
#[cfg(not(feature = "std"))]
19-
use alloc::{format, string::String, vec::Vec};
19+
use alloc::{boxed::Box, format, string::String, vec, vec::Vec};
2020

2121
#[cfg(feature = "serde")]
2222
use serde::{Deserialize, Serialize};
@@ -55,62 +55,29 @@ use crate::parser::ParserError;
5555
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5656
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5757
pub struct CreateDatabaseBuilder {
58-
/// The database name to create.
5958
pub db_name: ObjectName,
60-
/// Whether `IF NOT EXISTS` was specified.
6159
pub if_not_exists: bool,
62-
/// Optional storage location for the database.
6360
pub location: Option<String>,
64-
/// Optional managed storage location.
6561
pub managed_location: Option<String>,
66-
/// Whether `OR REPLACE` was specified.
6762
pub or_replace: bool,
68-
/// Whether the database is `TRANSIENT`.
6963
pub transient: bool,
70-
/// Optional `CLONE` source object name.
7164
pub clone: Option<ObjectName>,
72-
/// Optional data retention time in days.
7365
pub data_retention_time_in_days: Option<u64>,
74-
/// Optional max data extension time in days.
7566
pub max_data_extension_time_in_days: Option<u64>,
76-
/// Optional external volume identifier.
7767
pub external_volume: Option<String>,
78-
/// Optional catalog name.
7968
pub catalog: Option<String>,
80-
/// Whether to replace invalid characters.
8169
pub replace_invalid_characters: Option<bool>,
82-
/// Optional default DDL collation.
8370
pub default_ddl_collation: Option<String>,
84-
/// Optional storage serialization policy.
8571
pub storage_serialization_policy: Option<StorageSerializationPolicy>,
86-
/// Optional comment attached to the database.
8772
pub comment: Option<String>,
88-
/// Optional default character set (MySQL).
89-
///
90-
/// <https://dev.mysql.com/doc/refman/8.4/en/create-database.html>
91-
pub default_charset: Option<String>,
92-
/// Optional default collation (MySQL).
93-
///
94-
/// <https://dev.mysql.com/doc/refman/8.4/en/create-database.html>
95-
pub default_collation: Option<String>,
96-
/// Optional catalog sync configuration.
9773
pub catalog_sync: Option<String>,
98-
/// Optional catalog sync namespace mode.
9974
pub catalog_sync_namespace_mode: Option<CatalogSyncNamespaceMode>,
100-
/// Optional namespace flatten delimiter for catalog sync.
10175
pub catalog_sync_namespace_flatten_delimiter: Option<String>,
102-
/// Optional tags attached to the database.
10376
pub with_tags: Option<Vec<Tag>>,
104-
/// Optional contact entries associated with the database.
10577
pub with_contacts: Option<Vec<ContactEntry>>,
10678
}
10779

10880
impl CreateDatabaseBuilder {
109-
/// Create a new `CreateDatabaseBuilder` with the given database name.
110-
///
111-
/// # Arguments
112-
///
113-
/// * `name` - The name of the database to be created.
11481
pub fn new(name: ObjectName) -> Self {
11582
Self {
11683
db_name: name,
@@ -128,8 +95,6 @@ impl CreateDatabaseBuilder {
12895
default_ddl_collation: None,
12996
storage_serialization_policy: None,
13097
comment: None,
131-
default_charset: None,
132-
default_collation: None,
13398
catalog_sync: None,
13499
catalog_sync_namespace_mode: None,
135100
catalog_sync_namespace_flatten_delimiter: None,
@@ -138,49 +103,41 @@ impl CreateDatabaseBuilder {
138103
}
139104
}
140105

141-
/// Set the location for the database.
142106
pub fn location(mut self, location: Option<String>) -> Self {
143107
self.location = location;
144108
self
145109
}
146110

147-
/// Set the managed location for the database.
148111
pub fn managed_location(mut self, managed_location: Option<String>) -> Self {
149112
self.managed_location = managed_location;
150113
self
151114
}
152115

153-
/// Set whether this is an `OR REPLACE` operation.
154116
pub fn or_replace(mut self, or_replace: bool) -> Self {
155117
self.or_replace = or_replace;
156118
self
157119
}
158120

159-
/// Set whether this is a transient database.
160121
pub fn transient(mut self, transient: bool) -> Self {
161122
self.transient = transient;
162123
self
163124
}
164125

165-
/// Set whether to use `IF NOT EXISTS`.
166126
pub fn if_not_exists(mut self, if_not_exists: bool) -> Self {
167127
self.if_not_exists = if_not_exists;
168128
self
169129
}
170130

171-
/// Set the clone clause for the database.
172131
pub fn clone_clause(mut self, clone: Option<ObjectName>) -> Self {
173132
self.clone = clone;
174133
self
175134
}
176135

177-
/// Set the data retention time in days.
178136
pub fn data_retention_time_in_days(mut self, data_retention_time_in_days: Option<u64>) -> Self {
179137
self.data_retention_time_in_days = data_retention_time_in_days;
180138
self
181139
}
182140

183-
/// Set the maximum data extension time in days.
184141
pub fn max_data_extension_time_in_days(
185142
mut self,
186143
max_data_extension_time_in_days: Option<u64>,
@@ -189,31 +146,26 @@ impl CreateDatabaseBuilder {
189146
self
190147
}
191148

192-
/// Set the external volume for the database.
193149
pub fn external_volume(mut self, external_volume: Option<String>) -> Self {
194150
self.external_volume = external_volume;
195151
self
196152
}
197153

198-
/// Set the catalog for the database.
199154
pub fn catalog(mut self, catalog: Option<String>) -> Self {
200155
self.catalog = catalog;
201156
self
202157
}
203158

204-
/// Set whether to replace invalid characters.
205159
pub fn replace_invalid_characters(mut self, replace_invalid_characters: Option<bool>) -> Self {
206160
self.replace_invalid_characters = replace_invalid_characters;
207161
self
208162
}
209163

210-
/// Set the default DDL collation.
211164
pub fn default_ddl_collation(mut self, default_ddl_collation: Option<String>) -> Self {
212165
self.default_ddl_collation = default_ddl_collation;
213166
self
214167
}
215168

216-
/// Set the storage serialization policy.
217169
pub fn storage_serialization_policy(
218170
mut self,
219171
storage_serialization_policy: Option<StorageSerializationPolicy>,
@@ -222,31 +174,16 @@ impl CreateDatabaseBuilder {
222174
self
223175
}
224176

225-
/// Set the comment for the database.
226177
pub fn comment(mut self, comment: Option<String>) -> Self {
227178
self.comment = comment;
228179
self
229180
}
230181

231-
/// Set the default character set for the database.
232-
pub fn default_charset(mut self, default_charset: Option<String>) -> Self {
233-
self.default_charset = default_charset;
234-
self
235-
}
236-
237-
/// Set the default collation for the database.
238-
pub fn default_collation(mut self, default_collation: Option<String>) -> Self {
239-
self.default_collation = default_collation;
240-
self
241-
}
242-
243-
/// Set the catalog sync for the database.
244182
pub fn catalog_sync(mut self, catalog_sync: Option<String>) -> Self {
245183
self.catalog_sync = catalog_sync;
246184
self
247185
}
248186

249-
/// Set the catalog sync namespace mode for the database.
250187
pub fn catalog_sync_namespace_mode(
251188
mut self,
252189
catalog_sync_namespace_mode: Option<CatalogSyncNamespaceMode>,
@@ -255,7 +192,6 @@ impl CreateDatabaseBuilder {
255192
self
256193
}
257194

258-
/// Set the catalog sync namespace flatten delimiter for the database.
259195
pub fn catalog_sync_namespace_flatten_delimiter(
260196
mut self,
261197
catalog_sync_namespace_flatten_delimiter: Option<String>,
@@ -264,19 +200,16 @@ impl CreateDatabaseBuilder {
264200
self
265201
}
266202

267-
/// Set the tags for the database.
268203
pub fn with_tags(mut self, with_tags: Option<Vec<Tag>>) -> Self {
269204
self.with_tags = with_tags;
270205
self
271206
}
272207

273-
/// Set the contacts for the database.
274208
pub fn with_contacts(mut self, with_contacts: Option<Vec<ContactEntry>>) -> Self {
275209
self.with_contacts = with_contacts;
276210
self
277211
}
278212

279-
/// Build the `CREATE DATABASE` statement.
280213
pub fn build(self) -> Statement {
281214
Statement::CreateDatabase {
282215
db_name: self.db_name,
@@ -294,8 +227,6 @@ impl CreateDatabaseBuilder {
294227
default_ddl_collation: self.default_ddl_collation,
295228
storage_serialization_policy: self.storage_serialization_policy,
296229
comment: self.comment,
297-
default_charset: self.default_charset,
298-
default_collation: self.default_collation,
299230
catalog_sync: self.catalog_sync,
300231
catalog_sync_namespace_mode: self.catalog_sync_namespace_mode,
301232
catalog_sync_namespace_flatten_delimiter: self.catalog_sync_namespace_flatten_delimiter,
@@ -326,8 +257,6 @@ impl TryFrom<Statement> for CreateDatabaseBuilder {
326257
default_ddl_collation,
327258
storage_serialization_policy,
328259
comment,
329-
default_charset,
330-
default_collation,
331260
catalog_sync,
332261
catalog_sync_namespace_mode,
333262
catalog_sync_namespace_flatten_delimiter,
@@ -349,8 +278,6 @@ impl TryFrom<Statement> for CreateDatabaseBuilder {
349278
default_ddl_collation,
350279
storage_serialization_policy,
351280
comment,
352-
default_charset,
353-
default_collation,
354281
catalog_sync,
355282
catalog_sync_namespace_mode,
356283
catalog_sync_namespace_flatten_delimiter,

0 commit comments

Comments
 (0)