Skip to main content

rewrite

Function rewrite 

pub fn rewrite(sql: &str, opts: &Options) -> String
Expand description

Substitute every standalone FROM changes / JOIN changes in sql with the lineage-resolved source table when opts.use_canonical_lineage is on.

Handles two SQL conventions:

  • FROM changes ... changes.col (no per-query alias) → adds AS changes so qualified column references continue to resolve.
  • FROM changes c ... c.col (existing per-query alias like c, cchg) → replaces only the table name; the existing alias is preserved.

Word-boundary anchoring (regex \b) prevents touching changes_bucketed, changes_lineage, or any column named changes_*.

§Panics

Panics if the embedded regex fails to compile — unreachable since the pattern is a compile-time literal, validated by the unit tests in this module.