Skip to content

feat(rules): give syntax tree nodes names, literal values and source extents - #1544

Merged
chio-labs-delivery[bot] merged 5 commits into
mainfrom
feat/rule-ast-node-facts
Nov 17, 2026
Merged

chio-labs-delivery[bot] merged 5 commits into
mainfrom
feat/rule-ast-node-facts

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Why

Custom Rules could walk the syntax tree but saw only each node's kind and start. A rule that checks names, literal values or an expression's text had to re-parse the SQL.

Changes

  • SqlTreeNode gains name, quoted, qualifier (identifiers, columns, aliases, tables, CTEs), value and literal_type (literals), and end_line, end_column and span (character offsets into source, end exclusive).
  • Ends come only from spans the parser records; a node without one has no end. Literals have no span.
  • A relation marker reads as its call as written, such as __ref("orders"), even over several lines. Offsets map back through marker names and Snowflake TABLE( ) wrappers.
  • Table nodes now start at their own name instead of their parent's start, and Snowflake table-function nodes no longer start inside the inserted TABLE( text.
  • Function names and operator text stay out of scope. Names of more than three parts keep the parser's joined catalog; no supported dialect accepts them.
  • Docs: the rule context page gains a syntax tree example and attribute table; the docs skill is regenerated.

Verification

  • Rust sql_tree cases prove names, literals and offsets for DuckDB, PostgreSQL, a three-line marker, a Snowflake table function inside TABLE( ), and a CTE with non-ASCII text.
  • E2E: a Snowflake custom rule reads names, values and spans through sqb compile.
  • Rule position, hermeticity, cache invalidation and SqlDocument tests pass.
  • Same machine, base vs head, cold compiles: dense 3,000 models (5 alternating runs) wall 1.037x, CPU 1.001x; DuckShop with a rule walking every model's tree (5 runs) wall 0.980x, CPU 0.985x, identical diagnostics.
  • make check-ci passed on the final head.

DuckShop: adds XSQBRDUCK003 (quoted mixed-case column names only in _export models) with rule tests; it reports nothing on the current project.

…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.
@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 b318adc Nov 17, 2026
34 checks passed
@chio-labs-delivery
chio-labs-delivery Bot deleted the feat/rule-ast-node-facts branch November 17, 2026 10:08
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