pub struct CastExpr {
pub expr: Arc<dyn PhysicalExpr>,
/* private fields */
}Expand description
CAST expression casts an expression to a specific data type and returns a runtime error on invalid cast
Fields§
§expr: Arc<dyn PhysicalExpr>The expression to cast
Implementations§
Source§impl CastExpr
impl CastExpr
Sourcepub fn new(
expr: Arc<dyn PhysicalExpr>,
cast_type: DataType,
cast_options: Option<CastOptions<'static>>,
) -> Self
pub fn new( expr: Arc<dyn PhysicalExpr>, cast_type: DataType, cast_options: Option<CastOptions<'static>>, ) -> Self
Create a new CastExpr using only a DataType.
This constructor is provided for compatibility with existing call sites
that only know the target type. It synthesizes a Field with the
given type (nullable by default) and no name metadata. Callers that
already have a FieldRef (for example, coming from schema inference or a
resolved column) should prefer CastExpr::new_with_target_field, which
preserves the field’s name, nullability, and other metadata. In other
words:
- use
new()when only aDataTypeis available and you want the legacy semantics of a type-only cast - use
new_with_target_field()when you need explicit field metadata/name/nullability preserved
Sourcepub fn new_with_target_field(
expr: Arc<dyn PhysicalExpr>,
target_field: FieldRef,
cast_options: Option<CastOptions<'static>>,
) -> Self
pub fn new_with_target_field( expr: Arc<dyn PhysicalExpr>, target_field: FieldRef, cast_options: Option<CastOptions<'static>>, ) -> Self
Create a new CastExpr with an explicit target FieldRef.
The provided target_field is used verbatim for the expression’s
return schema, so the field’s name, nullability, and other metadata are
preserved. This is the preferred constructor when the caller already
has field information (for example, during logical-to-physical planning).
See CastExpr::new for the compatibility constructor that only accepts
a DataType.
Sourcepub fn expr(&self) -> &Arc<dyn PhysicalExpr> ⓘ
pub fn expr(&self) -> &Arc<dyn PhysicalExpr> ⓘ
The expression to cast
Sourcepub fn target_field(&self) -> &FieldRef
pub fn target_field(&self) -> &FieldRef
Field metadata describing the output column after casting.
Sourcepub fn cast_options(&self) -> &CastOptions<'static>
pub fn cast_options(&self) -> &CastOptions<'static>
The cast options
Sourcepub fn check_bigger_cast(cast_type: &DataType, src: &DataType) -> bool
pub fn check_bigger_cast(cast_type: &DataType, src: &DataType) -> bool
Check if casting from the specified source type to the target type is a
widening cast (e.g. from Int8 to Int16).
Sourcepub fn is_bigger_cast(&self, src: &DataType) -> bool
pub fn is_bigger_cast(&self, src: &DataType) -> bool
Check if the cast is a widening cast (e.g. from Int8 to Int16).
Trait Implementations§
impl Eq for CastExpr
Source§impl PhysicalExpr for CastExpr
impl PhysicalExpr for CastExpr
Source§fn get_properties(&self, children: &[ExprProperties]) -> Result<ExprProperties>
fn get_properties(&self, children: &[ExprProperties]) -> Result<ExprProperties>
A CastExpr preserves the ordering of its child if the cast is done
under the same datatype family.
Source§fn data_type(&self, _input_schema: &Schema) -> Result<DataType>
fn data_type(&self, _input_schema: &Schema) -> Result<DataType>
Source§fn nullable(&self, input_schema: &Schema) -> Result<bool>
fn nullable(&self, input_schema: &Schema) -> Result<bool>
Source§fn evaluate(&self, batch: &RecordBatch) -> Result<ColumnarValue>
fn evaluate(&self, batch: &RecordBatch) -> Result<ColumnarValue>
Source§fn return_field(&self, input_schema: &Schema) -> Result<FieldRef>
fn return_field(&self, input_schema: &Schema) -> Result<FieldRef>
Source§fn children(&self) -> Vec<&Arc<dyn PhysicalExpr>>
fn children(&self) -> Vec<&Arc<dyn PhysicalExpr>>
Source§fn with_new_children(
self: Arc<Self>,
children: Vec<Arc<dyn PhysicalExpr>>,
) -> Result<Arc<dyn PhysicalExpr>>
fn with_new_children( self: Arc<Self>, children: Vec<Arc<dyn PhysicalExpr>>, ) -> Result<Arc<dyn PhysicalExpr>>
Source§fn evaluate_bounds(&self, children: &[&Interval]) -> Result<Interval>
fn evaluate_bounds(&self, children: &[&Interval]) -> Result<Interval>
Source§fn propagate_constraints(
&self,
interval: &Interval,
children: &[&Interval],
) -> Result<Option<Vec<Interval>>>
fn propagate_constraints( &self, interval: &Interval, children: &[&Interval], ) -> Result<Option<Vec<Interval>>>
Source§fn fmt_sql(&self, f: &mut Formatter<'_>) -> Result
fn fmt_sql(&self, f: &mut Formatter<'_>) -> Result
PhysicalExpr in nice human readable “SQL” format Read moreSource§fn evaluate_selection(
&self,
batch: &RecordBatch,
selection: &BooleanArray,
) -> Result<ColumnarValue, DataFusionError>
fn evaluate_selection( &self, batch: &RecordBatch, selection: &BooleanArray, ) -> Result<ColumnarValue, DataFusionError>
Source§fn evaluate_statistics(
&self,
children: &[&Distribution],
) -> Result<Distribution, DataFusionError>
fn evaluate_statistics( &self, children: &[&Distribution], ) -> Result<Distribution, DataFusionError>
Part of the unused Statistics V2 framework; see https://github.com/apache/datafusion/pull/22071
Source§fn propagate_statistics(
&self,
parent: &Distribution,
children: &[&Distribution],
) -> Result<Option<Vec<Distribution>>, DataFusionError>
fn propagate_statistics( &self, parent: &Distribution, children: &[&Distribution], ) -> Result<Option<Vec<Distribution>>, DataFusionError>
Part of the unused Statistics V2 framework; see https://github.com/apache/datafusion/pull/22071
Source§fn snapshot(&self) -> Result<Option<Arc<dyn PhysicalExpr>>, DataFusionError>
fn snapshot(&self) -> Result<Option<Arc<dyn PhysicalExpr>>, DataFusionError>
PhysicalExpr, if it is dynamic. Read moreSource§fn snapshot_generation(&self) -> u64
fn snapshot_generation(&self) -> u64
PhysicalExpr for snapshotting purposes.
The generation is an arbitrary u64 that can be used to track changes
in the state of the PhysicalExpr over time without having to do an exhaustive comparison.
This is useful to avoid unnecessary computation or serialization if there are no changes to the expression.
In particular, dynamic expressions that may change over time; this allows cheap checks for changes.
Static expressions that do not change over time should return 0, as does the default implementation.
You should not call this method directly as it does not handle recursion.
Instead use snapshot_generation to handle recursion and capture the
full state of the PhysicalExpr.Source§fn is_volatile_node(&self) -> bool
fn is_volatile_node(&self) -> bool
Source§fn placement(&self) -> ExpressionPlacement
fn placement(&self) -> ExpressionPlacement
Source§fn expression_id(&self) -> Option<u64>
fn expression_id(&self) -> Option<u64>
PhysicalExpr, if it
has one. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for CastExpr
impl !UnwindSafe for CastExpr
impl Freeze for CastExpr
impl Send for CastExpr
impl Sync for CastExpr
impl Unpin for CastExpr
impl UnsafeUnpin for CastExpr
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more