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_scopemethod 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>
impl<'a, C: Catalog + ?Sized> NameResolver<'a, C>
Sourcepub fn resolve_table(
&self,
name: &str,
span: Span,
) -> Result<&TableMetadata, PlannerError>
pub fn resolve_table( &self, name: &str, span: Span, ) -> Result<&TableMetadata, PlannerError>
Sourcepub fn resolve_column<'t>(
&self,
table: &'t TableMetadata,
column: &str,
span: Span,
) -> Result<&'t ColumnMetadata, PlannerError>
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");Sourcepub fn resolve_column_with_scope(
&self,
tables: &[&TableMetadata],
table_qualifier: Option<&str>,
column: &str,
span: Span,
) -> Result<ResolvedColumn, PlannerError>
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
- If
table_qualifieris specified (e.g.,users.id), resolve from that table only. - If
table_qualifierisNone:- If the column exists in exactly one table, resolve it.
- If the column exists in multiple tables, return
AmbiguousColumnerror. - If the column doesn’t exist in any table, return
ColumnNotFounderror.
§Errors
PlannerError::TableNotFoundif the specified table qualifier doesn’t match any table.PlannerError::ColumnNotFoundif the column doesn’t exist in the resolved table(s).PlannerError::AmbiguousColumnif the column exists in multiple tables without qualification.
Sourcepub fn expand_wildcard(&self, table: &TableMetadata) -> Vec<String>
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 orderSourcepub fn resolve_expr(
&self,
expr: &Expr,
table: &TableMetadata,
) -> Result<(), PlannerError>
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.