Skip to content

Commit

Permalink
ARROW-11741: [C++] Fix decimal casts on big endian platforms
Browse files Browse the repository at this point in the history
Closes apache#9554 from pitrou/ARROW-11741-cast-decimal-big-endian

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
  • Loading branch information
pitrou authored and michalursa committed Jun 13, 2021
1 parent 8ccae5a commit c45c7be
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cpp/src/arrow/compute/kernels/codegen_internal.h
Expand Up @@ -663,11 +663,14 @@ struct ScalarUnaryNotNullStateful {
static void Exec(const ThisType& functor, KernelContext* ctx, const ArrayData& arg0,
Datum* out) {
ArrayData* out_arr = out->mutable_array();
auto out_data = out_arr->GetMutableValues<Decimal128>(1);
// Decimal128 data buffers are not safely reinterpret_cast-able on big-endian
using endian_agnostic = std::array<uint8_t, sizeof(Decimal128)>;
auto out_data = out_arr->GetMutableValues<endian_agnostic>(1);
VisitArrayValuesInline<Arg0Type>(
arg0,
[&](Arg0Value v) {
*out_data++ = functor.op.template Call<OutValue, Arg0Value>(ctx, v);
functor.op.template Call<OutValue, Arg0Value>(ctx, v).ToBytes(
out_data++->data());
},
[&]() { ++out_data; });
}
Expand Down

0 comments on commit c45c7be

Please sign in to comment.