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

maplefu 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 29077d953f GH-45532: [C++] `RunEndEncodedBuilder` should clear 
dimensions after a `Finish()` call (#45533)
29077d953f is described below

commit 29077d953fe4190d9ebc812fae6adc74ec1e97c7
Author: Lester Fan <[email protected]>
AuthorDate: Mon Apr 14 05:59:43 2025 -0400

    GH-45532: [C++] `RunEndEncodedBuilder` should clear dimensions after a 
`Finish()` call (#45533)
    
    
    
    ### Rationale for this change
    
    This resolves the issue reported in 
https://github.com/apache/arrow/issues/45532. Specifically, this updates the 
`RunEndEncodedBuilder` dimensions after a `Finish()` call and therefore makes 
the function idempotent.
    
    ### What changes are included in this PR?
    
    This updates the `RunEndEncodedBuilder`'s dimensions after a `Finish()` 
call and adds a test which ensures the function properly resets the builder 
state and is idempotent.
    
    ### Are these changes tested?
    
    Yes
    
    ### Are there any user-facing changes?
    
    Yes; this is a bug fix to a user-facing API.
    
    * GitHub Issue: #45532
    
    Lead-authored-by: Lester Fan <[email protected]>
    Co-authored-by: mwish <[email protected]>
    Signed-off-by: mwish <[email protected]>
---
 cpp/src/arrow/array/array_run_end_test.cc | 14 ++++++++++++++
 cpp/src/arrow/array/builder_run_end.cc    |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/cpp/src/arrow/array/array_run_end_test.cc 
b/cpp/src/arrow/array/array_run_end_test.cc
index 3e8c658726..f2c493fb3a 100644
--- a/cpp/src/arrow/array/array_run_end_test.cc
+++ b/cpp/src/arrow/array/array_run_end_test.cc
@@ -367,6 +367,20 @@ TEST_P(TestRunEndEncodedArray, Builder) {
   }
 }
 
+TEST_P(TestRunEndEncodedArray, BuilderReuseAfterFinish) {
+  // GH-45532: RunEndEncodedBuilder should clear dimensions after a Finish() 
call
+  auto ree_type = run_end_encoded(run_end_type, utf8());
+  ASSERT_OK_AND_ASSIGN(std::shared_ptr<ArrayBuilder> builder, 
MakeBuilder(ree_type));
+  ASSERT_OK(builder->AppendScalar(*MakeScalar("test"), 100));
+  ASSERT_EQ(builder->length(), 100);
+  ASSERT_OK(builder->Finish());
+  ASSERT_EQ(builder->length(), 0);
+  ASSERT_EQ(*builder->type(), *run_end_encoded(run_end_type, utf8()));
+  ASSERT_OK(builder->Finish());
+  ASSERT_OK(builder->Finish());
+  ASSERT_EQ(builder->length(), 0);
+}
+
 TEST_P(TestRunEndEncodedArray, Validate) {
   auto run_ends_good = ArrayFromJSON(run_end_type, "[10, 20, 30, 40]");
   auto values = ArrayFromJSON(utf8(), R"(["A", "B", "C", null])");
diff --git a/cpp/src/arrow/array/builder_run_end.cc 
b/cpp/src/arrow/array/builder_run_end.cc
index 5e76cd498b..9199b5ab49 100644
--- a/cpp/src/arrow/array/builder_run_end.cc
+++ b/cpp/src/arrow/array/builder_run_end.cc
@@ -289,6 +289,9 @@ Status 
RunEndEncodedBuilder::FinishInternal(std::shared_ptr<ArrayData>* out) {
   ARROW_ASSIGN_OR_RAISE(auto ree_array,
                         RunEndEncodedArray::Make(length_, run_ends_array, 
values_array));
   *out = std::move(ree_array->data());
+
+  Reset();
+
   return Status::OK();
 }
 

Reply via email to