korowa commented on code in PR #4737:
URL: https://github.com/apache/arrow-datafusion/pull/4737#discussion_r1057313831
##########
datafusion/physical-expr/src/expressions/nullif.rs:
##########
@@ -88,17 +50,34 @@ pub fn nullif_func(args: &[ColumnarValue]) ->
Result<ColumnarValue> {
let cond_array = eq_dyn(lhs, rhs)?;
// Now, invoke nullif on the result
- let array = primitive_bool_array_op!(lhs, &cond_array, nullif)?;
+ let array = nullif(lhs, as_boolean_array(&cond_array)?)?;
+ Ok(ColumnarValue::Array(array))
+ }
+ (ColumnarValue::Scalar(lhs), ColumnarValue::Array(rhs)) => {
+ // Similar to Array-Array case, except of ScalarValue -> Array cast
+ let lhs = lhs.to_array_of_size(rhs.len());
+ let cond_array = eq_dyn(&lhs, rhs)?;
+
+ let array = nullif(&lhs, as_boolean_array(&cond_array)?)?;
Ok(ColumnarValue::Array(array))
}
- _ => Err(DataFusionError::NotImplemented(
- "nullif does not support a literal as first argument".to_string(),
- )),
+ (ColumnarValue::Scalar(lhs), ColumnarValue::Scalar(rhs)) => {
+ let val = match lhs.eq(rhs) {
+ true => ScalarValue::Null,
Review Comment:
Nice catch, thank you!
Fixed scalar-scalar case to return empty value with data type inherited from
first argument, also added .slt for nullif
--
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]