This is an automated email from the ASF dual-hosted git repository.

pitrou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 1b0b16a8f6 GH-51144: [C++] Incorrect Logic for 
AdaptiveUIntBuilder::AppendValues (#51146)
1b0b16a8f6 is described below

commit 1b0b16a8f68c0082534aa185c0bb4052614df924
Author: Arash Andishgar <[email protected]>
AuthorDate: Thu Sep 3 16:09:41 2026 +0330

    GH-51144: [C++] Incorrect Logic for AdaptiveUIntBuilder::AppendValues 
(#51146)
    
    ### Rationale for this change
    
    `arrow::AdaptiveUIntBuilder::AppendValues` creates incorrect results when 
combined with `arrow::AdaptiveUIntBuilder::Append`.
    
    ### What changes are included in this PR?
    
    Correct the logic of `arrow::AdaptiveUIntBuilder::AppendValues` and add the 
relevant unit test.
    
    ### Are these changes tested?
    
    Yes. I ran the relevant unit test.
    
    ### Are there any user-facing changes?
    
    No.
    
    **This PR contains a "Critical Fix".** (b) A bug that caused incorrect or 
invalid data to be produced.
    
    * GitHub Issue: #51144
    
    Authored-by: arash andishgar <[email protected]>
    Signed-off-by: Antoine Pitrou <[email protected]>
---
 cpp/src/arrow/array/array_test.cc       | 15 +++++++++++++++
 cpp/src/arrow/array/builder_adaptive.cc |  1 +
 2 files changed, 16 insertions(+)

diff --git a/cpp/src/arrow/array/array_test.cc 
b/cpp/src/arrow/array/array_test.cc
index 668d9f00d8..2cdf94bfab 100644
--- a/cpp/src/arrow/array/array_test.cc
+++ b/cpp/src/arrow/array/array_test.cc
@@ -3322,6 +3322,21 @@ TEST_F(TestAdaptiveUIntBuilder, TestAppendEmptyValue) {
   AssertArraysEqual(*result_, *ArrayFromJSON(uint8(), "[null, null, 0, 42, 0, 
0]"));
 }
 
+TEST_F(TestAdaptiveUIntBuilder, TestAppendValuesAfterAppend) {
+  ASSERT_OK(builder_->Append(1));
+  ASSERT_OK(builder_->Append(2));
+  ASSERT_OK(builder_->Append(3));
+  ASSERT_OK(builder_->Append(4));
+  std::vector<uint64_t> values{5, 6, 7, 8};
+  ASSERT_OK(builder_->AppendValues(values.data(), values.size()));
+  Done();
+  ASSERT_OK(result_->ValidateFull());
+
+  std::shared_ptr<Array> expected;
+  ArrayFromVector<UInt8Type>({1, 2, 3, 4, 5, 6, 7, 8}, &expected);
+  AssertArraysEqual(*expected, *result_);
+}
+
 TEST(TestAdaptiveUIntBuilderWithStartIntSize, TestReset) {
   auto builder = std::make_shared<AdaptiveUIntBuilder>(
       static_cast<uint8_t>(sizeof(uint16_t)), default_memory_pool());
diff --git a/cpp/src/arrow/array/builder_adaptive.cc 
b/cpp/src/arrow/array/builder_adaptive.cc
index 3cd5a46321..05c90a03a0 100644
--- a/cpp/src/arrow/array/builder_adaptive.cc
+++ b/cpp/src/arrow/array/builder_adaptive.cc
@@ -349,6 +349,7 @@ Status AdaptiveUIntBuilder::AppendValuesInternal(const 
uint64_t* values, int64_t
 
 Status AdaptiveUIntBuilder::AppendValues(const uint64_t* values, int64_t 
length,
                                          const uint8_t* valid_bytes) {
+  RETURN_NOT_OK(CommitPendingData());
   RETURN_NOT_OK(Reserve(length));
 
   return AppendValuesInternal(values, length, valid_bytes);

Reply via email to