alamb commented on code in PR #4737:
URL: https://github.com/apache/arrow-datafusion/pull/4737#discussion_r1057283759
##########
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:
I wonder if this should actually be `ScalarValue::Boolean(None)` (aka a
typed boolean null, rather than `DataType::Null` 🤔 )
##########
datafusion/physical-expr/src/expressions/nullif.rs:
##########
@@ -15,52 +15,14 @@
// specific language governing permissions and limitations
// under the License.
-use std::sync::Arc;
-
use arrow::array::Array;
-use arrow::array::*;
use arrow::compute::eq_dyn;
use arrow::compute::nullif::nullif;
-use arrow::datatypes::DataType;
-use datafusion_common::{cast::as_boolean_array, DataFusionError, Result};
+use datafusion_common::{cast::as_boolean_array, DataFusionError, Result,
ScalarValue};
use datafusion_expr::ColumnarValue;
use super::binary::array_eq_scalar;
-/// Invoke a compute kernel on a primitive array and a Boolean Array
Review Comment:
😍
Thank you for this cleanup!
--
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]