44use std:: fmt:: Formatter ;
55use std:: ops:: Deref ;
66
7- use prost:: Message ;
8- use vortex_dtype:: DType ;
9- use vortex_error:: { VortexExpect , VortexResult , vortex_bail, vortex_err} ;
10- use vortex_proto:: expr as pb;
11-
12- use crate :: ArrayRef ;
137use crate :: compute:: cast as compute_cast;
148use crate :: expr:: expression:: Expression ;
159use crate :: expr:: { ChildName , ExprId , ExpressionView , StatsCatalog , VTable , VTableExt } ;
1610use crate :: stats:: Stat ;
11+ use crate :: ArrayRef ;
12+ use prost:: Message ;
13+ use vortex_dtype:: DType ;
14+ use vortex_error:: { vortex_bail, vortex_err, VortexExpect , VortexResult } ;
15+ use vortex_proto:: expr as pb;
16+ use vortex_vector:: Vector ;
1717
1818/// A cast expression that converts values to a target data type.
1919pub struct Cast ;
@@ -87,6 +87,16 @@ impl VTable for Cast {
8787 } )
8888 }
8989
90+ fn execute (
91+ & self ,
92+ expr : & ExpressionView < Self > ,
93+ vector : & Vector ,
94+ dtype : & DType ,
95+ ) -> VortexResult < Vector > {
96+ let input = expr. child ( 0 ) . execute ( vector, dtype) ?;
97+ vortex_compute:: cast:: Cast :: cast ( & input, dtype)
98+ }
99+
90100 fn stat_expression (
91101 & self ,
92102 expr : & ExpressionView < Self > ,
@@ -120,6 +130,15 @@ impl VTable for Cast {
120130 }
121131}
122132
133+ /// A trait that defines the compute function for performing a cast.
134+ ///
135+ /// The `try_cast` method attempts to convert the vector to the specified data type,
136+ /// returning a `VortexResult` that contains the casted vector or an error if the
137+ /// cast operation fails.
138+ trait VectorCast {
139+ fn try_cast ( self , dtype : & DType ) -> VortexResult < Vector > ;
140+ }
141+
123142/// Creates an expression that casts values to a target data type.
124143///
125144/// Converts the input expression's values to the specified target type.
@@ -141,11 +160,11 @@ mod tests {
141160 use vortex_error:: VortexUnwrap as _;
142161
143162 use super :: cast;
144- use crate :: IntoArray ;
145163 use crate :: arrays:: StructArray ;
146164 use crate :: expr:: exprs:: get_item:: get_item;
147165 use crate :: expr:: exprs:: root:: root;
148- use crate :: expr:: { Expression , test_harness} ;
166+ use crate :: expr:: { test_harness, Expression } ;
167+ use crate :: IntoArray ;
149168
150169 #[ test]
151170 fn dtype ( ) {
0 commit comments