yggdrasil.execution.expr.backends.sql¶
sql ¶
SQL emitter with dialect flavors + hand-rolled lifter.
:func:to_sql walks the AST and produces a SQL string for the
named dialect. Identifier quoting, string-literal escaping, and a
handful of dialect-specific keywords (ILIKE, TIMESTAMP
literals) come from :class:Dialect.
:func:from_sql parses a SQL predicate string back into our AST
via the in-module tokenizer + recursive-descent parser below —
no third-party SQL parser dependency. The grammar covers the
predicate-language subset every yggdrasil backend needs:
comparisons, AND / OR / NOT, IN, BETWEEN,
LIKE / ILIKE, IS [NOT] NULL, CAST, typed temporal
literals (TIMESTAMP '…' / DATE '…'), function-call
temporal coercions (TIMESTAMP('…') / DATE('…')), and the
+/-/*///% arithmetic operators between
columns and literals. Anything outside that surface raises a
ValueError pointing at the offending token.
to_sql ¶
Emit expr as a SQL string in the chosen dialect.
from_sql ¶
Parse a SQL predicate string into our AST.
The grammar covers comparisons, AND / OR / NOT,
IN (literal value list), BETWEEN, LIKE / ILIKE,
IS [NOT] NULL, CAST(… AS …), typed temporal literals
(TIMESTAMP '…' / DATE '…'), the function-call temporal
coercion form (TIMESTAMP('…') / DATE('…')), and
+/-/*///% arithmetic on columns and
literals. Tokens outside that surface raise ValueError
with the offending position.
Dialect selection only affects identifier / string-literal
quoting: Databricks and MySQL accept "…" as a string
literal (and \`…\``` as the identifier quote); ANSI /
Postgres / SQLite treat"…"`` as the identifier quote.