Repository navigation
fix(rules): report custom rule node findings at model file positions - #1546
Merged
Merged
Conversation
…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
disabled auto-merge
November 17, 2026 10:36
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-lineMODELheader or a multi-line macro expansion moved the finding to the wrong line.Changes
SqlDocumentof a model carries where its query sits in the model file, built the same way built-in model rules map positions.findingmaps a node through it when no explicit line or column is given, and a node inside macro output points at the macro call.sql.for_modelfact, so cached findings match cold ones.node=nodein the example and say where node findings point.Verification
make check-ci.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.