bobzhang/sqlglot/optimizer does not have a README file
pub struct CopyBudget {
expression : Expr
max_copy_factor : Int?
min_copy_budget : Int
remaining : Int?
}fn CopyBudget::consume(self : CopyBudget, outer_scope : Scope, inner_scope : Scope, alias : String) -> Boolfn CopyBudget::new(expression : Expr, max_copy_factor? : Int?, min_copy_budget? : Int) -> CopyBudgetpub struct MappingSchema {
mapping : Map[String, SchemaNode]
udf_mapping : Map[String, SchemaNode]
visible : Map[String, SchemaNode]
normalize : Bool
dialect : Dialect
// private fields
}fn MappingSchema::add_table(self : MappingSchema, table : Expr, column_mapping? : Map[String, SchemaNode], dialect? : Dialect, normalize? : Bool, match_depth? : Bool) -> Unit raise SqlglotErrorfn MappingSchema::add_table_str(self : MappingSchema, table : String, columns? : Array[String], column_types? : Map[String, SchemaNode], dialect? : Dialect, normalize? : Bool, match_depth? : Bool) -> Unit raise SqlglotErrorfn MappingSchema::column_names(self : MappingSchema, table : Expr, only_visible? : Bool, dialect? : Dialect, normalize? : Bool) -> Array[String] raise SqlglotErrorfn MappingSchema::copy(self : MappingSchema, schema? : Map[String, SchemaNode]) -> MappingSchema raise SqlglotErrorfn MappingSchema::find(self : MappingSchema, table : Expr, raise_on_missing? : Bool) -> Map[String, SchemaNode]? raise SqlglotErrorfn MappingSchema::find_column_types(self : MappingSchema, table : Expr) -> Map[String, Expr?]? raise SqlglotErrorfn MappingSchema::get_column_type(self : MappingSchema, table : Expr, column : Expr, dialect? : Dialect, normalize? : Bool) -> Expr raise SqlglotErrorfn MappingSchema::get_column_type_str(self : MappingSchema, table : Expr, column : String, dialect? : Dialect, normalize? : Bool) -> Expr raise SqlglotErrorfn MappingSchema::get_udf_type(self : MappingSchema, udf : Expr, dialect? : Dialect, normalize? : Bool) -> Expr raise SqlglotErrorfn MappingSchema::get_udf_type_str(self : MappingSchema, udf : String, dialect? : Dialect, normalize? : Bool) -> Expr raise SqlglotErrorfn MappingSchema::has_column(self : MappingSchema, table : Expr, column : Expr, dialect? : Dialect, normalize? : Bool) -> Bool raise SqlglotErrorfn MappingSchema::new(schema? : Map[String, SchemaNode], visible? : Map[String, SchemaNode], dialect? : Dialect, normalize? : Bool, udf_mapping? : Map[String, SchemaNode]) -> MappingSchema raise SqlglotErrorfn MappingSchema::normalize_table(self : MappingSchema, table : Expr, dialect? : Dialect, normalize? : Bool) -> Exprpub struct OptimizeOptions {
schema : MappingSchema
db : String?
catalog : String?
dialect : Dialect
sql : String?
isolate_tables : Bool
quote_identifiers : Bool
infer_schema : Bool?
identify : Bool
leave_tables_isolated : Bool
validate_qualify_columns : Bool
canonicalize_table_aliases : Bool
expand_alias_refs : Bool
expand_stars : Bool
allow_partial_qualification : Bool
on_qualify : (Expr) -> Unit?
constant_propagation : Bool
coalesce_simplification : Bool
}fn Resolver::get_source_columns(self : Resolver, name : String, only_visible? : Bool) -> Array[String] raise SqlglotErrorfn Resolver::get_source_columns_from_set_op(self : Resolver, expression : Expr) -> Array[String] raise SqlglotErrorpub(all) enum Rule {
Qualify
QualifyTables
QualifyColumns
IsolateTableSelects
PushdownProjections
Normalize
UnnestSubqueries
PushdownPredicates
OptimizeJoins
EliminateSubqueries
MergeSubqueries
EliminateJoins
EliminateCtes
QuoteIdentifiers
AnnotateTypes
Canonicalize
Simplify
CanonicalizeInternalNames
Custom((Expr, OptimizeOptions) -> Expr raise SqlglotError)
}pub(all) enum SchemaNode {
Dict(Map[String, SchemaNode])
Type(String)
DataType(Expr)
Null
Names(Array[String])
}pub struct Scope {
id : Int
expression : Expr
sources : Map[String, Source]
lateral_sources : Map[String, Source]
cte_sources : Map[String, Source]
outer_columns : Array[String]
parent : Scope?
scope_type : ScopeType
subquery_scopes : Array[Scope]
derived_table_scopes : Array[Scope]
table_scopes : Array[Scope]
cte_scopes : Array[Scope]
set_operation_scopes : Array[Scope]
udtf_scopes : Array[Scope]
can_be_correlated : Bool
// private fields
}pub struct Simplifier {
dialect : Dialect
annotate_new_expressions : Bool
annotator : TypeAnnotator
}fn Simplifier::absorb_and_eliminate(self : Simplifier, expression : Expr, root : Bool) -> Expr raise SqlglotErrorfn Simplifier::remove_complements(self : Simplifier, expression : Expr, root : Bool) -> Expr raise SqlglotErrorfn Simplifier::simplify(self : Simplifier, expression : Expr, constant_propagation? : Bool, coalesce_simplification? : Bool) -> Expr raise SqlglotErrorfn Simplifier::simplify_conditionals(self : Simplifier, expression : Expr) -> Expr raise SqlglotErrorfn Simplifier::simplify_connectors(self : Simplifier, expression : Expr, root : Bool) -> Expr raise SqlglotErrorfn Simplifier::simplify_literals(self : Simplifier, expression : Expr, root : Bool) -> Expr raise SqlglotErrorfn Simplifier::uniq_sort(self : Simplifier, expression : Expr, root : Bool) -> Expr raise SqlglotErrorfn TypeAnnotator::annotate(self : TypeAnnotator, expression : Expr, annotate_scope? : Bool) -> Expr raise SqlglotErrorfn TypeAnnotator::annotate_binary(self : TypeAnnotator, expression : Expr) -> Unit raise SqlglotErrorfn TypeAnnotator::annotate_by_args(self : TypeAnnotator, expression : Expr, args : Array[ArgRef], promote? : Bool, array? : Bool) -> Unitpub(all) enum TypeSpec {
Returns(TType)
Annotator((TypeAnnotator, Expr) -> Unit raise SqlglotError)
}fn ensure_schema(schema? : MappingSchema, mapping? : Map[String, SchemaNode], dialect? : Dialect) -> MappingSchema raise SqlglotErrorfn explode_projection_to_unnest(index_offset? : Int, unnest_map? : Bool) -> ((Expr) -> Expr raise SqlglotError)fn install() -> Unitfn isolate_table_selects(expression : Expr, schema? : MappingSchema, dialect? : Dialect) -> Expr raise SqlglotErrorfn merge_ctes(expression : Expr, leave_tables_isolated? : Bool, scopes? : Array[Scope], copy_budget? : CopyBudget) -> (Expr, Bool) raise SqlglotErrorfn merge_derived_tables(expression : Expr, leave_tables_isolated? : Bool, scopes? : Array[Scope], copy_budget? : CopyBudget) -> Expr raise SqlglotErrorfn merge_subqueries(expression : Expr, leave_tables_isolated? : Bool, max_copy_factor? : Int?, min_copy_budget? : Int) -> Expr raise SqlglotErrorfn optimize(expression : Expr, schema? : MappingSchema, mapping? : Map[String, SchemaNode], db? : String, catalog? : String, dialect? : Dialect, rules? : Array[Rule], sql? : String, infer_schema? : Bool, identify? : Bool, leave_tables_isolated? : Bool, validate_qualify_columns? : Bool, canonicalize_table_aliases? : Bool, expand_alias_refs? : Bool, expand_stars? : Bool, allow_partial_qualification? : Bool, isolate_tables? : Bool, quote_identifiers? : Bool, on_qualify? : (Expr) -> Unit, constant_propagation? : Bool, coalesce_simplification? : Bool) -> Expr raise SqlglotErrorfn optimize_sql(sql : String, schema? : MappingSchema, mapping? : Map[String, SchemaNode], dialect? : Dialect, rules? : Array[Rule], infer_schema? : Bool, identify? : Bool) -> Expr raise SqlglotErrorfn projection_reachability(expression : Expr, whole_query? : Bool) -> ProjectionReachability raise SqlglotErrorfn prune_projections(reachability : ProjectionReachability, root : Int, journal? : Array[(Expr, String, Value?)], remove_ctes? : Bool) -> Unitfn qualify(expression : Expr, dialect? : Dialect, db? : String, catalog? : String, schema? : MappingSchema, expand_alias_refs? : Bool, expand_stars? : Bool, infer_schema? : Bool, isolate_tables? : Bool, qualify_columns? : Bool, allow_partial_qualification? : Bool, validate_qualify_columns? : Bool, quote_identifiers? : Bool, identify? : Bool, canonicalize_table_aliases? : Bool, on_qualify? : (Expr) -> Unit, sql? : String) -> Expr raise SqlglotErrorfn qualify_columns(expression : Expr, schema : MappingSchema, expand_alias_refs? : Bool, expand_stars? : Bool, infer_schema? : Bool, allow_partial_qualification? : Bool) -> Expr raise SqlglotErrorfn qualify_tables(expression : Expr, db? : String, catalog? : String, on_qualify? : (Expr) -> Unit, dialect? : Dialect, canonicalize_table_aliases? : Bool) -> Expr raise SqlglotErrorfn replace_tree(expression : Expr, fun : (Expr) -> Expr raise SqlglotError, prune? : (Expr) -> Bool) -> Expr raise SqlglotErrorfn simplify(expression : Expr, constant_propagation? : Bool, coalesce_simplification? : Bool, dialect? : Dialect) -> Expr raise SqlglotErrorInstall
Download zipA SQL parser, transpiler and optimizer: a MoonBit port of sqlglot