Skip to content

feat(analysis): route each dialect's SQL analysis to Polyglot or a native module - #1354

Merged
kvlonge merged 7 commits into
mainfrom
feat/analysis-route
Nov 8, 2026
Merged

kvlonge merged 7 commits into
mainfrom
feat/analysis-route

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Why

Each dialect's SQL analysis needs one place to move from Polyglot to a native SQLQuack module, and a safe fallback for SQL a native parser can't read yet.

Changes

  • analysis_route(dialect) returns Legacy or Native(&dyn NativeDialect), keyed on the adapter's new sql_analysis_dialect. NATIVE_DIALECTS is empty, so every dialect stays on Polyglot and compile output doesn't change.
  • On a native route, a model whose analysis SQL or inline hook the parser can't read gets warning P026, naming the construct, line and column, and it isn't analysed. Under require_sql_analysis P026 is an error. Skipped models get no lineage and no rules, and they never call Polyglot.
  • Native normalization spells placeholders the way the engine accepts them. UDF and cursor stubs take the dialect's stub_prefix (__sqlbuild.udf_x for SQL Server), and a quoted @'name' becomes '__sqlbuild_parameter__name'.
  • On ClickHouse's native route, contract types are compared without top-level Nullable/LowCardinality, and nullability is compared through the inferred flag.

Verification

  • fensu check: 0 faults. cargo clippy -D warnings is clean on sqlbuild-analysis, sqlbuild-rules and sqlbuild-python.
  • The analysis_route, contracts and rules tests pass. They cover routing, gap location after placeholders, stub spellings, the P026 message, the ClickHouse type match and rules for skipped models.

Adds analysis_route: a table of dialects whose SQL a native module
analyses, empty for now so every dialect keeps the Polyglot path; the
NativeDialect trait with read_whole; the native parser's first gap in a
model's SQL, normalised and with its placeholders filled as analysis
reads it; and the P026 message for a model whose analysis is skipped.
Not yet wired into the model loop.
… the engine accepts

A native route checks each model's analysis SQL and inline hook statements
with its dialect's parser. A gap warns P026 and the model is not analysed;
under require_sql_analysis it is an error. UDF and cursor stubs take the
dialect's prefix, and a quoted hook parameter becomes the string literal it
is filled with. On ClickHouse's native route, contract types are compared
without top-level Nullable and LowCardinality, and nullability through the
inferred flag. Every dialect stays on the Polyglot route until its native
module is registered.
The model loop read sql_analysis_dialect from ModelInputBuildContext, which
did not have the field, so every compile failed. The context now copies it
from the compile adapter context.
@kvlonge
kvlonge enabled auto-merge (squash) November 7, 2026 20:01
@kvlonge
kvlonge merged commit 97ab62c into main Nov 8, 2026
48 checks passed
@kvlonge
kvlonge deleted the feat/analysis-route branch November 8, 2026 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant