From bee1bb03252bca9713cbc3e2c8b037ca9eb14ac6 Mon Sep 17 00:00:00 2001 From: Yaron Gvili Date: Thu, 11 May 2023 03:59:04 -0400 Subject: [PATCH 1/3] Fix source node batch realignment --- cpp/src/arrow/acero/source_node.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/acero/source_node.cc b/cpp/src/arrow/acero/source_node.cc index 6c138d8dccd..f4503d75791 100644 --- a/cpp/src/arrow/acero/source_node.cc +++ b/cpp/src/arrow/acero/source_node.cc @@ -105,10 +105,11 @@ struct SourceNode : ExecNode, public TracedNode { } ExecBatch batch = morsel.Slice(offset, batch_size); for (auto& value : batch.values) { - if (value.is_array()) { - ARROW_ASSIGN_OR_RAISE(value, arrow::util::EnsureAlignment( - value.make_array(), ipc::kArrowAlignment, - default_memory_pool())); + if (value.is_array() && value.type()->byte_width() > 1) { + ARROW_ASSIGN_OR_RAISE( + value, arrow::util::EnsureAlignment(value.make_array(), + value.type()->byte_width(), + default_memory_pool())); } } if (has_ordering) { From 892e4002690c869c31a942cbaf80f6dc7830581f Mon Sep 17 00:00:00 2001 From: Yaron Gvili Date: Thu, 11 May 2023 04:10:53 -0400 Subject: [PATCH 2/3] GH-35498: [C++] Fix source node batch realignment --- cpp/src/arrow/acero/source_node.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/arrow/acero/source_node.cc b/cpp/src/arrow/acero/source_node.cc index f4503d75791..6ba7770be1c 100644 --- a/cpp/src/arrow/acero/source_node.cc +++ b/cpp/src/arrow/acero/source_node.cc @@ -105,7 +105,7 @@ struct SourceNode : ExecNode, public TracedNode { } ExecBatch batch = morsel.Slice(offset, batch_size); for (auto& value : batch.values) { - if (value.is_array() && value.type()->byte_width() > 1) { + if (value.is_array() && value.type()->byte_width() > 1) { // GH-35498 ARROW_ASSIGN_OR_RAISE( value, arrow::util::EnsureAlignment(value.make_array(), value.type()->byte_width(), From f46d30417817e4e09a967a4a37f24bb3a4032b15 Mon Sep 17 00:00:00 2001 From: Yaron Gvili Date: Thu, 11 May 2023 07:00:10 -0400 Subject: [PATCH 3/3] realign to power-of-2 only --- cpp/src/arrow/acero/source_node.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cpp/src/arrow/acero/source_node.cc b/cpp/src/arrow/acero/source_node.cc index 6ba7770be1c..84b8d129fd8 100644 --- a/cpp/src/arrow/acero/source_node.cc +++ b/cpp/src/arrow/acero/source_node.cc @@ -34,6 +34,7 @@ #include "arrow/util/align_util.h" #include "arrow/util/async_generator.h" #include "arrow/util/async_util.h" +#include "arrow/util/bit_util.h" #include "arrow/util/checked_cast.h" #include "arrow/util/future.h" #include "arrow/util/logging.h" @@ -105,10 +106,11 @@ struct SourceNode : ExecNode, public TracedNode { } ExecBatch batch = morsel.Slice(offset, batch_size); for (auto& value : batch.values) { - if (value.is_array() && value.type()->byte_width() > 1) { // GH-35498 + int64_t width = value.type()->byte_width(); + if (value.is_array() && is_fixed_width(value.type()->id()) && width > 1 && + bit_util::IsPowerOf2(width)) { ARROW_ASSIGN_OR_RAISE( - value, arrow::util::EnsureAlignment(value.make_array(), - value.type()->byte_width(), + value, arrow::util::EnsureAlignment(value.make_array(), width, default_memory_pool())); } }