Skip to content

Commit ea5ac2d

Browse files
committed
fix(syntax): refuse a malformed CREATE INTERACTIVE WAREHOUSE and read MAX_STALENESS as a string
Snowflake refuses CREATE INTERACTIVE WAREHOUSE with no name, with IF EXISTS, or with a bare parenthesised list after the name, so the opaque check now knows the kind and refuses them too. A semantic view's MAX_STALENESS takes a string: Snowflake refuses a number there and parses a string, so the parser does the same.
1 parent 295e2fe commit ea5ac2d

6 files changed

Lines changed: 36 additions & 17 deletions

File tree

‎crates/sqlquack-syntax-snowflake/src/parser/_helpers/ddl/snowflake_alter.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ impl Parser {
6464
if self.match_text_seq(&["SNAPSHOT", "SET"]) {
6565
return self.parse_alter_snapshot_set().map(Some);
6666
}
67-
// `ALTER SNAPSHOT POLICY SET COMMENT = ...` alters a snapshot named POLICY (recorded errno 2003).
6867
let policy_named = self.tokens.get(self.current + 2).is_some_and(|token| {
6968
token.token_type != TokenType::QuotedIdentifier
7069
&& token.text.eq_ignore_ascii_case("SET")

‎crates/sqlquack-syntax-snowflake/src/parser/_helpers/ddl/snowflake_opaque.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl Parser {
3232
checked
3333
}
3434

35-
/// After a CREATE's name, the shape its kind needs: FROM for a code bundle or notebook project, a snapshot's service volume, an external agent's version, a variable's type, AS COPY for a pipe's body, an Openflow connector's added version and push, and a warehouse's actions; the cursor stays after the name.
35+
/// After a CREATE's name, the shape its kind needs: FROM for a code bundle or notebook project, a snapshot's service volume, an external agent's version, a variable's type, AS COPY for a pipe's body, no bare list after an interactive warehouse's name, an Openflow connector's added version and push, and a warehouse's actions; the cursor stays after the name.
3636
fn check_opaque_shape(&mut self, create: bool, kind_at: usize) -> Result<()> {
3737
let after_name = self.current;
3838
let kind = self.tokens[kind_at].text.to_ascii_uppercase();
@@ -68,6 +68,9 @@ impl Parser {
6868
Err(self.parse_error("Expected FROM"))
6969
}
7070
"PIPE" => self.check_pipe_body(),
71+
"INTERACTIVE" if self.check(TokenType::LParen) => {
72+
Err(self.parse_error("Expected a property after the warehouse name"))
73+
}
7174
_ => Ok(()),
7275
};
7376
self.current = after_name;

‎crates/sqlquack-syntax-snowflake/src/parser/_helpers/ddl/snowflake_semantic_view.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ impl Parser {
105105
}
106106
if self.match_text_seq(&["MAX_STALENESS"]) {
107107
self.expect_token(TokenType::Eq)?;
108-
if !self.check(TokenType::Number) && !self.check(TokenType::String) {
109-
return Err(self.parse_error("Expected a number after MAX_STALENESS ="));
108+
if !self.check(TokenType::String) {
109+
return Err(self.parse_error("Expected a string after MAX_STALENESS ="));
110110
}
111111
return Ok(property("MAX_STALENESS", None, Some(self.parse_primary()?)));
112112
}

‎crates/sqlquack-syntax-snowflake/src/parser/_helpers/ddl/snowflake_show.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Parser {
7373
return Ok(Some(Expression::Show(Box::new(show))));
7474
}
7575
if let Some(clause) = kind.strip_prefix("DELEGATED AUTHORIZATIONS ") {
76-
let clause = if clause == "BY USER" && self.is_statement_end_at(0) {
76+
let clause = if matches!(clause, "BY USER") && self.is_statement_end_at(0) {
7777
self.current -= 1;
7878
"BY"
7979
} else {

‎crates/sqlquack-syntax-snowflake/src/parser/constants.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ pub(crate) const SNOWFLAKE_OPAQUE_KINDS: &[&[&str]] = &[
549549
&["AI", "FUNCTION"],
550550
&["CODE", "BUNDLE"],
551551
&["EXTERNAL", "LISTING"],
552+
&["INTERACTIVE", "WAREHOUSE"],
552553
&["NOTEBOOK", "PROJECT"],
553554
&["OPENFLOW", "DATA", "PLANE", "INTEGRATION"],
554555
&["ORGANIZATION", "ACCOUNT"],

‎crates/sqlquack-syntax-snowflake/tests/parser/test_snowflake_receipted_objects.rs‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,26 @@ fn given_snowflake_numeric_operands_given_a_string_when_parsing_then_recorded_ve
13381338
sql: "CREATE SEMANTIC VIEW v1 TABLES ( v1 ) MAX_STALENESS = 'x' ;",
13391339
expected_kind: Some("create_object"),
13401340
},
1341+
SnowflakeVerdictTestCase {
1342+
description: "a semantic view refuses a number as MAX_STALENESS (recorded errno 1003)",
1343+
sql: "CREATE SEMANTIC VIEW v1 TABLES ( v1 ) MAX_STALENESS = 1 ;",
1344+
expected_kind: None,
1345+
},
1346+
SnowflakeVerdictTestCase {
1347+
description: "an interactive warehouse needs a name (recorded errno 1003)",
1348+
sql: "CREATE INTERACTIVE WAREHOUSE ;",
1349+
expected_kind: None,
1350+
},
1351+
SnowflakeVerdictTestCase {
1352+
description: "an interactive warehouse takes IF NOT EXISTS, not IF EXISTS (recorded errno 1003)",
1353+
sql: "CREATE INTERACTIVE WAREHOUSE IF EXISTS v1 ;",
1354+
expected_kind: None,
1355+
},
1356+
SnowflakeVerdictTestCase {
1357+
description: "an interactive warehouse takes no bare list after its name (recorded errno 1003)",
1358+
sql: "CREATE INTERACTIVE WAREHOUSE v1 ( v1 = 'm' ) ;",
1359+
expected_kind: None,
1360+
},
13411361
];
13421362
for test_case in test_cases {
13431363
assert_eq!(
@@ -1350,19 +1370,15 @@ fn given_snowflake_numeric_operands_given_a_string_when_parsing_then_recorded_ve
13501370
}
13511371

13521372
#[test]
1353-
fn given_a_snowflake_semantic_view_max_staleness_when_parsing_then_it_is_kept() {
1354-
assert_eq!(
1355-
statement_at(
1356-
"CREATE SEMANTIC VIEW v1 TABLES ( v1 ) MAX_STALENESS = 120 COMMENT = 'm' ;",
1357-
"/0/create_object/properties/1"
1358-
)["kind"],
1359-
json!("MAX_STALENESS")
1360-
);
1361-
}
1362-
1363-
#[test]
1364-
fn given_snowflake_routine_modifiers_or_a_snapshot_named_policy_when_parsing_then_they_are_kept() {
1373+
fn given_snowflake_routine_modifiers_staleness_or_a_snapshot_named_policy_when_parsing_then_they_are_kept(
1374+
) {
13651375
let test_cases = [
1376+
StatementTestCase {
1377+
description: "a semantic view keeps MAX_STALENESS as a property",
1378+
sql: "CREATE SEMANTIC VIEW v1 TABLES ( v1 ) MAX_STALENESS = '1 hour' COMMENT = 'm' ;",
1379+
pointer: "/0/create_object/properties/1/kind",
1380+
expected_value: json!("MAX_STALENESS"),
1381+
},
13661382
StatementTestCase {
13671383
description: "a function keeps SECURE",
13681384
sql: "CREATE SECURE EXTERNAL FUNCTION v1 ( ) RETURNS INT API_INTEGRATION = v1 AS 'm' ;",

0 commit comments

Comments
 (0)