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

HuaHuaY 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 8eca523490 GH-32723: [C++][Parquet] Concatenate chunked children of 
nested columns (#55351)
8eca523490 is described below

commit 8eca523490e8f16ff029ec1707e5ff4121242e7c
Author: Ludvig Hult <[email protected]>
AuthorDate: Fri Nov 6 03:22:56 2026 +0100

    GH-32723: [C++][Parquet] Concatenate chunked children of nested columns 
(#55351)
    
    ### Rationale for this change
    Adresses part of issue #32723.
    Using the parquet ReadTable functions fails on list of dicts, if they 
contain more than one row group.
    In such case, the data is in a chunked array. A NotImplemented guards stops 
this from being read.
    
    ### What changes are included in this PR?
    This PR is a minimal fix that addresses this in the case when the chunks 
can be combined into a single array.
    It does not address the overflow issues, and the preexisting 
arrow::Concatenate will throw on that. The error is propagated.
    
    ### Are these changes tested?
    One test case is added for this specific situation. It fails without the 
fix in reader.cc.
    No regressions on `parquet-arrow-reader-writer-test` found, which I also 
tested.
    On macOS.
    
    ### Are there any user-facing changes?
    The users will be able to read a few more parquet files that were 
previously rejected.
    
    ### Was AI used for this PR?
    
    Yes.
    
    Claude (Opus and Sonnet 5.5) was used for compiling information from 
existing issues and propose a solution. I decided to do a minimal fix, not 
addressing the overflow problems, to make sure I understand the PR. I also 
asked it to verify style guide and contributor process on 
https://arrow.apache.org/docs/dev/developers/guide/step_by_step/ hoping I dont 
miss any steps.
    
    **PR code and description written by:**
    
    - [x] Human (The PR text)
    - [x] AI (The code)
    
    **Reviewed before submission by:**
    
    - [x] Human
    - [ ] AI
    - [ ] Not reviewed
    
    * GitHub Issue: #32723
    
    Authored-by: Ludvig Hult <[email protected]>
    Signed-off-by: Zehua Zou <[email protected]>
---
 cpp/src/parquet/arrow/arrow_reader_writer_test.cc | 43 +++++++++++++++++++++++
 cpp/src/parquet/arrow/reader.cc                   | 23 +++++++-----
 2 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/cpp/src/parquet/arrow/arrow_reader_writer_test.cc 
b/cpp/src/parquet/arrow/arrow_reader_writer_test.cc
index 421769521d..873a41f24e 100644
--- a/cpp/src/parquet/arrow/arrow_reader_writer_test.cc
+++ b/cpp/src/parquet/arrow/arrow_reader_writer_test.cc
@@ -3453,6 +3453,49 @@ TEST(ArrowReadWrite, ListWithNoValues) {
   CheckSimpleRoundtrip(table, 2, props_store_schema);
 }
 
+TEST(ArrowReadWrite, NestedDictionaryMultipleRowGroups) {
+  // GH-45087: reading several row groups at once yields one chunk per row 
group
+  // for a nested dictionary leaf, and the chunks have different dictionaries.
+  using ::arrow::field;
+
+  auto dict_type = ::arrow::dictionary(::arrow::int32(), ::arrow::utf8());
+  for (const auto& type : {list(dict_type), ::arrow::large_list(dict_type)}) {
+    ARROW_SCOPED_TRACE("type = ", type->ToString());
+    auto array =
+        ::arrow::ArrayFromJSON(type, R"([["a"], ["b", "a"], ["c", "a"], 
["b"]])");
+    auto table = ::arrow::Table::Make(::arrow::schema({field("root", type)}), 
{array});
+    auto props_store_schema = 
ArrowWriterProperties::Builder().store_schema()->build();
+    CheckSimpleRoundtrip(table, /*row_group_size=*/2, props_store_schema);
+  }
+}
+
+TEST(ArrowReadWrite, NestedDictionaryDifferentDictionariesPerRowGroup) {
+  using ::arrow::field;
+
+  auto type = list(::arrow::dictionary(::arrow::int32(), ::arrow::utf8()));
+  // One input chunk per row group, each with its own dictionary.
+  auto chunk1 = ::arrow::ArrayFromJSON(type, R"([["a"], ["b", "a"]])");
+  auto chunk2 = ::arrow::ArrayFromJSON(type, R"([["c", "a"], ["b"]])");
+  auto schema = ::arrow::schema({field("root", type)});
+  auto input = Table::Make(
+      schema, {std::make_shared<::arrow::ChunkedArray>(ArrayVector{chunk1, 
chunk2})});
+
+  auto props_store_schema = 
ArrowWriterProperties::Builder().store_schema()->build();
+  std::shared_ptr<Table> result;
+  ASSERT_NO_FATAL_FAILURE(DoSimpleRoundtrip(input, /*use_threads=*/false,
+                                            /*row_group_size=*/2, {}, &result,
+                                            props_store_schema));
+  ASSERT_OK(result->ValidateFull());
+  ::arrow::AssertSchemaEqual(*schema, *result->schema(), 
/*check_metadata=*/false);
+
+  // Compare the decoded strings, so the order of the merged dictionary does 
not matter.
+  auto expected = ::arrow::ChunkedArrayFromJSON(
+      list(::arrow::utf8()), {R"([["a"], ["b", "a"], ["c", "a"], ["b"]])"});
+  ASSERT_OK_AND_ASSIGN(auto decoded,
+                       ::arrow::compute::Cast(result->column(0), 
list(::arrow::utf8())));
+  ::arrow::AssertChunkedEqual(*expected, *decoded.chunked_array());
+}
+
 TEST(ArrowReadWrite, Map) {
   using ::arrow::field;
   using ::arrow::map;
diff --git a/cpp/src/parquet/arrow/reader.cc b/cpp/src/parquet/arrow/reader.cc
index 872d1b4492..db2abfbb21 100644
--- a/cpp/src/parquet/arrow/reader.cc
+++ b/cpp/src/parquet/arrow/reader.cc
@@ -87,20 +87,23 @@ namespace bit_util = arrow::bit_util;
 namespace parquet::arrow {
 namespace {
 
-::arrow::Result<std::shared_ptr<ArrayData>> ChunksToSingle(const ChunkedArray& 
chunked) {
+::arrow::Result<std::shared_ptr<ArrayData>> ChunksToSingle(const ChunkedArray& 
chunked,
+                                                           MemoryPool* pool) {
   switch (chunked.num_chunks()) {
     case 0: {
       ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Array> array,
-                            ::arrow::MakeArrayOfNull(chunked.type(), 0));
+                            ::arrow::MakeArrayOfNull(chunked.type(), 0, pool));
       return array->data();
     }
     case 1:
       return chunked.chunk(0)->data();
-    default:
-      // ARROW-3762(wesm): If item reader yields a chunked array, we reject as
-      // this is not yet implemented
-      return Status::NotImplemented(
-          "Nested data conversions not implemented for chunked array outputs");
+    default: {
+      // GH-32723: A leaf reader can yield several chunks, e.g. one per row 
group for
+      // dictionaries. Concatenate fails if the merged data overflows the type.
+      ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Array> array,
+                            ::arrow::Concatenate(chunked.chunks(), pool));
+      return array->data();
+    }
   }
 }
 
@@ -670,7 +673,8 @@ class ListReader : public ColumnReaderImpl {
           
validity_buffer->Resize(bit_util::BytesForBits(validity_io.values_read)));
       validity_buffer->ZeroPadding();
     }
-    ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrayData> item_chunk, 
ChunksToSingle(**out));
+    ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrayData> item_chunk,
+                          ChunksToSingle(**out, ctx_->pool));
 
     std::vector<std::shared_ptr<Buffer>> buffers{
         validity_io.null_count > 0 ? validity_buffer : nullptr, 
offsets_buffer};
@@ -922,7 +926,8 @@ Status StructReader::BuildArray(int64_t length_upper_bound,
   for (auto& child : children_) {
     std::shared_ptr<ChunkedArray> field;
     RETURN_NOT_OK(child->BuildArray(validity_io.values_read, &field));
-    ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrayData> array_data, 
ChunksToSingle(*field));
+    ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrayData> array_data,
+                          ChunksToSingle(*field, ctx_->pool));
     children_array_data.push_back(std::move(array_data));
   }
 

Reply via email to