Repository navigation
feat(rules): repeated JSON parse rule and allow_exceptions setting - #936
Merged
Merged
Conversation
SQBRSQL045 reports the same JSON parse function applied to the same column more than once in one SELECT scope, at the second call, and names the count, for example `TRY_PARSE_JSON(e.value) is parsed 3 times in one SELECT`. Parse the payload once in the CTE that reads it and read every field from that column. Each SELECT is its own scope; nested SELECTs, subqueries, CTE bodies and set-operation branches are checked separately. Calls are keyed by function, table qualifier and column (case-insensitive) through parentheses, LOWER, UPPER, TRIM, CAST, TRY_CAST and the first COALESCE argument. Parse functions: Snowflake and Databricks PARSE_JSON and TRY_PARSE_JSON, BigQuery PARSE_JSON and SAFE.PARSE_JSON, DuckDB and MotherDuck JSON. PostgreSQL and SQL Server have no single-argument equivalent. The check is native and walks each body once. Refs CHI-488.
With `[rules] allow_exceptions = false` (default true), any [[rules.rule_exceptions]] or [[rules.rule_ignores]] entry fails rules configuration loading, so compile and rules run stop with an error that counts the entries, states the current value and shows the exact TOML to allow them again. Each inline `-- sqb: ignore` directive becomes a SQBRSQL000 error at the directive and suppresses nothing, so the hidden finding is reported too. The project-wide `ignore` list stays allowed. Document inline suppressions and the new setting in the Rules and project configuration references. Refs CHI-489.
kvlonge
enabled auto-merge (squash)
October 4, 2026 10:03
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
Projects enforce two common policies with custom rules: "parse each JSON payload once per SELECT" and "no rule exceptions or scoped ignores". The first is costly in Python (it walks every model's syntax tree) and is generally useful; the second needs a regex over the project config. Both belong in SQLBuild (CHI-488, CHI-489).
Changes
PARSE_JSON/TRY_PARSE_JSON, BigQueryPARSE_JSON/SAFE.PARSE_JSON, DuckDBjson()). Names compare the way each warehouse resolves them; multi-argument wrappers aren't plain columns. Not in the default lint set.[rules] allow_exceptions(defaulttrue). Whenfalse,[[rules.rule_exceptions]]/[[rules.rule_ignores]]are config errors and inline-- sqb: ignoredirectives become SQBRSQL000 errors that suppress nothing. The project-wideignorelist stays allowed. Help shows the exact TOML and current value;sqb formatuses the same loader.Verification
rules runand format.make test,make check-ci.