Skip to content

Commit

Permalink
extract helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
mapleFU committed Aug 17, 2024
1 parent fda14a4 commit 2fda2db
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions cpp/src/arrow/compute/kernels/row_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,33 +75,31 @@ void BooleanKeyEncoder::AddLengthNull(int32_t* length) {

Status BooleanKeyEncoder::Encode(const ExecValue& data, int64_t batch_length,
uint8_t** encoded_bytes) {
auto handle_next_valid_value = [encoded_bytes](bool value) mutable {
auto& encoded_ptr = *encoded_bytes++;
*encoded_ptr++ = kValidByte;
*encoded_ptr++ = value;
};
auto handle_next_null_value = [encoded_bytes]() mutable {
auto& encoded_ptr = *encoded_bytes++;
*encoded_ptr++ = kNullByte;
*encoded_ptr++ = 0;
};

if (data.is_array()) {
VisitArraySpanInline<BooleanType>(
data.array,
[&](bool value) {
auto& encoded_ptr = *encoded_bytes++;
*encoded_ptr++ = kValidByte;
*encoded_ptr++ = value;
},
[&] {
auto& encoded_ptr = *encoded_bytes++;
*encoded_ptr++ = kNullByte;
*encoded_ptr++ = 0;
});
data.array, [&](bool value) { handle_next_valid_value(value); },
[&] { handle_next_null_value(); });
} else {
const auto& scalar = data.scalar_as<BooleanScalar>();
if (!scalar.is_valid) {
for (int64_t i = 0; i < batch_length; i++) {
auto& encoded_ptr = *encoded_bytes++;
*encoded_ptr++ = kNullByte;
*encoded_ptr++ = 0;
handle_next_null_value();
}
} else {
const bool value = scalar.value;
for (int64_t i = 0; i < batch_length; i++) {
auto& encoded_ptr = *encoded_bytes++;
*encoded_ptr++ = kValidByte;
*encoded_ptr++ = value;
handle_next_valid_value(value);
}
}
}
Expand Down

0 comments on commit 2fda2db

Please sign in to comment.