Skip to content

fix(rules): report custom rule node findings at model file positions - #1546

Merged
chio-labs-delivery[bot] merged 9 commits into
mainfrom
fix/custom-rule-node-positions
Nov 17, 2026
Merged

chio-labs-delivery[bot] merged 9 commits into
mainfrom
fix/custom-rule-node-positions

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Why

A custom rule that reports ctx.finding(subject=model, node=node) got the node's line and column in the model's expanded query, reported as if they were model-file positions. A multi-line MODEL header or a multi-line macro expansion moved the finding to the wrong line.

Changes

  • The expanded SqlDocument of a model carries where its query sits in the model file, built the same way built-in model rules map positions. finding maps a node through it when no explicit line or column is given, and a node inside macro output points at the macro call.
  • The place travels in the custom-rule host payload and in the replayed sql.for_model fact, so cached findings match cold ones.
  • A document maps all its node starts once, on the first node finding, so reporting every column of a wide model stays linear.
  • The place travels as the authored query's byte range in the model file plus the expansion passes, and offsets are derived only when a rule reports a node. A first version repeated the authored query text in every model's payload (21 MB of a 123 MB payload on 3,000 models), which raised custom-rule CPU.
  • A node whose position is not an integer keeps the previous fallback.
  • The rule-context docs restore node=node in the example and say where node findings point.

Verification

  • New E2E test fails on the unchanged code: a multi-line header and a macro case, each compiled cold and warm.
  • Unit tests: 20,000 column findings under a 2 s limit (the old per-finding path extrapolates to about 11 s), and integer-only placement.
  • Rules unit, integration and E2E suites, DuckShop rule tests, fensu, dupes, clippy, make check-ci.
  • Same machine, dense 3,000 models, 6 alternating cold runs, median custom_rules_cpu_ms: main 758, first version 913 (1.21x; 1.41x in CI), this head 773 (1.02x). Compile JSON identical to the first version.

DuckShop: the quoted-alias rule reports at its node again, and its test asserts the model-file line and column.

…extents

Rules can read a node's name, quoting and qualifier, a literal's value and
type, and where a node ends (end_line, end_column and a character span into
the document source). A relation marker reads as the call it stands for, and
offsets map back through marker names and Snowflake TABLE( ) wrappers to the
text as written. Nodes the parser records no span for have no end.
ctx.finding(node=...) takes a node's query-relative position, so the docs
example and the DuckShop rule report at the model and quote the node's
authored text in the message instead.
…l file

ctx.finding(subject=model, node=...) took the node's line and column in the
model's expanded query and reported them against the model file, so a
multi-line MODEL header or a multi-line macro expansion moved the finding.
The expanded SQL document now carries where the query sits in the file, read
the way built-in model rules map positions, and the finding maps the node
through it; a node inside macro output points at the macro call. The query
place travels in the custom host payload and in the replayed sql.for_model
fact, so cached findings follow it.
Each node finding rebuilt the model query's character and line tables, so
reporting every column of a wide model took time proportional to findings
times model size. A document now maps all its syntax tree node starts into
the model file once, on the first node finding, and later findings look
their node up. A node whose line or column is not an integer gets no file
position again and falls back to its own line and column.
@kvlonge
kvlonge disabled auto-merge November 17, 2026 10:36
@kvlonge
kvlonge added this pull request to the merge queue Nov 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 17, 2026
…ansion passes

The place of a model's expanded query repeated the authored query text in
every model's custom-rule payload, about a sixth of the payload on a dense
3,000-model project. It now names the query by its byte range in the model
file, which the rule's SQL document already holds, and offsets are derived
only when a rule reports a node.
@chio-labs-delivery
chio-labs-delivery Bot added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 48e4132 Nov 17, 2026
35 checks passed
@chio-labs-delivery
chio-labs-delivery Bot deleted the fix/custom-rule-node-positions branch November 17, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant