Skip to content

Commit a2fea10

Browse files
mobuchowskialamb
andauthored
snowflake: add support for TRANSIENT keyword (#807)
* snowflake: add support for TRANSIENT keyword Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com> * fix clippy --------- Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
1 parent 79009f5 commit a2fea10

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

src/ast/helpers/stmt_create_table.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub struct CreateTableBuilder {
5050
pub external: bool,
5151
pub global: Option<bool>,
5252
pub if_not_exists: bool,
53+
pub transient: bool,
5354
pub name: ObjectName,
5455
pub columns: Vec<ColumnDef>,
5556
pub constraints: Vec<TableConstraint>,
@@ -78,6 +79,7 @@ impl CreateTableBuilder {
7879
external: false,
7980
global: None,
8081
if_not_exists: false,
82+
transient: false,
8183
name,
8284
columns: vec![],
8385
constraints: vec![],
@@ -123,6 +125,11 @@ impl CreateTableBuilder {
123125
self
124126
}
125127

128+
pub fn transient(mut self, transient: bool) -> Self {
129+
self.transient = transient;
130+
self
131+
}
132+
126133
pub fn columns(mut self, columns: Vec<ColumnDef>) -> Self {
127134
self.columns = columns;
128135
self
@@ -213,6 +220,7 @@ impl CreateTableBuilder {
213220
external: self.external,
214221
global: self.global,
215222
if_not_exists: self.if_not_exists,
223+
transient: self.transient,
216224
name: self.name,
217225
columns: self.columns,
218226
constraints: self.constraints,
@@ -248,6 +256,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
248256
external,
249257
global,
250258
if_not_exists,
259+
transient,
251260
name,
252261
columns,
253262
constraints,
@@ -272,6 +281,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
272281
external,
273282
global,
274283
if_not_exists,
284+
transient,
275285
name,
276286
columns,
277287
constraints,

src/ast/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ pub enum Statement {
12321232
external: bool,
12331233
global: Option<bool>,
12341234
if_not_exists: bool,
1235+
transient: bool,
12351236
/// Table name
12361237
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
12371238
name: ObjectName,
@@ -2034,6 +2035,7 @@ impl fmt::Display for Statement {
20342035
with_options,
20352036
or_replace,
20362037
if_not_exists,
2038+
transient,
20372039
hive_distribution,
20382040
hive_formats,
20392041
external,
@@ -2060,7 +2062,7 @@ impl fmt::Display for Statement {
20602062
// `CREATE TABLE t (a INT) AS SELECT a from t2`
20612063
write!(
20622064
f,
2063-
"CREATE {or_replace}{external}{global}{temporary}TABLE {if_not_exists}{name}",
2065+
"CREATE {or_replace}{external}{global}{temporary}{transient}TABLE {if_not_exists}{name}",
20642066
or_replace = if *or_replace { "OR REPLACE " } else { "" },
20652067
external = if *external { "EXTERNAL " } else { "" },
20662068
global = global
@@ -2074,6 +2076,7 @@ impl fmt::Display for Statement {
20742076
.unwrap_or(""),
20752077
if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
20762078
temporary = if *temporary { "TEMPORARY " } else { "" },
2079+
transient = if *transient { "TRANSIENT " } else { "" },
20772080
name = name,
20782081
)?;
20792082
if let Some(on_cluster) = on_cluster {

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ define_keywords!(
570570
TOP,
571571
TRAILING,
572572
TRANSACTION,
573+
TRANSIENT,
573574
TRANSLATE,
574575
TRANSLATE_REGEX,
575576
TRANSLATION,

src/parser.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,6 +2266,7 @@ impl<'a> Parser<'a> {
22662266
let or_replace = self.parse_keywords(&[Keyword::OR, Keyword::REPLACE]);
22672267
let local = self.parse_one_of_keywords(&[Keyword::LOCAL]).is_some();
22682268
let global = self.parse_one_of_keywords(&[Keyword::GLOBAL]).is_some();
2269+
let transient = self.parse_one_of_keywords(&[Keyword::TRANSIENT]).is_some();
22692270
let global: Option<bool> = if global {
22702271
Some(true)
22712272
} else if local {
@@ -2277,7 +2278,7 @@ impl<'a> Parser<'a> {
22772278
.parse_one_of_keywords(&[Keyword::TEMP, Keyword::TEMPORARY])
22782279
.is_some();
22792280
if self.parse_keyword(Keyword::TABLE) {
2280-
self.parse_create_table(or_replace, temporary, global)
2281+
self.parse_create_table(or_replace, temporary, global, transient)
22812282
} else if self.parse_keyword(Keyword::MATERIALIZED) || self.parse_keyword(Keyword::VIEW) {
22822283
self.prev_token();
22832284
self.parse_create_view(or_replace)
@@ -3248,6 +3249,7 @@ impl<'a> Parser<'a> {
32483249
or_replace: bool,
32493250
temporary: bool,
32503251
global: Option<bool>,
3252+
transient: bool,
32513253
) -> Result<Statement, ParserError> {
32523254
let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]);
32533255
let table_name = self.parse_object_name()?;
@@ -3352,6 +3354,7 @@ impl<'a> Parser<'a> {
33523354
.table_properties(table_properties)
33533355
.or_replace(or_replace)
33543356
.if_not_exists(if_not_exists)
3357+
.transient(transient)
33553358
.hive_distribution(hive_distribution)
33563359
.hive_formats(Some(hive_formats))
33573360
.global(global)

tests/sqlparser_snowflake.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ fn test_snowflake_create_table() {
3434
}
3535
}
3636

37+
#[test]
38+
fn test_snowflake_create_transient_table() {
39+
let sql = "CREATE TRANSIENT TABLE CUSTOMER (id INT, name VARCHAR(255))";
40+
match snowflake_and_generic().verified_stmt(sql) {
41+
Statement::CreateTable {
42+
name, transient, ..
43+
} => {
44+
assert_eq!("CUSTOMER", name.to_string());
45+
assert!(transient)
46+
}
47+
_ => unreachable!(),
48+
}
49+
}
50+
3751
#[test]
3852
fn test_snowflake_single_line_tokenize() {
3953
let sql = "CREATE TABLE# this is a comment \ntable_1";

0 commit comments

Comments
 (0)