@@ -127,7 +127,6 @@ impl DefaultExpressionConvertor {
127127 let mut result = self . convert ( source_expr. as_ref ( ) ) ?;
128128 for expr in field_names {
129129 let field_name = expr
130- . as_any ( )
131130 . downcast_ref :: < df_expr:: Literal > ( )
132131 . ok_or_else ( || exec_datafusion_err ! ( "get_field field name must be a literal" ) ) ?
133132 . value ( )
@@ -195,19 +194,19 @@ impl ExpressionConvertor for DefaultExpressionConvertor {
195194 fn convert ( & self , df : & dyn PhysicalExpr ) -> DFResult < Expression > {
196195 // TODO(joe): Don't return an error when we have an unsupported node, bubble up "TRUE" as in keep
197196 // for that node, up to any `and` or `or` node.
198- if let Some ( binary_expr) = df. as_any ( ) . downcast_ref :: < df_expr:: BinaryExpr > ( ) {
197+ if let Some ( binary_expr) = df. downcast_ref :: < df_expr:: BinaryExpr > ( ) {
199198 let left = self . convert ( binary_expr. left ( ) . as_ref ( ) ) ?;
200199 let right = self . convert ( binary_expr. right ( ) . as_ref ( ) ) ?;
201200 let operator = try_operator_from_df ( binary_expr. op ( ) ) ?;
202201
203202 return Ok ( Binary . new_expr ( operator, [ left, right] ) ) ;
204203 }
205204
206- if let Some ( col_expr) = df. as_any ( ) . downcast_ref :: < df_expr:: Column > ( ) {
205+ if let Some ( col_expr) = df. downcast_ref :: < df_expr:: Column > ( ) {
207206 return Ok ( get_item ( col_expr. name ( ) . to_owned ( ) , root ( ) ) ) ;
208207 }
209208
210- if let Some ( like) = df. as_any ( ) . downcast_ref :: < df_expr:: LikeExpr > ( ) {
209+ if let Some ( like) = df. downcast_ref :: < df_expr:: LikeExpr > ( ) {
211210 let child = self . convert ( like. expr ( ) . as_ref ( ) ) ?;
212211 let pattern = self . convert ( like. pattern ( ) . as_ref ( ) ) ?;
213212 return Ok ( Like . new_expr (
@@ -219,42 +218,34 @@ impl ExpressionConvertor for DefaultExpressionConvertor {
219218 ) ) ;
220219 }
221220
222- if let Some ( literal) = df. as_any ( ) . downcast_ref :: < df_expr:: Literal > ( ) {
221+ if let Some ( literal) = df. downcast_ref :: < df_expr:: Literal > ( ) {
223222 let value = Scalar :: from_df ( literal. value ( ) ) ;
224223 return Ok ( lit ( value) ) ;
225224 }
226225
227- if let Some ( cast_expr) = df. as_any ( ) . downcast_ref :: < df_expr:: CastExpr > ( ) {
228- let cast_dtype = DType :: from_arrow ( ( cast_expr. cast_type ( ) , Nullability :: Nullable ) ) ;
226+ if let Some ( cast_expr) = df. downcast_ref :: < df_expr:: CastExpr > ( ) {
227+ let cast_dtype = DType :: from_arrow ( cast_expr. target_field ( ) . as_ref ( ) ) ;
229228 let child = self . convert ( cast_expr. expr ( ) . as_ref ( ) ) ?;
230229 return Ok ( cast ( child, cast_dtype) ) ;
231230 }
232231
233- if let Some ( cast_col_expr) = df. as_any ( ) . downcast_ref :: < df_expr:: CastColumnExpr > ( ) {
234- let target = cast_col_expr. target_field ( ) ;
235-
236- let target_dtype = DType :: from_arrow ( ( target. data_type ( ) , target. is_nullable ( ) . into ( ) ) ) ;
237- let child = self . convert ( cast_col_expr. expr ( ) . as_ref ( ) ) ?;
238- return Ok ( cast ( child, target_dtype) ) ;
239- }
240-
241- if let Some ( is_null_expr) = df. as_any ( ) . downcast_ref :: < df_expr:: IsNullExpr > ( ) {
232+ if let Some ( is_null_expr) = df. downcast_ref :: < df_expr:: IsNullExpr > ( ) {
242233 let arg = self . convert ( is_null_expr. arg ( ) . as_ref ( ) ) ?;
243234 return Ok ( is_null ( arg) ) ;
244235 }
245236
246- if let Some ( is_not_null_expr) = df. as_any ( ) . downcast_ref :: < df_expr:: IsNotNullExpr > ( ) {
237+ if let Some ( is_not_null_expr) = df. downcast_ref :: < df_expr:: IsNotNullExpr > ( ) {
247238 let arg = self . convert ( is_not_null_expr. arg ( ) . as_ref ( ) ) ?;
248239 return Ok ( is_not_null ( arg) ) ;
249240 }
250241
251- if let Some ( in_list) = df. as_any ( ) . downcast_ref :: < df_expr:: InListExpr > ( ) {
242+ if let Some ( in_list) = df. downcast_ref :: < df_expr:: InListExpr > ( ) {
252243 let value = self . convert ( in_list. expr ( ) . as_ref ( ) ) ?;
253244 let list_elements: Vec < _ > = in_list
254245 . list ( )
255246 . iter ( )
256247 . map ( |e| {
257- if let Some ( lit) = e. as_any ( ) . downcast_ref :: < df_expr:: Literal > ( ) {
248+ if let Some ( lit) = e. downcast_ref :: < df_expr:: Literal > ( ) {
258249 Ok ( Scalar :: from_df ( lit. value ( ) ) )
259250 } else {
260251 Err ( exec_datafusion_err ! ( "Failed to cast sub-expression" ) )
@@ -272,11 +263,11 @@ impl ExpressionConvertor for DefaultExpressionConvertor {
272263 return Ok ( if in_list. negated ( ) { not ( expr) } else { expr } ) ;
273264 }
274265
275- if let Some ( scalar_fn) = df. as_any ( ) . downcast_ref :: < ScalarFunctionExpr > ( ) {
266+ if let Some ( scalar_fn) = df. downcast_ref :: < ScalarFunctionExpr > ( ) {
276267 return self . try_convert_scalar_function ( scalar_fn) ;
277268 }
278269
279- if let Some ( case_expr) = df. as_any ( ) . downcast_ref :: < df_expr:: CaseExpr > ( ) {
270+ if let Some ( case_expr) = df. downcast_ref :: < df_expr:: CaseExpr > ( ) {
280271 return self . try_convert_case_expr ( case_expr) ;
281272 }
282273
@@ -297,7 +288,7 @@ impl ExpressionConvertor for DefaultExpressionConvertor {
297288 for projection_expr in source_projection. iter ( ) {
298289 let r = projection_expr. expr . apply ( |node| {
299290 // We only pull column children of scalar functions that we can't push into the scan.
300- if let Some ( scalar_fn_expr) = node. as_any ( ) . downcast_ref :: < ScalarFunctionExpr > ( )
291+ if let Some ( scalar_fn_expr) = node. downcast_ref :: < ScalarFunctionExpr > ( )
301292 && !can_scalar_fn_be_pushed_down ( scalar_fn_expr)
302293 {
303294 scan_projection. extend (
@@ -312,7 +303,7 @@ impl ExpressionConvertor for DefaultExpressionConvertor {
312303
313304 // DataFusion assumes different decimal types can be coerced.
314305 // Vortex expects a perfect match so we don't push it down.
315- if let Some ( binary_expr) = node. as_any ( ) . downcast_ref :: < df_expr:: BinaryExpr > ( )
306+ if let Some ( binary_expr) = node. downcast_ref :: < df_expr:: BinaryExpr > ( )
316307 && binary_expr. op ( ) . is_numerical_operators ( )
317308 && ( is_decimal ( & binary_expr. left ( ) . data_type ( input_schema) ?)
318309 && is_decimal ( & binary_expr. right ( ) . data_type ( input_schema) ?) )
@@ -406,14 +397,13 @@ fn try_operator_from_df(value: &DFOperator) -> DFResult<Operator> {
406397 }
407398}
408399
409- fn can_be_pushed_down_impl ( df_expr : & Arc < dyn PhysicalExpr > , schema : & Schema ) -> bool {
400+ fn can_be_pushed_down_impl ( expr : & Arc < dyn PhysicalExpr > , schema : & Schema ) -> bool {
410401 // We currently do not support pushdown of dynamic expressions in DF.
411402 // See issue: https://github.com/vortex-data/vortex/issues/4034
412- if is_dynamic_physical_expr ( df_expr ) {
403+ if is_dynamic_physical_expr ( expr ) {
413404 return false ;
414405 }
415406
416- let expr = df_expr. as_any ( ) ;
417407 if let Some ( binary) = expr. downcast_ref :: < df_expr:: BinaryExpr > ( ) {
418408 can_binary_be_pushed_down ( binary, schema)
419409 } else if let Some ( col) = expr. downcast_ref :: < df_expr:: Column > ( ) {
@@ -429,9 +419,6 @@ fn can_be_pushed_down_impl(df_expr: &Arc<dyn PhysicalExpr>, schema: &Schema) ->
429419 } else if let Some ( cast_expr) = expr. downcast_ref :: < df_expr:: CastExpr > ( ) {
430420 // CastExpr child must be an expression type that convert() can handle
431421 is_convertible_expr ( cast_expr. expr ( ) )
432- } else if let Some ( cast_col_expr) = expr. downcast_ref :: < df_expr:: CastColumnExpr > ( ) {
433- // CastColumnExpr child must be an expression type that convert() can handle
434- is_convertible_expr ( cast_col_expr. expr ( ) )
435422 } else if let Some ( is_null) = expr. downcast_ref :: < df_expr:: IsNullExpr > ( ) {
436423 can_be_pushed_down_impl ( is_null. arg ( ) , schema)
437424 } else if let Some ( is_not_null) = expr. downcast_ref :: < df_expr:: IsNotNullExpr > ( ) {
@@ -447,17 +434,15 @@ fn can_be_pushed_down_impl(df_expr: &Arc<dyn PhysicalExpr>, schema: &Schema) ->
447434 } else if let Some ( case_expr) = expr. downcast_ref :: < df_expr:: CaseExpr > ( ) {
448435 can_case_be_pushed_down ( case_expr, schema)
449436 } else {
450- tracing:: debug!( %df_expr , "DataFusion expression can't be pushed down" ) ;
437+ tracing:: debug!( %expr , "DataFusion expression can't be pushed down" ) ;
451438 false
452439 }
453440}
454441
455442/// Checks if an expression type is one that convert() can handle.
456443/// This is less restrictive than can_be_pushed_down since it only checks
457444/// expression types, not data type support.
458- fn is_convertible_expr ( df_expr : & Arc < dyn PhysicalExpr > ) -> bool {
459- let expr = df_expr. as_any ( ) ;
460-
445+ fn is_convertible_expr ( expr : & Arc < dyn PhysicalExpr > ) -> bool {
461446 // Expression types that convert() handles
462447 expr. downcast_ref :: < df_expr:: BinaryExpr > ( ) . is_some ( )
463448 || expr. downcast_ref :: < df_expr:: Column > ( ) . is_some ( )
@@ -466,9 +451,6 @@ fn is_convertible_expr(df_expr: &Arc<dyn PhysicalExpr>) -> bool {
466451 || expr
467452 . downcast_ref :: < df_expr:: CastExpr > ( )
468453 . is_some_and ( |e| is_convertible_expr ( e. expr ( ) ) )
469- || expr
470- . downcast_ref :: < df_expr:: CastColumnExpr > ( )
471- . is_some_and ( |e| is_convertible_expr ( e. expr ( ) ) )
472454 || expr. downcast_ref :: < df_expr:: IsNullExpr > ( ) . is_some ( )
473455 || expr. downcast_ref :: < df_expr:: IsNotNullExpr > ( ) . is_some ( )
474456 || expr. downcast_ref :: < df_expr:: InListExpr > ( ) . is_some ( )
@@ -568,6 +550,8 @@ mod tests {
568550 use arrow_schema:: Field ;
569551 use arrow_schema:: Schema ;
570552 use arrow_schema:: TimeUnit as ArrowTimeUnit ;
553+ use datafusion:: arrow:: array:: AsArray ;
554+ use datafusion:: arrow:: datatypes:: Int32Type ;
571555 use datafusion_common:: ScalarValue ;
572556 use datafusion_expr:: Operator as DFOperator ;
573557 use datafusion_physical_expr:: PhysicalExpr ;
@@ -988,12 +972,7 @@ mod tests {
988972 let vortex_as_arrow = vortex_result. into_primitive ( ) . as_slice :: < i32 > ( ) . to_vec ( ) ;
989973
990974 // Convert DataFusion result to Vec for comparison
991- let df_as_arrow: Vec < i32 > = df_array
992- . as_any ( )
993- . downcast_ref :: < Int32Array > ( )
994- . unwrap ( )
995- . values ( )
996- . to_vec ( ) ;
975+ let df_as_arrow: Vec < i32 > = df_array. as_primitive :: < Int32Type > ( ) . values ( ) . to_vec ( ) ;
997976
998977 // Compare results
999978 // Expected: [0, 0, 50, 100, 100] for values [1, 5, 10, 15, 20]
0 commit comments