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
5 changes: 4 additions & 1 deletion coverage/syntax-databricks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,4 +605,7 @@ alternations, groups, `PERMUTE` and quantifiers) beside the pattern's text, beca
Syntax block defines the pattern as a grammar of its own rather than as a string.

Spellings the language treats as one token stay one tree: the letter case of keywords and of a
raw-string prefix, the quote character around a string or binary literal, and comments.
raw-string prefix, the quote character around a string or binary literal, and comments. An
unquoted function name keeps the case it is written in, so `count` and `COUNT` give two trees, but
its case carries no meaning: the formatter writes built-in names in upper case, and its round trip
compares unquoted function names without their case. A backquoted name keeps its case.
51 changes: 51 additions & 0 deletions coverage/syntax-databricks/reviews/expressions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1292,3 +1292,54 @@ note = "Re-binds db-expressions-063, not a re-read: that exclusion was bound to
[[review.exclusion]]
form = "db.expressions.object-type"
reason = "output-only type. The page (doc.data-types.object-type, page_sha256 bb2353b8cf2213122635372bfbe0177c7a19da940f0138ce38766f0368c5546a) says: \"The OBJECT cannot be stored in a table column. It is only exposed when calling schema_of_variant or schema_of_variant_agg.\" The pinned engine (2026.45) and the local parser both refuse OBJECT as input. Reconsider if the page changes or the engine starts accepting OBJECT as input."

[[review]]
id = "db-expressions-066"
family = "expressions"
catalogue_sha256 = "ffc590e2daad0e5c31541285aca1a5a7d1ce7e7bedb0c1ccdc4c1cfcdd32473c"
obligations_sha256 = "697332d6178cfd5465cf1ebae8c6d98f956a76ed507c8807032c76c97f48bc11"
parser_tree = "65eb7d867d31419e4ab65ad8122999be321d3e50"
reviewed_utc = "2026-11-18T15:02:18Z"
verdict = "approved"
forms = [
"db.expressions.object-type",
]
note = "Re-binds db-expressions-065, not a re-read: that exclusion was bound to parser tree 243ba4a2 and went stale when the parser kept the written spelling of comments, locations, paths, formats, function bodies, handlers, resource URIs and SQLSTATE values, and a function parameter's comment (parser tree 65eb7d86), so object-type again left the excluded count. The catalogue and obligation files are byte-identical to the ones it bound (catalogue ffc590e2, obligations 697332d6), and the local parser still refuses OBJECT as input in all three cases, with the same error as before (unsupported data type OBJECT, position 22). The exclusion and its reason are repeated unchanged."

[[review.exclusion]]
form = "db.expressions.object-type"
reason = "output-only type. The page (doc.data-types.object-type, page_sha256 bb2353b8cf2213122635372bfbe0177c7a19da940f0138ce38766f0368c5546a) says: \"The OBJECT cannot be stored in a table column. It is only exposed when calling schema_of_variant or schema_of_variant_agg.\" The pinned engine (2026.45) and the local parser both refuse OBJECT as input. Reconsider if the page changes or the engine starts accepting OBJECT as input."

[[review]]
id = "db-expressions-067"
family = "expressions"
catalogue_sha256 = "ffc590e2daad0e5c31541285aca1a5a7d1ce7e7bedb0c1ccdc4c1cfcdd32473c"
obligations_sha256 = "697332d6178cfd5465cf1ebae8c6d98f956a76ed507c8807032c76c97f48bc11"
parser_tree = "3d4fbc2eb304670ab3b8472c8a98ff374880a3f1"
reviewed_utc = "2026-11-18T15:19:01Z"
verdict = "approved"
forms = [
"db.expressions.object-type",
]
note = "Re-binds db-expressions-066, not a re-read: that exclusion was bound to parser tree 65eb7d86 and went stale when the parser kept raw and adjacent COPY credential values and a raw string after a literal type (parser tree 3d4fbc2e), so object-type again left the excluded count. The catalogue and obligation files are byte-identical to the ones it bound (catalogue ffc590e2, obligations 697332d6), and the local parser still refuses OBJECT as input in all three cases, with the same error as before (unsupported data type OBJECT, position 22). The exclusion and its reason are repeated unchanged."

[[review.exclusion]]
form = "db.expressions.object-type"
reason = "output-only type. The page (doc.data-types.object-type, page_sha256 bb2353b8cf2213122635372bfbe0177c7a19da940f0138ce38766f0368c5546a) says: \"The OBJECT cannot be stored in a table column. It is only exposed when calling schema_of_variant or schema_of_variant_agg.\" The pinned engine (2026.45) and the local parser both refuse OBJECT as input. Reconsider if the page changes or the engine starts accepting OBJECT as input."

[[review]]
id = "db-expressions-068"
family = "expressions"
catalogue_sha256 = "ffc590e2daad0e5c31541285aca1a5a7d1ce7e7bedb0c1ccdc4c1cfcdd32473c"
obligations_sha256 = "697332d6178cfd5465cf1ebae8c6d98f956a76ed507c8807032c76c97f48bc11"
parser_tree = "359320d6cc062fb34f152cdb7017cbe3f81c5c30"
reviewed_utc = "2026-11-18T16:28:23Z"
verdict = "approved"
forms = [
"db.expressions.object-type",
]
note = "Re-binds db-expressions-067, not a re-read: that exclusion was bound to parser tree 3d4fbc2e and went stale when the parser stopped recording a numeric COPY credential value as a written spelling (parser tree 359320d6), so object-type again left the excluded count. The catalogue and obligation files are byte-identical to the ones it bound (catalogue ffc590e2, obligations 697332d6), and the local parser still refuses OBJECT as input in all three cases, with the same error as before (unsupported data type OBJECT, position 22). The exclusion and its reason are repeated unchanged."

[[review.exclusion]]
form = "db.expressions.object-type"
reason = "output-only type. The page (doc.data-types.object-type, page_sha256 bb2353b8cf2213122635372bfbe0177c7a19da940f0138ce38766f0368c5546a) says: \"The OBJECT cannot be stored in a table column. It is only exposed when calling schema_of_variant or schema_of_variant_agg.\" The pinned engine (2026.45) and the local parser both refuse OBJECT as input. Reconsider if the page changes or the engine starts accepting OBJECT as input."
7 changes: 5 additions & 2 deletions coverage/syntax-databricks/screen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
#
# Letter case is allowed without an entry, because the screen makes no case variants: the lexer
# reads a keyword and the r or R prefix of a raw string case-insensitively, so SELECT and select,
# and r'x' and R'x', are one token each and give one tree. A receipt that shows Databricks reading
# two such spellings differently makes it a finding.
# and r'x' and R'x', are one token each and give one tree. The letter case of an unquoted function
# name is allowed too: the tree keeps it as written, so count and COUNT give two trees, but Databricks
# reads unquoted function names case-insensitively, and the formatter writes built-in names in upper
# case, so its round trip compares them without case. A backquoted name keeps its case. A receipt
# that shows Databricks reading two such spellings differently makes it a finding.
#
# [[lexical]]
# mutation = "requote"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ pub(crate) fn bigquery_literal_type(expression: &Expression) -> Option<&'static
Expression::Literal(literal) => match literal.as_ref() {
Literal::Number(text) if text.contains(['.', 'e', 'E']) => Kind::Float64,
Literal::Number(_) | Literal::HexNumber(_) => Kind::Int64,
Literal::String(_) | Literal::TripleQuotedString(..) | Literal::RawString(_) => {
Kind::String
}
Literal::String(_)
| Literal::TripleQuotedString(..)
| Literal::RawString(_)
| Literal::JoinedString(..) => Kind::String,
Literal::ByteString(_) => Kind::Bytes,
Literal::Date(_) => Kind::Date,
Literal::Datetime(_) => Kind::Datetime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,52 @@ fn given_a_bigquery_query_when_checking_it_then_findings_follow_googlesql() {
);
}
}

#[test]
fn given_one_string_spelled_two_ways_when_grouping_then_the_expressions_match() {
let test_cases = [
QueryFindingsTestCase {
description: "adjacent strings in the select, one string in GROUP BY",
sql: "SELECT COALESCE(status, 'a' 'b') AS x FROM orders GROUP BY COALESCE(status, 'ab')",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "one string in the select, adjacent strings in GROUP BY",
sql: "SELECT COALESCE(status, 'ab') AS x FROM orders GROUP BY COALESCE(status, 'a' 'b')",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "adjacent strings in a concatenation",
sql: "SELECT status || 'a' 'b' AS x FROM orders GROUP BY status || 'ab'",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "a raw string in the select, a plain one in GROUP BY",
sql: "SELECT COALESCE(status, r'ab') AS x FROM orders GROUP BY COALESCE(status, 'ab')",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "a plain string in the select, a raw one in GROUP BY",
sql: "SELECT COALESCE(status, 'ab') AS x FROM orders GROUP BY COALESCE(status, r'ab')",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "adjacent strings of another value are still a different expression",
sql: "SELECT COALESCE(status, 'a' 'c') AS x FROM orders GROUP BY COALESCE(status, 'ab')",
expected_findings: &[(
"E230",
"Column must be grouped or used in an aggregate function",
16,
)],
},
];
let schema = typed_bigquery_shop_schema();
for test_case in test_cases {
assert_eq!(
bigquery_findings(test_case.sql, &schema),
owned_findings(test_case.expected_findings),
"{}",
test_case.description
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ fn given_bigquery_queries_when_typing_outputs_then_each_has_the_analyzer_type()
sql: "SELECT status || 'x' AS v FROM orders",
expected_type: Some("STRING"),
},
BigqueryTypeTestCase {
description: "adjacent strings are STRING",
sql: "SELECT 'a' 'b' AS v",
expected_type: Some("STRING"),
},
BigqueryTypeTestCase {
description: "COUNT(*) is INT64",
sql: "SELECT COUNT(*) AS v FROM orders",
Expand Down
116 changes: 116 additions & 0 deletions crates/sqlquack-semantics/src/databricks/profile/tests/test_lineage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,50 @@ fn given_a_window_named_after_parentheses_when_checked_then_only_an_undefined_na
}
}

#[test]
fn given_a_typed_literal_of_a_raw_string_when_analysed_then_it_reads_as_the_plain_one() {
let test_cases = [
SameReadingTestCase {
description: "DATE",
sql: "SELECT DATE r'2020-01-01' AS d",
expected_same_as: "SELECT DATE '2020-01-01' AS d",
},
SameReadingTestCase {
description: "TIMESTAMP",
sql: "SELECT TIMESTAMP r'2020-01-01 10:00:00' AS d",
expected_same_as: "SELECT TIMESTAMP '2020-01-01 10:00:00' AS d",
},
SameReadingTestCase {
description: "TIMESTAMP_NTZ",
sql: "SELECT TIMESTAMP_NTZ r'2020-01-01 10:00:00' AS d",
expected_same_as: "SELECT TIMESTAMP_NTZ '2020-01-01 10:00:00' AS d",
},
SameReadingTestCase {
description: "a hexadecimal binary",
sql: "SELECT X r'AB' AS d",
expected_same_as: "SELECT X'AB' AS d",
},
SameReadingTestCase {
description: "an INTERVAL with a unit",
sql: "SELECT INTERVAL r'1' DAY AS d",
expected_same_as: "SELECT INTERVAL '1' DAY AS d",
},
SameReadingTestCase {
description: "an INTERVAL string alone",
sql: "SELECT INTERVAL r'1 day' AS d",
expected_same_as: "SELECT INTERVAL '1 day' AS d",
},
];
for test_case in test_cases {
assert_eq!(
reading(test_case.sql),
reading(test_case.expected_same_as),
"{}",
test_case.description
);
}
}

#[test]
fn given_adjacent_strings_when_analysed_then_they_read_as_the_string_they_join_to() {
let test_cases = [
Expand All @@ -596,3 +640,75 @@ fn given_adjacent_strings_when_analysed_then_they_read_as_the_string_they_join_t
);
}
}

#[test]
fn given_one_string_spelled_two_ways_when_grouping_then_the_expressions_match() {
let test_cases = [
QueryFindingsTestCase {
description: "adjacent strings in the select, one string in GROUP BY",
sql: "SELECT COALESCE(status, 'a' 'b') AS x FROM orders GROUP BY COALESCE(status, 'ab')",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "one string in the select, adjacent strings in GROUP BY",
sql: "SELECT COALESCE(status, 'ab') AS x FROM orders GROUP BY COALESCE(status, 'a' 'b')",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "adjacent strings in a concatenation",
sql: "SELECT status || 'a' 'b' AS x FROM orders GROUP BY status || 'ab'",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "a raw string in the select, a plain one in GROUP BY",
sql: "SELECT COALESCE(status, r'ab') AS x FROM orders GROUP BY COALESCE(status, 'ab')",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "a plain string in the select, a raw one in GROUP BY",
sql: "SELECT COALESCE(status, 'ab') AS x FROM orders GROUP BY COALESCE(status, r'ab')",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "a raw DATE literal in the select, a plain one in GROUP BY",
sql: "SELECT datediff(ordered_at, DATE r'2020-01-01') AS x FROM orders GROUP BY datediff(ordered_at, DATE '2020-01-01')",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "a plain TIMESTAMP literal in the select, a raw one in GROUP BY",
sql: "SELECT COALESCE(ordered_at, TIMESTAMP '2020-01-01 00:00:00') AS x FROM orders GROUP BY COALESCE(ordered_at, TIMESTAMP r'2020-01-01 00:00:00')",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "a raw X literal in the select, a plain one in GROUP BY",
sql: "SELECT COALESCE(CAST(status AS BINARY), X r'AB') AS x FROM orders GROUP BY COALESCE(CAST(status AS BINARY), X'AB')",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "a raw DATE literal of another value is still a different expression",
sql: "SELECT datediff(ordered_at, DATE r'2020-01-02') AS x FROM orders GROUP BY datediff(ordered_at, DATE '2020-01-01')",
expected_findings: &[(
"E230",
"Column must be grouped or used in an aggregate function",
16,
)],
},
QueryFindingsTestCase {
description: "adjacent strings of another value are still a different expression",
sql: "SELECT COALESCE(status, 'a' 'c') AS x FROM orders GROUP BY COALESCE(status, 'ab')",
expected_findings: &[(
"E230",
"Column must be grouped or used in an aggregate function",
16,
)],
},
];
for test_case in test_cases {
assert_eq!(
databricks_findings(test_case.sql),
owned_findings(test_case.expected_findings),
"{}",
test_case.description
);
}
}
Loading
Loading