Expand description
Dataform SQLX handling shared by every reader and rewrite.
Mirrors kumo_sql_prover.sqlx and sqlx_fragments. A SQLX file splits into config, js,
pre_operations, post_operations and input "name" blocks (kept byte for byte) and SQL
sections. ${...} interpolations in SQL are masked with SQL-safe sentinels for parsing and
restored afterwards; a restore that finds a sentinel lost or duplicated fails rather than
producing different SQL.
Dataform leaves a ${...} inside a -- or /* */ comment as text, so those are never masked
or read as references. A # comment is not one of them: @dataform/cli 3.0.71 evaluates
${ref(...)} after #.
Structs§
- Masked
Sqlx - SQL with its interpolations replaced by sentinels.
- RefCall
- One
ref(...),resolve(...),self()orwhen(...)call in a masked interpolation. - RefTarget
- A literal
ref/resolvetarget. - Sqlx
Assertions - The
assertions: {...}block. - Sqlx
BigQuery - The
bigquery: {...}block (and its top-level spellings). - Sqlx
Column - Documentation of one column (
columns: {a: "text"}or{a: {description, columns, bigqueryPolicyTags}}). - Sqlx
Config - What a config block says, read without running it.
- Sqlx
Restoration - How to put one interpolation back.
- Sqlx
Section - One section with its exact text and where it sits in the file.
Enums§
- RefFunction
- A Dataform function called in an interpolation.
- Sqlx
Dependency - A dependency named in
dependencies: [...]. - Sqlx
Section Kind - What a section of a SQLX file is.
Constants§
- LOADER_
TOKEN_ REASON - Refused: the text holds a positional sentinel, which means different things in different models.
- STRING_
REASON - Refused: a string literal holds a masked expression, so its value is unknown.
Functions§
- content_
sentinel - The content-derived sentinel for an interpolation:
__sqlx_<16 hex of sha256>__. - decode_
sqlx_ bytes - File text from bytes: UTF-8 with any byte-order mark dropped (it would hide a leading config block), else Windows-1252.
- defuse_
comment_ templates sqlwith each${inside a--or/* */comment written$ {, so it is never read as an interpolation (Dataform does not evaluate it).- dynamic_
sentinels - Content sentinels of every interpolation in
sqlthat is not a relation reference. - is_
relation_ reference - Whether a
${...}always expands to exactly one table or view name:self(), or oneref(...)/resolve(...)call whose closing parenthesis ends the expression, with no template literal, comment,/or backslash in its arguments. - is_
table_ reference ${ref("t")},${ref("dataset", "t")},${resolve("t")}or${self()}: one table name once compiled.- looks_
like_ sqlx - Whether
textlooks like Dataform SQLX: it has a block (config {,js {, …) at the start of a line, or a${anywhere. - mask_
sqlx - Replace every
${...}outside--//* */comments with a SQL-safe sentinel and record how to restore it. An interpolation that opens or continues a condition (${when(incremental(), "WHERE x > 1")}) is masked with the clause keyword beside it so the masked text still parses. - mask_
sqlx_ by_ content - Mask with sentinels derived from each interpolation’s text, so the same interpolation has the same sentinel wherever a rewrite moves it.
- masked_
template_ problem - Why a prover must not read these masked texts as they are, or
None. - outside_
sql_ comments - The matches of
patterninsqlthat do not start inside a--or/* */comment. - parse_
sqlx_ config - Read a
config { ... }block (or just its{ ... }) without running it. An empty block,tags: [], trailing commas, unquoted keys, single-quoted strings and//comments are fine; computed values are listed inSqlxConfig::computed. - restore_
sqlx - Put the interpolations back into
rewritten(a rewrite ofmasked.masked). Fails when a sentinel was lost or duplicated, or separated from the connective it stands with. - restore_
sqlx_ interpolations restore_sqlxfrom the restorations alone.- split_
sqlx_ sections - Split SQLX into SQL sections and blocks, in order. The result always ends with a SQL section (possibly empty), and joining the texts gives back the input.
- sql_
comment_ spans (start, end)of every--and/* */comment in SQL.- with_
preserved_ whitespace transformedwithoriginal’s leading and trailing whitespace.