Expand description
SQL formatting and structural complexity scoring.
Mirrors kumosql.formatting. format_sql lays BigQuery SQL out again from its tokens:
keywords, built-in function names, literals and types take the chosen case, clauses start new
lines, subqueries and blocks are indented, and every comment is kept in order. Formatting only
ever changes whitespace and case: the result is lexed again and compared token for token (and
parsed again and compared tree for tree) before it is returned, and anything that would change
is left as written. Dataform SQLX is never formatted.
complexity scores a query’s structure from its syntax tree with the same weights and bands
as the reference.
Structs§
- Complexity
- A structural complexity score with its breakdown.
- Complexity
Metrics - The counts a complexity score is made of.
- Format
Diagnostic - A note about one formatting run (
lineis -1 for the whole text). - Format
Outcome - What
format_with_diagnosticsdid. - Format
Preferences - Formatting preferences (the reference’s sqlfluff settings).
- Format
Rule - One formatting rule this formatter applies.
- Pipeline
Complexity - The complexity of a pipeline of tables.
Enums§
- Comma
Position - Where a list’s commas go.
- Complexity
Band - How complex a score is:
< 10low,< 25moderate,< 50high, otherwise very high. - Indent
Unit - Indentation with spaces or tabs.
- Keyword
Case - The case keywords, function names, literals and types take.
Functions§
- complexity
- Score a query’s structural complexity: a weighted sum of joins (comma joins included), CTEs,
subqueries, set operations, CASE expressions (
IFincluded), window functions, AND/OR predicates and maximum SELECT nesting. Bands:< 10low,< 25moderate,< 50high, otherwise very high. SQL that does not parse, and Dataform SQLX, are errors. - format_
rules - Every rule this formatter applies, with its code, name and groups.
- format_
sql - Format BigQuery SQL. Text with no statement that parses, and Dataform SQLX, are errors.
- format_
statements - Format
sqland return it with the number of statements left as written (ones that do not parse). - format_
with_ diagnostics - Format like the reference’s
format_sqlrule: never fails, explains what it left alone. - parse_
preferences - Validate JSON-shaped preferences; missing keys keep their defaults.
- pipeline_
complexity complexitysummed over a pipeline’s queries, plus one per table so a pass-through table counts.