Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
05a3501
fix(databricks): keep raw strings in path keys and resources
kvlonge Nov 18, 2026
ae39a85
fix(databricks): keep a returned table's columns apart from their spa…
kvlonge Nov 18, 2026
eb46430
fix(semantics): find a named window in any case where names fold
kvlonge Nov 18, 2026
6beb329
fix(semantics): report an unknown base of a window an OVER reads
kvlonge Nov 18, 2026
14e9785
fix(syntax): keep a window name's quotes in OVER and WINDOW
kvlonge Nov 18, 2026
0e00482
fix(semantics): check a named window's frame offsets as column refere…
kvlonge Nov 18, 2026
88640e7
fix(semantics): hide a projection's own alias from the named window i…
kvlonge Nov 18, 2026
099b4da
fix(semantics): keep SQLite and BigQuery window keys from reading out…
kvlonge Nov 18, 2026
32d890e
fix(sqlite): a projection cannot read another projection's alias
kvlonge Nov 18, 2026
b7349a2
fix(duckdb): a NATURAL join of sides sharing no column is an error
kvlonge Nov 18, 2026
67f9861
fix(semantics): a merged join key is ambiguous beside another item's …
kvlonge Nov 18, 2026
a80c80c
fix(semantics): a join condition reads only the items its engine lets…
kvlonge Nov 19, 2026
1556ff6
perf(semantics): normalise a single-spaced ASCII type spelling in one…
kvlonge Nov 19, 2026
b17c324
perf(semantics): upper-case a Snowflake identifier in place
kvlonge Nov 19, 2026
0276edf
perf(semantics): order findings without a position map when none need…
kvlonge Nov 19, 2026
4a81f84
perf(semantics): read the family of a bare type word without allocating
kvlonge Nov 19, 2026
6253870
perf(semantics): walk a node's children without collecting them first
kvlonge Nov 19, 2026
da98aa5
perf(semantics): hash scope-rule names with FxHash
kvlonge Nov 19, 2026
f5f1503
perf(semantics): collect a SELECT's scope once for its structure rules
kvlonge Nov 19, 2026
b4d5106
perf(semantics): look an aggregate's name up in a set
kvlonge Nov 19, 2026
0ba833c
perf(semantics): append a node's findings instead of extending with them
kvlonge Nov 19, 2026
747ec27
perf(semantics): append a level's findings instead of extending with …
kvlonge Nov 19, 2026
150a37d
docs: complete the 0.22.0 lint breaking-change entry
kvlonge Nov 19, 2026
56952db
perf(semantics): record the lower analysis instruction count
kvlonge Nov 19, 2026
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

### ⚠ BREAKING CHANGES

* **lint:** lint now refuses a Postgres, BigQuery or Databricks statement whose tree nests past 512 levels, as Snowflake, DuckDB and SQLite already did, so 600 UNION ALL operands or 600
* **lint:** lint now refuses a Postgres, BigQuery or Databricks statement whose tree nests past 512 levels, as Snowflake, DuckDB and SQLite already did, so 600 UNION ALL operands or 600 `::` casts no longer lint in those dialects.
* keep each comma item's joins with it in Postgres, Databricks, DuckDB and SQL Server
* **bigquery:** sqlquack-syntax adds Literal::RawByteString and Literal::JoinedBytes, and GrantPrincipal gains a written field, so an exhaustive match on Literal or a GrantPrincipal struct literal no longer compiles.

Expand Down
4 changes: 2 additions & 2 deletions coverage/instruction-counts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ rustc = "rustc 1.99.1 (58cf8f9c3 2026-10-13)"
tolerance_percent = 2

[counts]
analysis = 239698431
parse = 253081114
analysis = 182168067
parse = 252986430
18 changes: 17 additions & 1 deletion crates/sqlquack-semantics/src/bigquery/profile/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::bigquery::profile::_helpers::typing::{
use crate::bigquery::profile::constants::{BIGQUERY_DATE_PART_FUNCTIONS, BIGQUERY_WEEKDAY_PARTS};
use crate::dialects::types::DialectProfile;
use crate::lineage::constants::SNOWFLAKE_VALUES_COLUMN;
use crate::lineage::models::Engine;
use crate::lineage::models::{Engine, JoinConditionReach};
use crate::lineage::models::{Lineage, LineageContext, TransformKind};
use crate::lineage::types::DialectRules;
use crate::lineage::types::ValueType;
Expand Down Expand Up @@ -58,6 +58,22 @@ impl DialectRules for BigQueryRules {
false
}

fn window_keys_read_outputs(&self) -> bool {
false
}

fn select_list_reads_outputs(&self) -> bool {
true
}

fn merged_keys_hide_other_items(&self) -> bool {
true
}

fn join_conditions_read(&self) -> JoinConditionReach {
JoinConditionReach::Every
}

fn checks_call_signatures(&self) -> bool {
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ use crate::lineage::tests::test_types::QueryFindingsTestCase;
#[test]
fn given_a_bigquery_query_when_checking_it_then_findings_follow_googlesql() {
let test_cases = [
QueryFindingsTestCase {
description: "an inline window ordered by another output's alias",
sql: "SELECT quantity AS q, sum(quantity) OVER (ORDER BY q) AS x FROM orders",
expected_findings: &[("E201", "Unknown column 'q' in table 'orders'", 51)],
},
QueryFindingsTestCase {
description: "a TIMESTAMP_TRUNC date part is not a column (analyzer: accepted)",
sql: "SELECT TIMESTAMP_TRUNC(ordered_at, DAY) AS v FROM orders",
Expand Down
18 changes: 17 additions & 1 deletion crates/sqlquack-semantics/src/clickhouse/profile/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::lineage::constants::{
DATE_PART_FUNCTIONS, SNOWFLAKE_VALUES_COLUMN, WINDOW_ONLY_FUNCTIONS,
};
use crate::lineage::main::rendered_type::rendered_type;
use crate::lineage::models::Engine;
use crate::lineage::models::{Engine, JoinConditionReach};
use crate::lineage::models::{Lineage, LineageContext};
use crate::lineage::types::DialectRules;
use crate::lineage::types::ValueType;
Expand Down Expand Up @@ -73,6 +73,22 @@ impl DialectRules for ClickHouseRules {
false
}

fn window_keys_read_outputs(&self) -> bool {
true
}

fn select_list_reads_outputs(&self) -> bool {
true
}

fn merged_keys_hide_other_items(&self) -> bool {
true
}

fn join_conditions_read(&self) -> JoinConditionReach {
JoinConditionReach::Every
}

fn checks_call_signatures(&self) -> bool {
true
}
Expand Down
18 changes: 17 additions & 1 deletion crates/sqlquack-semantics/src/databricks/profile/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::databricks::profile::_helpers::typing::{
use crate::databricks::profile::constants::DATABRICKS_VALUES_COLUMN;
use crate::dialects::types::DialectProfile;
use crate::lineage::constants::DATE_PART_FUNCTIONS;
use crate::lineage::models::Engine;
use crate::lineage::models::{Engine, JoinConditionReach};
use crate::lineage::models::{Lineage, LineageContext};
use crate::lineage::types::DialectRules;
use crate::lineage::types::ValueType;
Expand Down Expand Up @@ -63,6 +63,22 @@ impl DialectRules for DatabricksRules {
false
}

fn window_keys_read_outputs(&self) -> bool {
true
}

fn select_list_reads_outputs(&self) -> bool {
true
}

fn merged_keys_hide_other_items(&self) -> bool {
true
}

fn join_conditions_read(&self) -> JoinConditionReach {
JoinConditionReach::Every
}

fn checks_call_signatures(&self) -> bool {
true
}
Expand Down
18 changes: 17 additions & 1 deletion crates/sqlquack-semantics/src/duckdb/profile/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::duckdb::profile::constants::{
DUCKDB_VALUES_COLUMN,
};
use crate::lineage::constants::{DATE_PART_FUNCTIONS, WINDOW_ONLY_FUNCTIONS};
use crate::lineage::models::Engine;
use crate::lineage::models::{Engine, JoinConditionReach};
use crate::lineage::models::{Lineage, LineageContext};
use crate::lineage::types::DialectRules;
use crate::lineage::types::ValueType;
Expand Down Expand Up @@ -64,6 +64,22 @@ impl DialectRules for DuckDbRules {
false
}

fn window_keys_read_outputs(&self) -> bool {
true
}

fn select_list_reads_outputs(&self) -> bool {
true
}

fn merged_keys_hide_other_items(&self) -> bool {
true
}

fn join_conditions_read(&self) -> JoinConditionReach {
JoinConditionReach::Earlier
}

fn checks_call_signatures(&self) -> bool {
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,60 @@ fn given_named_windows_when_resolving_names_then_only_the_windows_an_over_reads_
sql: "SELECT sum(amount) OVER w AS x FROM orders WINDOW w AS (ORDER BY nope)",
expected_findings: &[("E201", "Unknown column 'nope' in table 'orders'", 65)],
},
QueryFindingsTestCase {
description: "a window named in another case, which DuckDB resolves to it",
sql: "SELECT sum(amount) OVER W AS x FROM orders WINDOW w AS (PARTITION BY nope)",
expected_findings: &[("E201", "Unknown column 'nope' in table 'orders'", 69)],
},
QueryFindingsTestCase {
description: "a used window extending an unknown window",
sql: "SELECT sum(amount) OVER w2 AS x FROM orders WINDOW w AS (ORDER BY id), w2 AS (zz ORDER BY id)",
expected_findings: &[("E232", "Unknown named window 'zz'", 78)],
},
QueryFindingsTestCase {
description: "an unknown window two steps along the used window's chain",
sql: "SELECT sum(amount) OVER w3 AS x FROM orders WINDOW w2 AS (zz ORDER BY id), w3 AS (w2)",
expected_findings: &[("E232", "Unknown named window 'zz'", 58)],
},
QueryFindingsTestCase {
description: "an unused window extending an unknown window",
sql: "SELECT amount FROM orders WINDOW w2 AS (zz ORDER BY id)",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "an unknown column in a used window's frame offset",
sql: "SELECT sum(amount) OVER w AS x FROM orders WINDOW w AS (ORDER BY id ROWS BETWEEN nope PRECEDING AND CURRENT ROW)",
expected_findings: &[("E201", "Unknown column 'nope' in table 'orders'", 81)],
},
QueryFindingsTestCase {
description: "the same offset written inline",
sql: "SELECT sum(amount) OVER (ORDER BY id ROWS BETWEEN nope PRECEDING AND CURRENT ROW) AS x FROM orders",
expected_findings: &[("E201", "Unknown column 'nope' in table 'orders'", 50)],
},
QueryFindingsTestCase {
description: "an unknown qualifier in a used window's end offset",
sql: "SELECT sum(amount) OVER w AS x FROM orders WINDOW w AS (ORDER BY id ROWS BETWEEN 1 PRECEDING AND zz.id FOLLOWING)",
expected_findings: &[(
"E222",
"Unknown table or alias 'zz' referenced by column 'id'",
97,
)],
},
QueryFindingsTestCase {
description: "a used window ordered by its own projection's alias, as inline (2.0: Binder Error)",
sql: "SELECT sum(amount) OVER w AS x FROM orders WINDOW w AS (ORDER BY x)",
expected_findings: &[("E201", "Unknown column 'x' in table 'orders'", 65)],
},
QueryFindingsTestCase {
description: "a window shared by two projections, ordered by one's alias",
sql: "SELECT sum(amount) OVER w AS x, avg(amount) OVER w AS y FROM orders WINDOW w AS (ORDER BY y)",
expected_findings: &[("E201", "Unknown column 'y' in table 'orders'", 90)],
},
QueryFindingsTestCase {
description: "an unknown column in a window shared by two projections is reported once",
sql: "SELECT sum(amount) OVER w AS x, avg(amount) OVER w AS y FROM orders WINDOW w AS (ORDER BY nope)",
expected_findings: &[("E201", "Unknown column 'nope' in table 'orders'", 90)],
},
QueryFindingsTestCase {
description: "a window that the used window extends",
sql: "SELECT sum(amount) OVER w2 AS x FROM orders WINDOW w AS (PARTITION BY nope), w2 AS (w ORDER BY id)",
Expand Down Expand Up @@ -716,6 +770,58 @@ fn given_a_comma_after_a_joined_item_when_resolving_names_then_the_join_reads_on
sql: "SELECT * FROM orders a JOIN orders b USING (status), customers c",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "an ON condition reading a USING key only a later join merges (2.0: column not found)",
sql: "SELECT 1 FROM exports a JOIN exports b ON id IS NOT NULL JOIN orders c ON true JOIN customers d USING (id)",
expected_findings: &[(
"E201",
"Unknown column 'id' (not found in any referenced table)",
42,
)],
},
QueryFindingsTestCase {
description: "an ON condition reading a key a later join widens, beside an item offering the name (2.0: accepted)",
sql: "SELECT 1 FROM orders x JOIN (orders a JOIN customers b USING (id)) ON true JOIN exports c ON id IS NOT NULL JOIN customers d USING (id)",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "an ON condition reading a USING key a later join merges again (2.0: accepted)",
sql: "SELECT 1 FROM orders a JOIN customers b USING (id) JOIN exports c ON id IS NOT NULL JOIN customers d USING (id)",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "an ON condition reading a later comma group's item (2.0: table not found)",
sql: "SELECT 1 FROM orders a JOIN customers c ON b.id = c.id, customers b",
expected_findings: &[(
"E222",
"Unknown table or alias 'b' referenced by column 'id'",
43,
)],
},
QueryFindingsTestCase {
description: "an ON condition reading a later item of its own join chain (2.0: table not found)",
sql: "SELECT 1 FROM orders a JOIN customers b ON c.id = a.id JOIN customers c ON true",
expected_findings: &[(
"E222",
"Unknown table or alias 'c' referenced by column 'id'",
43,
)],
},
QueryFindingsTestCase {
description: "an ON condition reading an earlier comma group's item (2.0: accepted)",
sql: "SELECT 1 FROM orders a, customers b JOIN customers c ON a.id = c.id",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "an ON condition reading an earlier comma group's column (2.0: accepted)",
sql: "SELECT 1 FROM orders a, customers b JOIN customers c ON customer_id = c.id",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "a parenthesised join's ON condition reading an earlier comma item (2.0: accepted)",
sql: "SELECT 1 FROM orders a, (customers b JOIN customers c ON a.id = c.id)",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "an unqualified USING key beside a later item's column of its name, which DuckDB binds",
sql: "SELECT id FROM orders a JOIN customers b USING (id), exports c CROSS JOIN customers d",
Expand All @@ -732,6 +838,55 @@ fn given_a_comma_after_a_joined_item_when_resolving_names_then_the_join_reads_on
}
}

#[test]
fn given_a_natural_join_when_resolving_names_then_sides_sharing_no_column_are_refused() {
let test_cases = [
QueryFindingsTestCase {
description: "a NATURAL join of tables sharing no column (2.0: no columns found to join on)",
sql: "SELECT * FROM orders NATURAL JOIN shop.products",
expected_findings: &[("E201", "NATURAL JOIN has no column both sides offer", 39)],
},
QueryFindingsTestCase {
description: "a NATURAL LEFT join sharing no column",
sql: "SELECT * FROM customers NATURAL LEFT JOIN exports",
expected_findings: &[("E201", "NATURAL JOIN has no column both sides offer", 42)],
},
QueryFindingsTestCase {
description: "a NATURAL join whose comma neighbour, not its left item, shares a column",
sql: "SELECT * FROM customers c, shop.products p NATURAL JOIN orders o",
expected_findings: &[("E201", "NATURAL JOIN has no column both sides offer", 56)],
},
QueryFindingsTestCase {
description: "a NATURAL join of a derived table sharing no column",
sql: "SELECT * FROM orders NATURAL JOIN (SELECT 1 AS z) s",
expected_findings: &[("E201", "NATURAL JOIN has no column both sides offer", 34)],
},
QueryFindingsTestCase {
description: "a second NATURAL join whose right shares no column with the joined left",
sql: "SELECT * FROM orders o NATURAL JOIN customers c NATURAL JOIN exports e",
expected_findings: &[("E201", "NATURAL JOIN has no column both sides offer", 61)],
},
QueryFindingsTestCase {
description: "a NATURAL join of tables sharing a column",
sql: "SELECT * FROM orders NATURAL JOIN customers",
expected_findings: &[],
},
QueryFindingsTestCase {
description: "a NATURAL join sharing a column spelled in another case",
sql: "SELECT * FROM orders NATURAL JOIN (SELECT 1 AS ID) s",
expected_findings: &[],
},
];
for test_case in test_cases {
assert_eq!(
duckdb_parser_findings(test_case.sql),
owned_findings(test_case.expected_findings),
"{}",
test_case.description
);
}
}

#[test]
fn given_joined_and_comma_items_when_expanding_a_star_then_the_columns_follow_the_written_order() {
let test_cases = [
Expand Down
39 changes: 39 additions & 0 deletions crates/sqlquack-semantics/src/lineage/_helpers/checks/families.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use crate::lineage::models::{LineageContext, LineageScope};
/// The scale of a fixed-point type that holds only integers.
const INTEGER_SCALE: &str = "0";

/// The longest bare type word `word_family` lowers on the stack.
const WORD_CAPACITY: usize = 32;

pub(crate) fn type_arguments(normalized: &str) -> Option<(&str, &str)> {
let open: usize = normalized.find('(')?;
if !normalized.ends_with(')') || open + 1 >= normalized.len() {
Expand All @@ -25,6 +28,26 @@ pub(crate) fn type_arguments(normalized: &str) -> Option<(&str, &str)> {
))
}

/// The family of a bare type word such as `BIGINT`, lowered without allocating, else `None`.
pub(crate) fn word_family(spelling: &str) -> Option<Family> {
let bytes: &[u8] = spelling.as_bytes();
if bytes.is_empty()
|| bytes.len() > WORD_CAPACITY
|| !bytes
.iter()
.all(|byte| byte.is_ascii_alphanumeric() || *byte == b'_')
{
return None;
}
let mut lowered: [u8; WORD_CAPACITY] = [0; WORD_CAPACITY];
for (slot, byte) in lowered.iter_mut().zip(bytes) {
*slot = byte.to_ascii_lowercase();
}
Some(base_family(&String::from_utf8_lossy(
&lowered[..bytes.len()],
)))
}

fn base_family(base: &str) -> Family {
match base {
"bool" | "boolean" => Family::Boolean,
Expand Down Expand Up @@ -270,13 +293,29 @@ pub(crate) fn normalized_spelling(spelling: &str) -> String {
let trimmed: &str = spelling
.trim()
.trim_matches(|character| matches!(character, '"' | '\'' | '`'));
if is_single_spaced_ascii(trimmed) {
let mut lowered: String = trimmed.to_owned();
lowered.make_ascii_lowercase();
return lowered;
}
trimmed
.split_whitespace()
.collect::<Vec<&str>>()
.join(" ")
.to_lowercase()
}

/// Whether `text` is printable ASCII with single spaces between words and none around them.
fn is_single_spaced_ascii(text: &str) -> bool {
let bytes: &[u8] = text.as_bytes();
bytes.first() != Some(&b' ')
&& bytes.last() != Some(&b' ')
&& !text.contains(" ")
&& bytes
.iter()
.all(|byte| *byte == b' ' || byte.is_ascii_graphic())
}

/// The family of an array, map or struct spelling, or of a decimal that holds only integers.
pub(crate) fn composite_family(normalized: &str) -> Option<Family> {
if let Some((base, inner)) = type_arguments(normalized) {
Expand Down
Loading
Loading