Skip to main content

Module sql_resolve

Module sql_resolve 

Source
Expand description

Table / alias resolution for embedded SQL.

sql_sem defines the empty SqlStatementModel shape. This module is the population pass: given the raw SQL text of a SELECT / INSERT / UPDATE / DELETE / MERGE, it builds the AliasScope (alias → table) and classifies every table reference as read or write so the lineage layer can emit precise column-level edges later.

The recogniser is heuristic and line-shaped (no full SQL parser — that is the parser crate’s job). It handles the common shapes the lab corpus exercises:

  • FROM t [alias], FROM s.t [alias], comma-joined lists.
  • JOIN t [alias] ON … (any join keyword).
  • INSERT INTO t, UPDATE t [alias] SET, DELETE FROM t.
  • MERGE INTO t [alias] USING s [alias].

Bare aliases default to the table name when the FROM clause supplied none. Subquery contents are not descended into here (the lineage layer recurses; this pass models the top level).

§/oracle evidence

  • DATABASE-REFERENCE.md PL/SQL Language Reference — embedded SQL defers to the SQL Language Reference for the FROM / JOIN / alias grammar.
  • LOW-LEVEL-CATALOGS.md Data Dictionary View Families — ALL_TAB_COLUMNS is the server-side authority a later pass cross-checks the resolved (schema, table) pairs against.

Re-exports§

pub use crate::sql_sem::AliasScope as ResolvedAliasScope;

Functions§

resolve_sql
Resolve table + alias structure from a single embedded SQL statement’s raw text. Returns a populated SqlStatementModel (reads / writes columns are left for the column-resolution pass; this pass fills tables + alias_scope + verb).