NameResolver

Struct NameResolver 

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

Name resolver for validating table and column references.

The NameResolver validates SQL identifiers against the catalog, ensuring that referenced tables and columns exist. It also handles wildcard expansion for SELECT * queries.

§Design Notes

  • In v0.1.1, only single-table operations are supported (no JOINs).
  • The resolve_column_with_scope method is prepared for future JOIN support (v0.3.0+).
  • Wildcard expansion returns columns in table definition order.

§Examples

use alopex_sql::catalog::MemoryCatalog;
use alopex_sql::planner::name_resolver::NameResolver;

let catalog = MemoryCatalog::new();
let resolver = NameResolver::new(&catalog);

// Resolve a table reference
let table = resolver.resolve_table("users", span)?;

Implementations§

Source§

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

Source

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

Create a new name resolver with the given catalog.

Source

pub fn resolve_table( &self, name: &str, span: Span, ) -> Result<&TableMetadata, PlannerError>

Resolve a table reference.

Validates that the table exists in the catalog and returns its metadata.

§Errors

Returns PlannerError::TableNotFound if the table doesn’t exist.

§Examples
let table = resolver.resolve_table("users", span)?;
assert_eq!(table.name, "users");
Source

pub fn resolve_column<'t>( &self, table: &'t TableMetadata, column: &str, span: Span, ) -> Result<&'t ColumnMetadata, PlannerError>

Resolve a column reference within a single table context.

Validates that the column exists in the given table and returns its metadata.

§Errors

Returns PlannerError::ColumnNotFound if the column doesn’t exist in the table.

§Examples
let table = resolver.resolve_table("users", span)?;
let column = resolver.resolve_column(table, "id", span)?;
assert_eq!(column.name, "id");
Source

pub fn resolve_column_with_scope( &self, tables: &[&TableMetadata], table_qualifier: Option<&str>, column: &str, span: Span, ) -> Result<ResolvedColumn, PlannerError>

Resolve a column reference with scope for multiple tables.

This method supports resolution in contexts with multiple tables (for future JOIN support). In v0.1.1, tables should always contain exactly one element.

§Resolution Rules
  1. If table_qualifier is specified (e.g., users.id), resolve from that table only.
  2. If table_qualifier is None:
    • If the column exists in exactly one table, resolve it.
    • If the column exists in multiple tables, return AmbiguousColumn error.
    • If the column doesn’t exist in any table, return ColumnNotFound error.
§Errors
  • PlannerError::TableNotFound if the specified table qualifier doesn’t match any table.
  • PlannerError::ColumnNotFound if the column doesn’t exist in the resolved table(s).
  • PlannerError::AmbiguousColumn if the column exists in multiple tables without qualification.
Source

pub fn expand_wildcard(&self, table: &TableMetadata) -> Vec<String>

Expand a wildcard (*) to all column names in definition order.

Returns a vector of column names from the table in the order they were defined.

§Examples
let table = resolver.resolve_table("users", span)?;
let columns = resolver.expand_wildcard(table);
// Returns ["id", "name", "email"] in definition order
Source

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

Validate all column references within an expression.

Recursively traverses the expression tree and validates that all column references exist in the given table.

§Errors

Returns PlannerError::ColumnNotFound if any column reference in the expression doesn’t exist in the table.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'a, C> UnwindSafe for NameResolver<'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,