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)
Null
NULL type (for NULL literals)
Implementations§
Source§impl ResolvedType
impl ResolvedType
Sourcepub fn from_ast(dt: &DataType) -> Self
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,
});Sourcepub fn can_cast_to(&self, target: &ResolvedType) -> bool
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
Nullcan be cast to any type- Numeric widening:
Integer→BigInt,Float,Double - Numeric widening:
BigInt→Double - Numeric widening:
Float→Double Vectortypes 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));Trait Implementations§
Source§impl Clone for ResolvedType
impl Clone for ResolvedType
Source§fn clone(&self) -> ResolvedType
fn clone(&self) -> ResolvedType
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ResolvedType
impl Debug for ResolvedType
Source§impl Display for ResolvedType
impl Display for ResolvedType
Source§impl From<PersistedType> for ResolvedType
impl From<PersistedType> for ResolvedType
Source§fn from(value: PersistedType) -> Self
fn from(value: PersistedType) -> Self
Converts to this type from the input type.
Source§impl From<ResolvedType> for PersistedType
impl From<ResolvedType> for PersistedType
Source§fn from(value: ResolvedType) -> Self
fn from(value: ResolvedType) -> Self
Converts to this type from the input type.
Source§impl PartialEq for ResolvedType
impl PartialEq for ResolvedType
Source§impl TryFrom<&SqlValue> for ResolvedType
impl TryFrom<&SqlValue> for ResolvedType
impl Eq for ResolvedType
impl StructuralPartialEq for ResolvedType
Auto Trait Implementations§
impl Freeze for ResolvedType
impl RefUnwindSafe for ResolvedType
impl Send for ResolvedType
impl Sync for ResolvedType
impl Unpin for ResolvedType
impl UnwindSafe for ResolvedType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more