Skip to content

Commit 7754eb4

Browse files
committed
fix(snowflake): match recorded verdicts for typed operands
Resource monitor trigger percentages and CODE BUNDLE / NOTEBOOK PROJECT FROM sources must be literals of the recorded kind, a COPY transform column takes no string after a dot, and RECLUSTER MAX_SIZE parses a string that Snowflake rejects only semantically. Regenerate the ALTER SERVICE obligations, drop unobservable records whose obligations no longer exist, and refresh the syntax baseline.
1 parent 6431c68 commit 7754eb4

8 files changed

Lines changed: 2789 additions & 514 deletions

File tree

‎coverage/syntax/baseline.json‎

Lines changed: 2711 additions & 444 deletions
Large diffs are not rendered by default.

‎coverage/syntax/obligations/ddl.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66607,12 +66607,12 @@ anchor = "doc.identifiers-syntax"
6660766607
note = "reserved: a reserved keyword, unquoted (expected rejection) and double-quoted (expected acceptance)"
6660866608

6660966609
[[obligation]]
66610-
id = "sf.ddl.alter-service.fromspecification-fromspecificationtemplate.o097"
66610+
id = "sf.ddl.alter-service.fromspecification-fromspecificationtemplate.o101"
6661166611
kind = "identifier_class"
6661266612
required = true
6661366613
target = "<stage>"
66614-
anchor = "doc.identifiers-syntax"
66615-
note = "quoted: a double-quoted identifier with blanks and mixed case"
66614+
anchor = "doc.sql.alter-service / Syntax"
66615+
note = "quoted: a double-quoted identifier with blanks and mixed case, observed"
6661666616

6661766617
[[obligation]]
6661866618
id = "sf.ddl.alter-service.fromspecification-fromspecificationtemplate.o082"

‎coverage/syntax/unobservable/ddl.toml‎

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,18 +2855,6 @@ cases = [
28552855
runs = []
28562856
probes = []
28572857

2858-
[[unobservable]]
2859-
obligation = "sf.ddl.create-openflow-runtime.o007"
2860-
form = "sf.ddl.create-openflow-runtime"
2861-
construct = "a valid operand: CREATE OPENFLOW RUNTIME IF NOT EXISTS v1 . v1 . v1 IN DEPLOYMENT v1 NODE_TYPE = SMALL NODE_TYPE_TIER = 'S1' MIN_NODES = 1 MAX_NODES = 1 EXECUTE_AS_ROLE = v1 EXTERNAL_ACCESS_INTEGRATIONS = ( v1 , v1 ) DISPLAY_NAME = 'm' COMMENT = 'm' ;"
2862-
reason = "not submitted: held by the capture guard in chunk ux-07: CREATE of an account-level or unvetted kind (OPENFLOW RUNTIME IF)"
2863-
cause = "not_submitted"
2864-
cases = [
2865-
{ case_id = "sf.ddl.create-openflow-runtime.k902812cf55f6", sql_sha256 = "902812cf55f69c4d8f71102d21efa76ce8b3442b2350d86ba61b0550bb203627" },
2866-
]
2867-
runs = []
2868-
probes = []
2869-
28702858
[[unobservable]]
28712859
obligation = "sf.ddl.create-openflow-runtime.o008"
28722860
form = "sf.ddl.create-openflow-runtime"
@@ -2879,18 +2867,6 @@ cases = [
28792867
runs = []
28802868
probes = []
28812869

2882-
[[unobservable]]
2883-
obligation = "sf.ddl.create-openflow-runtime.o009"
2884-
form = "sf.ddl.create-openflow-runtime"
2885-
construct = "a valid operand: CREATE OPENFLOW RUNTIME IF NOT EXISTS v1 . v1 . v1 IN DEPLOYMENT v1 NODE_TYPE = SMALL NODE_TYPE_TIER = 'S1' MIN_NODES = 1 MAX_NODES = 1 EXECUTE_AS_ROLE = v1 EXTERNAL_ACCESS_INTEGRATIONS = ( v1 , v1 ) DISPLAY_NAME = 'm' COMMENT = 'm' ;"
2886-
reason = "not submitted: held by the capture guard in chunk ux-07: CREATE of an account-level or unvetted kind (OPENFLOW RUNTIME IF)"
2887-
cause = "not_submitted"
2888-
cases = [
2889-
{ case_id = "sf.ddl.create-openflow-runtime.k902812cf55f6", sql_sha256 = "902812cf55f69c4d8f71102d21efa76ce8b3442b2350d86ba61b0550bb203627" },
2890-
]
2891-
runs = []
2892-
probes = []
2893-
28942870
[[unobservable]]
28952871
obligation = "sf.ddl.create-openflow-runtime.o010"
28962872
form = "sf.ddl.create-openflow-runtime"
@@ -3155,18 +3131,6 @@ cases = [
31553131
runs = []
31563132
probes = []
31573133

3158-
[[unobservable]]
3159-
obligation = "sf.ddl.create-openflow-runtime.o032"
3160-
form = "sf.ddl.create-openflow-runtime"
3161-
construct = "a valid operand: CREATE OPENFLOW RUNTIME v1 IN DEPLOYMENT v1 NODE_TYPE = SMALL MIN_NODES = 1 MAX_NODES = 1 EXECUTE_AS_ROLE = v1 ;"
3162-
reason = "not submitted: held by the capture guard in chunk ux-06: CREATE of an account-level or unvetted kind (OPENFLOW RUNTIME v1)"
3163-
cause = "not_submitted"
3164-
cases = [
3165-
{ case_id = "sf.ddl.create-openflow-runtime.k12803a83606a", sql_sha256 = "12803a83606a6ac49cd68bb169af6369dd66f264c3b85b92c49581d7cc46ee96" },
3166-
]
3167-
runs = []
3168-
probes = []
3169-
31703134
[[unobservable]]
31713135
obligation = "sf.ddl.create-openflow-runtime.o033"
31723136
form = "sf.ddl.create-openflow-runtime"
@@ -3203,18 +3167,6 @@ cases = [
32033167
runs = []
32043168
probes = []
32053169

3206-
[[unobservable]]
3207-
obligation = "sf.ddl.create-openflow-runtime.o036"
3208-
form = "sf.ddl.create-openflow-runtime"
3209-
construct = "a valid operand: CREATE OPENFLOW RUNTIME IF NOT EXISTS v1 . v1 . v1 IN DEPLOYMENT v1 NODE_TYPE = SMALL NODE_TYPE_TIER = 'S1' MIN_NODES = 1 MAX_NODES = 1 EXECUTE_AS_ROLE = v1 EXTERNAL_ACCESS_INTEGRATIONS = ( v1 , v1 ) DISPLAY_NAME = 'm' COMMENT = 'm' ;"
3210-
reason = "not submitted: held by the capture guard in chunk ux-07: CREATE of an account-level or unvetted kind (OPENFLOW RUNTIME IF)"
3211-
cause = "not_submitted"
3212-
cases = [
3213-
{ case_id = "sf.ddl.create-openflow-runtime.k902812cf55f6", sql_sha256 = "902812cf55f69c4d8f71102d21efa76ce8b3442b2350d86ba61b0550bb203627" },
3214-
]
3215-
runs = []
3216-
probes = []
3217-
32183170
[[unobservable]]
32193171
obligation = "sf.ddl.create-openflow-runtime.o037"
32203172
form = "sf.ddl.create-openflow-runtime"
@@ -4574,18 +4526,6 @@ cases = [
45744526
runs = []
45754527
probes = []
45764528

4577-
[[unobservable]]
4578-
obligation = "sf.ddl.create-streamlit.define-streamlit.o057"
4579-
form = "sf.ddl.create-streamlit.define-streamlit"
4580-
construct = "a valid operand: DEFINE STREAMLIT d1.s1.v1 FROM 'asset://a1/' MAIN_FILE = 'm' QUERY_WAREHOUSE = v1 RUNTIME_NAME = 'm' COMPUTE_POOL = v1 COMMENT = 'm' TITLE = 'm' IMPORTS = ( 'm' , 'm' ) EXTERNAL_ACCESS_INTEGRATIONS = ( i1 , i1 ) SECRETS = ( 'm' = d1.s1.v1 , 'm' = d1.s1.v1 ) ;"
4581-
reason = "not submitted: held by capture guard f187c2c in the define-stage packet udq-08.jsonl: billable or out-of-account: compute pool or service"
4582-
cause = "not_submitted"
4583-
cases = [
4584-
{ case_id = "sf.ddl.create-streamlit.define-streamlit.kd5fc596eaaca", sql_sha256 = "d5fc596eaaca94b885013dde68a1dc15ab1926e48a043a835741aa81caebc2e1" },
4585-
]
4586-
runs = []
4587-
probes = []
4588-
45894529
[[unobservable]]
45904530
obligation = "sf.ddl.create-streamlit.define-streamlit.o058"
45914531
form = "sf.ddl.create-streamlit.define-streamlit"

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,13 @@ impl Parser {
195195
let mut properties: Vec<ObjectProperty> = Vec::new();
196196
if self.match_identifier("MAX_SIZE") {
197197
self.expect_token(TokenType::Eq)?;
198-
properties.push(property(
199-
"MAX_SIZE",
200-
None,
201-
Some(self.parse_number_operand()?),
202-
));
198+
// Snowflake parses a string here and rejects it only semantically.
199+
let size = if self.check(TokenType::String) {
200+
self.parse_primary()?
201+
} else {
202+
self.parse_number_operand()?
203+
};
204+
properties.push(property("MAX_SIZE", None, Some(size)));
203205
}
204206
if self.match_token(TokenType::Where) {
205207
properties.push(property("WHERE", None, Some(self.parse_expression()?)));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ impl Parser {
330330
}
331331
Some(TokenType::Dot)
332332
if load
333-
&& (next == Some(TokenType::From)
333+
&& (matches!(next, Some(TokenType::From | TokenType::String))
334334
|| self.copy_type(index - 1) == Some(TokenType::String)
335335
|| self.copy_reserved(index - 1)) =>
336336
{

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ impl Parser {
378378
self.skip();
379379
let mut triggers: Vec<ObjectProperty> = Vec::new();
380380
while self.match_token(TokenType::On) {
381+
if !self.check(TokenType::Number) {
382+
return Err(self.parse_error("Expected a number before PERCENT"));
383+
}
381384
let percent = self.parse_object_value()?;
382385
self.expect_alter_words(&[&["PERCENT", "DO"]])?;
383386
let action = self.parse_simple_name()?;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Parser {
3535
checked
3636
}
3737

38-
/// 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.
38+
/// After a CREATE's name, the shape its kind needs: FROM and a quoted location 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.
3939
fn check_opaque_shape(&mut self, create: bool, kind_at: usize) -> Result<()> {
4040
let after_name = self.current;
4141
let kind = self.tokens[kind_at].text.to_ascii_uppercase();
@@ -60,6 +60,7 @@ impl Parser {
6060
return checked;
6161
}
6262
let project = matches!(second.as_str(), "PROJECT") && after_name > kind_at + 2;
63+
let project_or_bundle = project || kind == "CODE";
6364
let checked = match kind.as_str() {
6465
"EXTERNAL" if matches!(second.as_str(), "AGENT") => self.check_external_agent_tail(),
6566
"VARIABLE" => self.check_variable_tail(),
@@ -70,6 +71,9 @@ impl Parser {
7071
"NOTEBOOK" if project && !self.check(TokenType::From) => {
7172
Err(self.parse_error("Expected FROM"))
7273
}
74+
"CODE" | "NOTEBOOK" if project_or_bundle && !self.check_next(TokenType::String) => {
75+
Err(self.parse_error("Expected a quoted location after FROM"))
76+
}
7377
"PIPE" => self.check_pipe_body(),
7478
"INTERACTIVE" if self.check(TokenType::LParen) => {
7579
Err(self.parse_error("Expected a property after the warehouse name"))

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,65 @@ fn given_a_snowflake_external_consumer_when_parsing_then_recorded_verdicts_hold(
7272
}
7373
}
7474

75+
#[test]
76+
fn given_typed_operands_when_parsing_then_recorded_verdicts_hold() {
77+
let test_cases = [
78+
SnowflakeVerdictTestCase {
79+
description: "a RECLUSTER MAX_SIZE string is parsed (recorded semantic error)",
80+
sql: "ALTER TABLE v1 RECLUSTER MAX_SIZE = 'x' ;",
81+
expected_kind: Some("alter_object"),
82+
},
83+
SnowflakeVerdictTestCase {
84+
description: "CREATE CODE BUNDLE FROM takes a string (recorded errno 1003)",
85+
sql: "CREATE CODE BUNDLE v1 . v1 . v1 FROM m1 ;",
86+
expected_kind: None,
87+
},
88+
SnowflakeVerdictTestCase {
89+
description: "DEFINE CODE BUNDLE FROM takes a string (recorded errno 1003)",
90+
sql: "DEFINE CODE BUNDLE v1 . v1 . v1 FROM m1 ;",
91+
expected_kind: None,
92+
},
93+
SnowflakeVerdictTestCase {
94+
description: "NOTEBOOK PROJECT FROM takes a string (recorded errno 1003)",
95+
sql: "CREATE NOTEBOOK PROJECT v1 . v1 . v1 FROM m1 ;",
96+
expected_kind: None,
97+
},
98+
SnowflakeVerdictTestCase {
99+
description: "a COPY transform column takes no string after . (recorded errno 1003)",
100+
sql: "COPY INTO v1 FROM ( SELECT $1 . 'v1' FROM @s1 ) ;",
101+
expected_kind: None,
102+
},
103+
SnowflakeVerdictTestCase {
104+
description: "ALTER RESOURCE MONITOR needs a number for a later percent (recorded errno 1003)",
105+
sql: "ALTER RESOURCE MONITOR v1 TRIGGERS ON 80 PERCENT DO SUSPEND ON 'x' PERCENT DO SUSPEND ;",
106+
expected_kind: None,
107+
},
108+
SnowflakeVerdictTestCase {
109+
description: "ALTER RESOURCE MONITOR needs a number for the percent (recorded errno 1003)",
110+
sql: "ALTER RESOURCE MONITOR v1 TRIGGERS ON 'x' PERCENT DO SUSPEND ;",
111+
expected_kind: None,
112+
},
113+
SnowflakeVerdictTestCase {
114+
description: "CREATE RESOURCE MONITOR needs a number for the percent (recorded errno 1003)",
115+
sql: "CREATE RESOURCE MONITOR v1 WITH CREDIT_QUOTA = 1 TRIGGERS ON 'x' PERCENT DO SUSPEND ;",
116+
expected_kind: None,
117+
},
118+
SnowflakeVerdictTestCase {
119+
description: "CREATE RESOURCE MONITOR needs a number for a later percent (recorded errno 1003)",
120+
sql: "CREATE RESOURCE MONITOR v1 WITH CREDIT_QUOTA = 1 TRIGGERS ON 80 PERCENT DO SUSPEND ON 'x' PERCENT DO SUSPEND ;",
121+
expected_kind: None,
122+
},
123+
];
124+
for test_case in test_cases {
125+
assert_eq!(
126+
snowflake_kind(test_case.sql),
127+
test_case.expected_kind.map(str::to_owned),
128+
"{}",
129+
test_case.description
130+
);
131+
}
132+
}
133+
75134
#[test]
76135
fn given_a_snowflake_external_consumer_when_parsing_then_the_tree_keeps_its_kind() {
77136
let test_cases = [

0 commit comments

Comments
 (0)