Repository navigation
feat(rules): give syntax tree nodes names, literal values and source extents - #1544
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.
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
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
SqlTreeNodegainsname,quoted,qualifier(identifiers, columns, aliases, tables, CTEs),valueandliteral_type(literals), andend_line,end_columnandspan(character offsets intosource, end exclusive).__ref("orders"), even over several lines. Offsets map back through marker names and SnowflakeTABLE( )wrappers.TABLE(text.Verification
sql_treecases prove names, literals and offsets for DuckDB, PostgreSQL, a three-line marker, a Snowflake table function insideTABLE( ), and a CTE with non-ASCII text.sqb compile.SqlDocumenttests pass.make check-cipassed on the final head.DuckShop: adds
XSQBRDUCK003(quoted mixed-case column names only in_exportmodels) with rule tests; it reports nothing on the current project.