lidavidm commented on a change in pull request #10410:
URL: https://github.com/apache/arrow/pull/10410#discussion_r640733082



##########
File path: cpp/src/arrow/compute/kernels/scalar_if_else_test.cc
##########
@@ -25,52 +25,51 @@ namespace arrow {
 namespace compute {
 
 void CheckIfElseOutputArray(const Datum& cond, const Datum& left, const Datum& 
right,
-                            const Datum& expected, bool all_valid = true) {
+                            const Datum& expected) {
   ASSERT_OK_AND_ASSIGN(Datum datum_out, IfElse(cond, left, right));
   std::shared_ptr<Array> result = datum_out.make_array();
   ASSERT_OK(result->ValidateFull());
+  std::shared_ptr<Array> expected_ = expected.make_array();
   AssertArraysEqual(*expected.make_array(), *result, /*verbose=*/true);
-  if (all_valid) {
-    // Check null count of ArrayData is set, not the computed Array.null_count
-    ASSERT_EQ(result->data()->null_count, 0);
-  }
+
+  ASSERT_EQ(result->data()->null_count, expected_->data()->null_count);

Review comment:
       Note AssertArraysEqual already performs this check for you.

##########
File path: cpp/src/arrow/compute/kernels/scalar_if_else.cc
##########
@@ -699,14 +699,58 @@ struct IfElseFunctor<Type, enable_if_boolean<Type>> {
   // AAS
   static Status Call(KernelContext* ctx, const ArrayData& cond, const 
ArrayData& left,
                      const Scalar& right, ArrayData* out) {
-    // todo impl
+    ARROW_RETURN_NOT_OK(PromoteNullsVisitor(ctx, cond, left, right, out));
+
+    // out_buff = left & cond
+    ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Buffer> out_buf,
+                          arrow::internal::BitmapAnd(
+                              ctx->memory_pool(), left.buffers[1]->data(), 
left.offset,
+                              cond.buffers[1]->data(), cond.offset, 
cond.length, 0));
+
+    bool right_data = internal::UnboxScalar<BooleanType>::Unbox(right);
+
+    // out_buff = left & cond | right & ~cond
+    if (right_data) {
+      arrow::internal::BitmapOrNot(out_buf->data(), 0, cond.buffers[1]->data(),
+                                   cond.offset, cond.length, 0, 
out_buf->mutable_data());
+    }
+
+    out->buffers[1] = std::move(out_buf);
     return Status::OK();
   }
 
   // ASS
   static Status Call(KernelContext* ctx, const ArrayData& cond, const Scalar& 
left,
                      const Scalar& right, ArrayData* out) {
-    // todo impl
+    ARROW_RETURN_NOT_OK(PromoteNullsVisitor(ctx, cond, left, right, out));
+
+    bool left_data = internal::UnboxScalar<BooleanType>::Unbox(left);
+    bool right_data = internal::UnboxScalar<BooleanType>::Unbox(right);
+
+    // out_buf = left & cond | right & ~cond
+    std::shared_ptr<Buffer> out_buf = nullptr;
+    if (left_data) {
+      if (right_data) {
+        // out_buf = ones
+        ARROW_ASSIGN_OR_RAISE(out_buf, ctx->AllocateBitmap(cond.length));
+        // filling with UINT8_MAX upto the buffer's size (in bytes)
+        arrow::compute::internal::SetMemory<UINT8_MAX>(out_buf.get());

Review comment:
       You could just inline the memset call here - no need to put a helper in 
a header IMO unless we're going to use it a lot. 




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to