TypeChecker

Struct TypeChecker 

Source
pub struct TypeChecker<'a, C: Catalog + ?Sized> { /* private fields */ }
Expand description

Type checker for SQL expressions.

Performs type inference and validation for expressions, ensuring that operations are valid for the types involved and that constraints are met.

§Examples

use alopex_sql::catalog::MemoryCatalog;
use alopex_sql::planner::type_checker::TypeChecker;

let catalog = MemoryCatalog::new();
let type_checker = TypeChecker::new(&catalog);

Implementations§

Source§

impl<'a, C: Catalog + ?Sized> TypeChecker<'a, C>

Source

pub fn new(catalog: &'a C) -> Self

Create a new TypeChecker with the given catalog.

Source

pub fn catalog(&self) -> &'a C

Get a reference to the catalog.

Source

pub fn infer_type( &self, expr: &Expr, table: &TableMetadata, ) -> Result<TypedExpr, PlannerError>

Infer the type of an expression within a table context.

Recursively analyzes the expression to determine its type, resolving column references against the provided table metadata.

§Errors

Returns an error if:

  • A column reference cannot be resolved
  • A binary operation is invalid for the operand types
  • A function call has invalid arguments
Source

pub fn check_binary_op( &self, op: BinaryOp, left: &ResolvedType, right: &ResolvedType, span: Span, ) -> Result<ResolvedType, PlannerError>

Check binary operation and return the result type.

Validates that the operator is valid for the given operand types and returns the result type.

§Type Rules
  • Arithmetic operators (+, -, *, /, %): Require numeric operands
  • Comparison operators (=, <>, <, >, <=, >=): Require compatible types
  • Logical operators (AND, OR): Require boolean operands
  • String concatenation (||): Requires text operands
Source

pub fn normalize_metric( &self, metric: &str, span: Span, ) -> Result<VectorMetric, PlannerError>

Normalize a metric string to VectorMetric enum (case-insensitive).

§Valid Values
  • “cosine” (case-insensitive) → VectorMetric::Cosine
  • “l2” (case-insensitive) → VectorMetric::L2
  • “inner” (case-insensitive) → VectorMetric::Inner
§Errors

Returns PlannerError::InvalidMetric if the value is not recognized.

Source

pub fn check_function_call( &self, name: &str, args: &[TypedExpr], span: Span, ) -> Result<ResolvedType, PlannerError>

Check function call and return the result type.

Validates that the function arguments have correct types and returns the result type.

Source

pub fn check_vector_distance( &self, args: &[TypedExpr], span: Span, ) -> Result<ResolvedType, PlannerError>

Check vector_distance function arguments.

Signature: vector_distance(column: Vector, vector: Vector, metric: Text) -> Double

§Requirements
  • First argument must be a Vector type (column reference)
  • Second argument must be a Vector type (vector literal)
  • Third argument must be a Text type (metric string)
  • Vector dimensions must match
Source

pub fn check_vector_similarity( &self, args: &[TypedExpr], span: Span, ) -> Result<ResolvedType, PlannerError>

Check vector_similarity function arguments.

Signature: vector_similarity(column: Vector, vector: Vector, metric: Text) -> Double

Same validation rules as vector_distance.

Source

pub fn check_vector_dimension( &self, expected: u32, found: u32, span: Span, ) -> Result<(), PlannerError>

Check that two vector dimensions match.

§Errors

Returns PlannerError::VectorDimensionMismatch if dimensions don’t match.

Source

pub fn check_insert_values( &self, table: &TableMetadata, columns: &[String], values: &[Vec<Expr>], span: Span, ) -> Result<Vec<Vec<TypedExpr>>, PlannerError>

Check INSERT values against table columns.

Validates that:

  • The number of values matches the number of columns
  • Each value’s type is compatible with the column type
  • NOT NULL constraints are satisfied
  • Vector dimensions match for vector columns
§Column Order

If columns is empty, uses TableMetadata.column_names() order (definition order).

§Errors
  • ColumnValueCountMismatch: Number of values doesn’t match columns
  • TypeMismatch: Value type incompatible with column type
  • NullConstraintViolation: NULL value for NOT NULL column
  • VectorDimensionMismatch: Vector dimension mismatch
Source

pub fn check_assignment( &self, table: &TableMetadata, column: &str, value: &Expr, span: Span, ) -> Result<TypedExpr, PlannerError>

Check UPDATE assignment type compatibility.

Validates that the value’s type is compatible with the column type.

§Errors
  • ColumnNotFound: Column doesn’t exist
  • TypeMismatch: Value type incompatible with column type
  • NullConstraintViolation: NULL value for NOT NULL column
  • VectorDimensionMismatch: Vector dimension mismatch
Source

pub fn check_null_constraint( &self, column: &ColumnMetadata, value: &TypedExpr, span: Span, ) -> Result<(), PlannerError>

Check NOT NULL constraint for a value.

§Errors

Returns PlannerError::NullConstraintViolation if the column has NOT NULL constraint and the value is NULL.

Auto Trait Implementations§

§

impl<'a, C> Freeze for TypeChecker<'a, C>
where C: ?Sized,

§

impl<'a, C> RefUnwindSafe for TypeChecker<'a, C>
where C: RefUnwindSafe + ?Sized,

§

impl<'a, C> Send for TypeChecker<'a, C>
where C: Sync + ?Sized,

§

impl<'a, C> Sync for TypeChecker<'a, C>
where C: Sync + ?Sized,

§

impl<'a, C> Unpin for TypeChecker<'a, C>
where C: ?Sized,

§

impl<'a, C> UnwindSafe for TypeChecker<'a, C>
where C: RefUnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> MaybeSend for T
where T: Send,