sqlode/query_analyzer/type_inference

IR-driven type inference.

infer_expr_type walks a query_ir.Expr and returns the inferred #(ScalarType, nullable) pair, resolving column references against the supplied catalog and table scope. It replaces the previous heuristic path that operated on raw List(lexer.Token).

When the IR contains a RawExpr node — or an inner construct that inference can’t make sense of — the function returns an UnsupportedExpression error tied to the raw token fragment so the operator gets an explicit diagnostic pointing at the IR gap, never a silent fallback to StringType.

Types

Inferred type and nullability for an expression.

pub type InferredType {
  InferredType(scalar: model.ScalarType, nullable: Bool)
}

Constructors

Scope used to resolve ColumnRef during expression inference.

  • catalog is the augmented catalog (base tables + CTEs + VALUES
    • derived tables).
  • in_scope_tables is the ordered list of FROM/JOIN table names (or aliases) visible at this expression’s nesting level.
  • nullable_tables is the list of table names whose columns become nullable because of an outer LEFT/RIGHT/FULL join.
pub type Scope {
  Scope(
    query_name: String,
    catalog: model.Catalog,
    in_scope_tables: List(String),
    nullable_tables: List(String),
  )
}

Constructors

  • Scope(
      query_name: String,
      catalog: model.Catalog,
      in_scope_tables: List(String),
      nullable_tables: List(String),
    )

Values

pub fn infer_expr_type(
  scope: Scope,
  expr: query_ir.Expr,
) -> Result(InferredType, context.AnalysisError)
pub fn scope(
  query_name: String,
  catalog: model.Catalog,
  in_scope_tables: List(String),
  nullable_tables: List(String),
) -> Scope
Search Document