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



##########
File path: cpp/src/arrow/compute/kernels/scalar_if_else.cc
##########
@@ -1827,9 +1827,131 @@ Status ExecArrayCoalesce(KernelContext* ctx, const 
ExecBatch& batch, Datum* out)
   return Status::OK();
 }
 
+// Special case: implement 'coalesce' for an array and a scalar for any
+// fixed-width type (a 'fill_null' operation)
+template <typename Type>
+Status ExecArrayScalarCoalesce(KernelContext* ctx, Datum left, Datum right,
+                               int64_t length, Datum* out) {
+  ArrayData* output = out->mutable_array();
+  const int64_t out_offset = output->offset;
+  uint8_t* out_valid = output->buffers[0]->mutable_data();
+  uint8_t* out_values = output->buffers[1]->mutable_data();
+
+  const ArrayData& left_arr = *left.array();
+  const uint8_t* left_valid =
+      left_arr.MayHaveNulls() ? left_arr.buffers[0]->data() : nullptr;
+  arrow::internal::OptionalBitBlockCounter bit_counter(left_valid, 
left_arr.offset,

Review comment:
       In this case it does better, though I could imagine it doing badly at 
~50% nulls.
   ```
   
--------------------------------------------------------------------------------------
   Benchmark                            Time             CPU   Iterations 
UserCounters...
   
--------------------------------------------------------------------------------------
   Before:
   CoalesceScalarBench64/0        1321249 ns      1321175 ns          508 
bytes_per_second=5.9133G/s items_per_second=793.67M/s length=1048.58k null%=1 
num_args=2
   CoalesceScalarBench64/2        5049228 ns      5049073 ns          133 
bytes_per_second=1.54731G/s items_per_second=207.677M/s length=1048.58k 
null%=25 num_args=2
   CoalesceScalarStringBench/0   87407512 ns     87404678 ns            7 
bytes_per_second=5.70364G/s items_per_second=11.9968M/s length=1048.58k null%=1 
num_args=2
   CoalesceScalarStringBench/2   77686321 ns     77685936 ns            8 
bytes_per_second=4.87622G/s items_per_second=13.4976M/s length=1048.58k 
null%=25 num_args=2
   After:
   CoalesceScalarBench64/0         988642 ns       988606 ns          664 
bytes_per_second=7.90255G/s items_per_second=1060.66M/s length=1048.58k null%=1 
num_args=2
   CoalesceScalarBench64/2        4537487 ns      4537432 ns          154 
bytes_per_second=1.72179G/s items_per_second=231.095M/s length=1048.58k 
null%=25 num_args=2
   CoalesceScalarStringBench/0  103582667 ns    103575544 ns            6 
bytes_per_second=4.81315G/s items_per_second=10.1238M/s length=1048.58k null%=1 
num_args=2
   CoalesceScalarStringBench/2   79813292 ns     79807705 ns            8 
bytes_per_second=4.74658G/s items_per_second=13.1388M/s length=1048.58k 
null%=25 num_args=2
   ```




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


Reply via email to