alamb commented on code in PR #2810:
URL: https://github.com/apache/arrow-datafusion/pull/2810#discussion_r910507550
##########
datafusion/physical-expr/src/expressions/case.rs:
##########
@@ -228,7 +238,23 @@ impl PhysicalExpr for CaseExpr {
}
fn data_type(&self, input_schema: &Schema) -> Result<DataType> {
- self.when_then_expr[0].1.data_type(input_schema)
+ // since all then results have the same data type, we can choose any
one as the
+ // return data type except for the null.
+ let mut data_type = DataType::Null;
+ for i in 0..self.when_then_expr.len() {
+ data_type = self.when_then_expr[i].1.data_type(input_schema)?;
+ if !data_type.equals_datatype(&DataType::Null) {
+ break;
+ }
+ }
+ // if all then results are null, we use data type of else expr instead
if possible.
Review Comment:
if they are all null, the output type is also null I would think.
##########
datafusion/physical-expr/src/expressions/case.rs:
##########
@@ -138,7 +138,12 @@ impl CaseExpr {
let then_value = self.when_then_expr[i]
.1
.evaluate_selection(batch, &when_match)?;
- let then_value = then_value.into_array(batch.num_rows());
+ let then_value = match then_value {
+ ColumnarValue::Scalar(value) if value.is_null() => {
+ new_null_array(&return_type, batch.num_rows())
+ }
Review Comment:
I don't understand why this code is needed -- I would have expected that
`then_value.into_array()` would have worked
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]