lidavidm commented on a change in pull request #11853:
URL: https://github.com/apache/arrow/pull/11853#discussion_r764851344
##########
File path: cpp/src/arrow/compute/kernels/vector_replace.cc
##########
@@ -444,6 +456,225 @@ struct ReplaceWithMaskFunctor {
}
};
+template <typename Type>
+void fillNullInDirectionImpl(const ArrayData& array, const uint8_t*
null_bitmap,
+ ArrayData* output, int8_t incrementer) {
+ uint8_t* out_bitmap = output->buffers[0]->mutable_data();
+ uint8_t* out_values = output->buffers[1]->mutable_data();
+ arrow::internal::CopyBitmap(array.buffers[0]->data(), array.offset,
array.length,
+ out_bitmap, output->offset);
+ ReplaceWithMask<Type>::CopyData(*array.type, out_values, 0, array, 0,
array.length);
+
+ auto array_scalars = arrow::MakeArray(array.Copy());
+
+ int64_t write_offset = incrementer == 1 ? 0 : array.length - 1;
+ int64_t bitmap_offset = 0;
+ int64_t current_value_offset = 0;
+ bool has_fill_value = false;
+ arrow::internal::OptionalBinaryBitBlockCounter counter(
+ null_bitmap, array.offset, null_bitmap, array.offset, array.length);
+
+ while (write_offset < array.length && write_offset >= 0) {
+ BitBlockCount block = counter.NextAndBlock();
+ if (block.AllSet()) {
+ current_value_offset = write_offset + incrementer * (block.length - 1);
+ } else {
+ if (block.popcount) {
+ for (int64_t i = 0; i != block.length; i++) {
+ uint64_t write_value_offset = write_offset + incrementer *
bitmap_offset;
+ auto current_bit = bit_util::GetBit(null_bitmap, bitmap_offset);
+ if (!current_bit) {
+ if (has_fill_value) {
+ ReplaceWithMask<Type>::CopyData(*array.type, out_values,
write_value_offset,
+ array, current_value_offset,
/*length=*/1);
+ bit_util::SetBitTo(out_bitmap, write_value_offset, true);
+ }
+ } else {
+ has_fill_value = true;
+ current_value_offset = write_value_offset;
+ }
+ bitmap_offset += 1;
+ }
+ } else {
+ auto in = *(array_scalars->GetScalar(current_value_offset));
+ ReplaceWithMask<Type>::CopyData(*array.type, out_values, write_offset,
*in,
+ current_value_offset, block.length);
+ bitmap_offset += block.length;
+ }
+ write_offset += block.length * incrementer;
+ }
+ }
+}
+
+template <typename Type, typename Enable = void>
+struct FillNullExecutor {};
+
+template <typename Type>
+struct FillNullExecutor<Type, enable_if_boolean<Type>> {
+ static Status ExecFillNull(KernelContext* ctx, const ArrayData& array,
+ const uint8_t* reverted_bitmap, ArrayData* output,
+ uint8_t direction) {
+ fillNullInDirectionImpl<Type>(array, reverted_bitmap, output, direction);
Review comment:
Ah whoops, right. Sorry for the confusion.
--
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]