findReferencedSchemaTables method
Finds tables references from the global schema before any analyis steps ran.
This includes tables added in FROM
if those tables haven't been added
syntactically, for instance through a WITH
clause.
In a sense, this is comparable to finding "free variables" in a syntactic construct for other languages.
Implementation
Set<String> findReferencedSchemaTables(AstNode root) {
// Poorly clone the AST so that the analysis doesn't bring the original one
// into a weird state.
final sql = root.toSql();
final clone = parse(sql).rootNode;
final scope = _FakeRootScope();
final context = AnalysisContext(clone, sql, scope, EngineOptions(),
schemaSupport: schemaReader);
AstPreparingVisitor(context: context).start(clone);
clone.accept(ColumnResolver(context), const ColumnResolverContext());
return scope.addedTables;
}