ResolvedType

Enum ResolvedType 

Source
pub enum ResolvedType {
    Integer,
    BigInt,
    Float,
    Double,
    Text,
    Blob,
    Boolean,
    Timestamp,
    Vector {
        dimension: u32,
        metric: VectorMetric,
    },
    Null,
}
Expand description

Normalized type information for type checking.

This enum represents the resolved type after normalization from AST types. For example, INTEGER and INT both resolve to ResolvedType::Integer.

§Examples

use alopex_sql::planner::types::ResolvedType;
use alopex_sql::ast::ddl::{DataType, VectorMetric};

// Convert from AST DataType
let int_type = ResolvedType::from_ast(&DataType::Integer);
assert_eq!(int_type, ResolvedType::Integer);

// VECTOR with omitted metric defaults to Cosine
let vec_type = ResolvedType::from_ast(&DataType::Vector { dimension: 128, metric: None });
assert_eq!(vec_type, ResolvedType::Vector { dimension: 128, metric: VectorMetric::Cosine });

Variants§

§

Integer

Integer type (INTEGER, INT → Integer)

§

BigInt

Big integer type

§

Float

Single-precision floating point

§

Double

Double-precision floating point

§

Text

Text/string type

§

Blob

Binary data type

§

Boolean

Boolean type (BOOLEAN, BOOL → Boolean)

§

Timestamp

Timestamp type

§

Vector

Vector type with dimension and metric Metric is always populated (defaults to Cosine if omitted in AST)

Fields

§dimension: u32
§

Null

NULL type (for NULL literals)

Implementations§

Source§

impl ResolvedType

Source

pub fn from_ast(dt: &DataType) -> Self

Convert from AST DataType to ResolvedType.

For VECTOR types, if metric is omitted in the AST, it defaults to Cosine.

§Examples
use alopex_sql::planner::types::ResolvedType;
use alopex_sql::ast::ddl::{DataType, VectorMetric};

// INTEGER and INT both resolve to Integer
assert_eq!(ResolvedType::from_ast(&DataType::Integer), ResolvedType::Integer);
assert_eq!(ResolvedType::from_ast(&DataType::Int), ResolvedType::Integer);

// BOOLEAN and BOOL both resolve to Boolean
assert_eq!(ResolvedType::from_ast(&DataType::Boolean), ResolvedType::Boolean);
assert_eq!(ResolvedType::from_ast(&DataType::Bool), ResolvedType::Boolean);

// VECTOR with metric
let vec_with_metric = ResolvedType::from_ast(&DataType::Vector {
    dimension: 128,
    metric: Some(VectorMetric::L2),
});
assert_eq!(vec_with_metric, ResolvedType::Vector {
    dimension: 128,
    metric: VectorMetric::L2,
});

// VECTOR without metric defaults to Cosine
let vec_default = ResolvedType::from_ast(&DataType::Vector {
    dimension: 256,
    metric: None,
});
assert_eq!(vec_default, ResolvedType::Vector {
    dimension: 256,
    metric: VectorMetric::Cosine,
});
Source

pub fn can_cast_to(&self, target: &ResolvedType) -> bool

Check if this type can be implicitly cast to the target type.

Implicit conversion rules:

  • Same types are always compatible
  • Null can be cast to any type
  • Numeric widening: IntegerBigInt, Float, Double
  • Numeric widening: BigIntDouble
  • Numeric widening: FloatDouble
  • Vector types require dimension check (done separately)
§Examples
use alopex_sql::planner::types::ResolvedType;

// Same type
assert!(ResolvedType::Integer.can_cast_to(&ResolvedType::Integer));

// Null can cast to any type
assert!(ResolvedType::Null.can_cast_to(&ResolvedType::Integer));
assert!(ResolvedType::Null.can_cast_to(&ResolvedType::Text));

// Numeric widening
assert!(ResolvedType::Integer.can_cast_to(&ResolvedType::BigInt));
assert!(ResolvedType::Integer.can_cast_to(&ResolvedType::Float));
assert!(ResolvedType::Integer.can_cast_to(&ResolvedType::Double));
assert!(ResolvedType::BigInt.can_cast_to(&ResolvedType::Double));
assert!(ResolvedType::Float.can_cast_to(&ResolvedType::Double));

// Incompatible types
assert!(!ResolvedType::Text.can_cast_to(&ResolvedType::Integer));
assert!(!ResolvedType::BigInt.can_cast_to(&ResolvedType::Integer));
Source

pub fn type_name(&self) -> &'static str

Get a human-readable name for this type.

Used for error messages.

Trait Implementations§

Source§

impl Clone for ResolvedType

Source§

fn clone(&self) -> ResolvedType

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ResolvedType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ResolvedType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<PersistedType> for ResolvedType

Source§

fn from(value: PersistedType) -> Self

Converts to this type from the input type.
Source§

impl From<ResolvedType> for PersistedType

Source§

fn from(value: ResolvedType) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ResolvedType

Source§

fn eq(&self, other: &ResolvedType) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&SqlValue> for ResolvedType

Source§

type Error = StorageError

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

fn try_from(value: &SqlValue) -> Result<Self>

Performs the conversion.
Source§

impl Eq for ResolvedType

Source§

impl StructuralPartialEq for ResolvedType

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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,