Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Jul 16, 2024
1 parent 876e236 commit 64acd91
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 9 additions & 4 deletions native/core/src/execution/datafusion/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use datafusion_expr::expr::find_df_window_func;
use datafusion_expr::{ScalarUDF, WindowFrame, WindowFrameBound, WindowFrameUnits};
use datafusion_physical_expr::window::WindowExpr;
use datafusion_physical_expr_common::aggregate::create_aggregate_expr;
use datafusion_physical_expr_common::expressions::Literal;
use itertools::Itertools;
use jni::objects::GlobalRef;
use num::{BigInt, ToPrimitive};
Expand Down Expand Up @@ -545,10 +546,14 @@ impl PhysicalPlanner {

// optimized path for CASE WHEN predicate THEN expr ELSE null END
if else_phy_expr.is_none() && when_then_pairs.len() == 1 {
return Ok(Arc::new(ExprOrNull::new(
when_then_pairs[0].0.clone(),
when_then_pairs[0].1.clone(),
)));
let when_then = &when_then_pairs[0];
// ExprOrNull does not support scalar expressions
if !when_then.1.as_any().is::<Literal>() {
return Ok(Arc::new(ExprOrNull::new(
when_then.0.clone(),
when_then.1.clone(),
)));
}
}

Ok(Arc::new(CaseExpr::try_new(
Expand Down
7 changes: 3 additions & 4 deletions native/spark-expr/src/expr_or_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ impl PhysicalExpr for ExprOrNull {
let bit_mask = arrow::compute::kernels::boolean::not(bit_mask)?;
match self.expr.evaluate(batch)? {
ColumnarValue::Array(array) => Ok(ColumnarValue::Array(nullif(&array, &bit_mask)?)),
ColumnarValue::Scalar(value) => {
let array = value.to_array_of_size(batch.num_rows())?;
Ok(ColumnarValue::Array(nullif(&array, &bit_mask)?))
}
ColumnarValue::Scalar(_) => Err(DataFusionError::Execution(
"expression did not evaluate to an array".to_string(),
)),
}
} else {
Err(DataFusionError::Execution(
Expand Down

0 comments on commit 64acd91

Please sign in to comment.