Skip to content

Commit

Permalink
apacheGH-41529: [C++][Compute] Remove redundant logic for ArrayData a…
Browse files Browse the repository at this point in the history
…s ExecResults in ExecScalarCaseWhen (apache#41380)

### Rationale for this change
Remove useless path in `ExecScalarCaseWhen`

### What changes are included in this PR?
Refactor : remove processing logic for ArrayData as ExecResults in ExecScalarCaseWhen.

### Are these changes tested?
Yes, by exists.

### Are there any user-facing changes?
No

* GitHub Issue: apache#41529

Authored-by: ZhangHuiGui <2689496754@qq.com>
Signed-off-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
  • Loading branch information
ZhangHuiGui authored May 10, 2024
1 parent 1c62df5 commit 5255adc
Showing 1 changed file with 19 additions and 31 deletions.
50 changes: 19 additions & 31 deletions cpp/src/arrow/compute/kernels/scalar_if_else.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1483,39 +1483,27 @@ Status ExecScalarCaseWhen(KernelContext* ctx, const ExecSpan& batch, ExecResult*
result = temp.get();
}

// TODO(wesm): clean this up to have less duplication
if (out->is_array_data()) {
ArrayData* output = out->array_data().get();
if (is_dictionary_type<Type>::value) {
const ExecValue& dict_from = has_result ? result : batch[1];
if (dict_from.is_scalar()) {
output->dictionary = checked_cast<const DictionaryScalar&>(*dict_from.scalar)
.value.dictionary->data();
} else {
output->dictionary = dict_from.array.ToArrayData()->dictionary;
}
}
CopyValues<Type>(result, /*in_offset=*/0, batch.length,
output->GetMutableValues<uint8_t>(0, 0),
output->GetMutableValues<uint8_t>(1, 0), output->offset);
} else {
// ArraySpan
ArraySpan* output = out->array_span_mutable();
if (is_dictionary_type<Type>::value) {
const ExecValue& dict_from = has_result ? result : batch[1];
output->child_data.resize(1);
if (dict_from.is_scalar()) {
output->child_data[0].SetMembers(
*checked_cast<const DictionaryScalar&>(*dict_from.scalar)
.value.dictionary->data());
} else {
output->child_data[0] = dict_from.array;
}
// Only input types of non-fixed length (which cannot be pre-allocated)
// will save the output data in ArrayData. And make sure the FixedLength
// types must be output in ArraySpan.
static_assert(is_fixed_width(Type::type_id));
DCHECK(out->is_array_span());

ArraySpan* output = out->array_span_mutable();
if (is_dictionary_type<Type>::value) {
const ExecValue& dict_from = has_result ? result : batch[1];
output->child_data.resize(1);
if (dict_from.is_scalar()) {
output->child_data[0].SetMembers(
*checked_cast<const DictionaryScalar&>(*dict_from.scalar)
.value.dictionary->data());
} else {
output->child_data[0] = dict_from.array;
}
CopyValues<Type>(result, /*in_offset=*/0, batch.length,
output->GetValues<uint8_t>(0, 0), output->GetValues<uint8_t>(1, 0),
output->offset);
}
CopyValues<Type>(result, /*in_offset=*/0, batch.length,
output->GetValues<uint8_t>(0, 0), output->GetValues<uint8_t>(1, 0),
output->offset);
return Status::OK();
}

Expand Down

0 comments on commit 5255adc

Please sign in to comment.