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 a092214ba32 GH-55638: [C++][Parquet] Fix CDC to make list page
boundaries independent of array chunking (#55639)
a092214ba32 is described below
commit a092214ba329872794b951afef3c522cd0e01155
Author: Krisztián Szűcs <[email protected]>
AuthorDate: Tue Nov 17 11:19:45 2026 +0100
GH-55638: [C++][Parquet] Fix CDC to make list page boundaries independent
of array chunking (#55639)
### Rationale for this change
With content-defined chunking, list columns lose the chunk boundaries that
fall at the start of a `WriteArrow()` call, so their pages depend on how the
data is chunked in memory.
### What changes are included in this PR?
CDC marks a page boundary at the start of an input array-chunk with an
empty CDC-chunk. For list columns this empty CDC-chunk was dropped, so the
boundary was lost. Now it is kept, like for non-list columns.
```
content-defined boundary before D
WriteArrow([A B C]) CDC-chunks: [A B C] page [A B C] stays open
WriteArrow([D E F])
bug: CDC-chunks: [D E F] empty CDC-chunk dropped, D
E F join page [A B C]
fix: CDC-chunks: [] [D E F] empty CDC-chunk closes page
[A B C]
pages (bug): [A B C D E F]
pages (fix): [A B C] [D E F]
```
### Are these changes tested?
Yes. A new test compares the pages of a chunked table and its combined
version for each tested type, and the tests now check that no data page is
empty.
### Are there any user-facing changes?
No.
### Was AI used for this PR?
In accordance to the [AI generation
guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code),
please disclose below whether and how AI was used in this PR.
**PR code and description written by:**
- [ ] Human
- [x] AI
**Reviewed before submission by:**
- [x] Human
- [x] AI
- [ ] Not reviewed
* GitHub Issue: #55638
Lead-authored-by: Krisztian Szucs <[email protected]>
Co-authored-by: Krisztián Szűcs <[email protected]>
Co-authored-by: Antoine Pitrou <[email protected]>
Signed-off-by: Antoine Pitrou <[email protected]>
---
cpp/src/parquet/chunker_internal.cc | 15 +++++++--------
cpp/src/parquet/chunker_internal_test.cc | 22 ++++++++++++++++++++++
2 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/cpp/src/parquet/chunker_internal.cc
b/cpp/src/parquet/chunker_internal.cc
index aa0a2217b83..eda59a84698 100644
--- a/cpp/src/parquet/chunker_internal.cc
+++ b/cpp/src/parquet/chunker_internal.cc
@@ -229,7 +229,8 @@ class ContentDefinedChunker::Impl {
// chunks must be non-empty and monotonic increasing
ARROW_DCHECK(!chunks.empty());
- // the first chunk must start at the first level
+ // the first chunk must start at the first level, it may be empty to close
the
+ // page left open by the previous call
auto first_chunk = chunks.front();
ARROW_DCHECK_EQ(first_chunk.level_offset, 0);
ARROW_DCHECK_EQ(first_chunk.value_offset, 0);
@@ -326,13 +327,11 @@ class ContentDefinedChunker::Impl {
}
if (rep_level == 0 && gearhash.NeedNewChunk()) {
- // if we are at a record boundary and need a new chunk, we create a
new chunk
- auto levels_to_write = offset - prev_offset;
- if (levels_to_write > 0) {
- chunks.push_back({prev_offset, prev_value_offset,
levels_to_write});
- prev_offset = offset;
- prev_value_offset = value_offset;
- }
+ // if we are at a record boundary and need a new chunk, we create a
new chunk,
+ // at offset 0 it is empty and closes the page of the previous call
+ chunks.push_back({prev_offset, prev_value_offset, offset -
prev_offset});
+ prev_offset = offset;
+ prev_value_offset = value_offset;
}
if (def_level >= level_info_.repeated_ancestor_def_level) {
// we only increment the value offset if we have a leaf value
diff --git a/cpp/src/parquet/chunker_internal_test.cc
b/cpp/src/parquet/chunker_internal_test.cc
index 30e930326b9..e83cd25a73e 100644
--- a/cpp/src/parquet/chunker_internal_test.cc
+++ b/cpp/src/parquet/chunker_internal_test.cc
@@ -396,6 +396,7 @@ ParquetInfo GetColumnParquetInfo(const
std::shared_ptr<Buffer>& data, int column
while (auto page = page_reader->NextPage()) {
if (page->type() == PageType::DATA_PAGE || page->type() ==
PageType::DATA_PAGE_V2) {
auto data_page = static_cast<DataPage*>(page.get());
+ EXPECT_GT(data_page->num_values(), 0) << "empty data page";
column_info.page_sizes.push_back(data_page->uncompressed_size());
column_info.page_lengths.push_back(data_page->num_values());
} else if (page->type() == PageType::DICTIONARY_PAGE) {
@@ -1467,6 +1468,27 @@ TEST_P(TestCDCSingleRowGroup, ArrayOffsets) {
}
}
+TEST_P(TestCDCSingleRowGroup, IndependentOfArrayChunks) {
+ // Content-defined chunking should produce the same pages
+ // for logically equal inputs, regardless of the inputs' own
+ // in-memory chunking.
+ const auto& param = GetParam();
+ ASSERT_OK_AND_ASSIGN(auto chunked, ConcatenateTables({part1_, part2_,
part3_}));
+ ASSERT_OK_AND_ASSIGN(auto combined, chunked->CombineChunks());
+ ASSERT_EQ(chunked->column(0)->num_chunks(), 3);
+ ASSERT_EQ(combined->column(0)->num_chunks(), 1);
+ ASSERT_OK_AND_ASSIGN(
+ auto chunked_parquet,
+ WriteTableToBuffer(chunked, kMinChunkSize, kMaxChunkSize,
kRowGroupLength, false,
+ param.data_page_version));
+ ASSERT_OK_AND_ASSIGN(
+ auto combined_parquet,
+ WriteTableToBuffer(combined, kMinChunkSize, kMaxChunkSize,
kRowGroupLength, false,
+ param.data_page_version));
+ ASSERT_EQ(GetPageEnds(chunked_parquet, /*column_index=*/0),
+ GetPageEnds(combined_parquet, /*column_index=*/0));
+}
+
#if defined(ADDRESS_SANITIZER) || defined(ARROW_VALGRIND)
// Instantiate the test suite with a reduced set of types to avoid slow tests
INSTANTIATE_TEST_SUITE_P(