Skip to content

Commit 38e0788

Browse files
committed
test(semantics): check a named window after a parenthesized query by its findings
The case for an unknown column in such a window compared two empty finding lists, because named window specs are not checked for unknown columns in any form. The test now shows what the change does: the window function inside the parentheses finds the window named after them, and a name no WINDOW clause defines is still unknown.
1 parent d62efa3 commit 38e0788

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

‎crates/sqlquack-semantics/src/databricks/profile/tests/test_lineage.rs‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,6 @@ fn given_a_parenthesized_query_with_clauses_after_it_when_analysed_then_they_rea
468468
sql: "( SELECT sum ( quantity ) OVER w AS x FROM orders LIMIT 1 ) WINDOW w AS ( ORDER BY quantity )",
469469
expected_same_as: "SELECT sum ( quantity ) OVER w AS x FROM orders WINDOW w AS ( ORDER BY quantity ) LIMIT 1",
470470
},
471-
SameReadingTestCase {
472-
description: "an unknown column in a named window written after the parentheses",
473-
sql: "( SELECT sum ( quantity ) OVER w AS x FROM orders LIMIT 1 ) WINDOW w AS ( ORDER BY nope )",
474-
expected_same_as: "SELECT sum ( quantity ) OVER w AS x FROM orders WINDOW w AS ( ORDER BY nope ) LIMIT 1",
475-
},
476471
SameReadingTestCase {
477472
description: "ORDER BY a column the query does not output",
478473
sql: "( SELECT id FROM orders ) ORDER BY quantity",
@@ -554,6 +549,30 @@ fn given_a_parenthesized_query_with_clauses_after_it_when_analysed_then_they_rea
554549
}
555550
}
556551

552+
#[test]
553+
fn given_a_window_named_after_parentheses_when_checked_then_only_an_undefined_name_is_found() {
554+
let test_cases = [
555+
QueryFindingsTestCase {
556+
description: "the window function inside reads the window named after the parentheses",
557+
sql: "( SELECT sum ( quantity ) OVER w AS x FROM orders LIMIT 1 ) WINDOW w AS ( ORDER BY quantity )",
558+
expected_findings: &[],
559+
},
560+
QueryFindingsTestCase {
561+
description: "a window no WINDOW clause names is still unknown",
562+
sql: "( SELECT sum ( quantity ) OVER w2 AS x FROM orders LIMIT 1 ) WINDOW w AS ( ORDER BY quantity )",
563+
expected_findings: &[("E232", "Unknown named window 'w2'", 15)],
564+
},
565+
];
566+
for test_case in test_cases {
567+
assert_eq!(
568+
databricks_findings(test_case.sql),
569+
owned_findings(test_case.expected_findings),
570+
"{}",
571+
test_case.description
572+
);
573+
}
574+
}
575+
557576
#[test]
558577
fn given_adjacent_strings_when_analysed_then_they_read_as_the_string_they_join_to() {
559578
let test_cases = [

0 commit comments

Comments
 (0)