Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ impl Parser {
if !self.applies_snowflake_context_rules() {
return Ok(());
}
if self.is_statement_end_at(0) {
return Err(self.parse_error("Expected an object kind and a name"));
}
let start = self.current;
let checked = match create {
true if self.check_text_seq(&["AI", "FUNCTION"]) => self.check_ai_function(),
Expand All @@ -41,16 +44,21 @@ impl Parser {
/// 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.
fn check_opaque_shape(&mut self, create: bool, kind_at: usize) -> Result<()> {
let after_name = self.current;
let kind = self.tokens[kind_at].text.to_ascii_uppercase();
let second = self.tokens[kind_at + 1].text.to_ascii_uppercase();
let word = |at: usize| {
self.tokens
.get(at)
.map_or_else(String::new, |token| token.text.to_ascii_uppercase())
};
let (kind, second) = (word(kind_at), word(kind_at + 1));
if !create {
let connector = matches!((kind.as_str(), second.as_str()), ("OPENFLOW", "CONNECTOR"));
let warehouse = matches!(kind.as_str(), "WAREHOUSE");
let checked = match (connector, warehouse) {
(true, _) if self.check_text_seq(&["ADD"]) => self.check_connector_version(),
(true, _) if self.check_text_seq(&["PUSH"]) => self.check_connector_push(),
(_, true) => {
let exists = self.tokens[kind_at + 1].token_type == TokenType::If
let exists = self.tokens.get(kind_at + 1).map(|token| token.token_type)
== Some(TokenType::If)
&& self.tokens.get(kind_at + 2).map(|token| token.token_type)
== Some(TokenType::Exists);
let unnamed =
Expand Down
24 changes: 24 additions & 0 deletions crates/sqlquack-syntax-snowflake/src/parser/tests/test_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,30 @@ fn given_incomplete_sql_when_parsing_then_parsing_fails() {
sql: "SELECT x ILIKE",
expected_error: "error",
},
ParseErrorTestCase {
description: "a bare ALTER is rejected, not read past the end of its tokens",
dialect: Some(DialectType::Snowflake),
sql: "ALTER",
expected_error: "Expected an object kind and a name",
},
ParseErrorTestCase {
description: "a bare ALTER ICEBERG is rejected",
dialect: Some(DialectType::Snowflake),
sql: "ALTER ICEBERG",
expected_error: "Expected an object kind and a name",
},
ParseErrorTestCase {
description: "an ALTER ended by a semicolon is rejected",
dialect: Some(DialectType::Snowflake),
sql: "ALTER;",
expected_error: "error",
},
ParseErrorTestCase {
description: "an ALTER ended by a semicolon before a statement is rejected",
dialect: Some(DialectType::Snowflake),
sql: "ALTER;TABLE t1 ADD COLUMN c1 INT",
expected_error: "error",
},
ParseErrorTestCase {
description: "RESAMPLE's USING takes a column, not a string",
dialect: Some(DialectType::Snowflake),
Expand Down
Loading