Skip to content

Commit 20a7810

Browse files
committed
GH-50778: [C++] Fix chunked level histogram accumulation
1 parent aeff591 commit 20a7810

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

cpp/src/parquet/size_statistics.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void UpdateLevelHistogram(std::span<const int16_t> levels, std::span<int64_t> hi
168168
auto it = levels.begin();
169169
while (it != levels.end()) {
170170
const auto chunk_size = std::min<int64_t>(levels.end() - it, kChunkSize);
171-
hist1 += std::accumulate(levels.begin(), levels.begin() + chunk_size, int16_t{0});
171+
hist1 += std::accumulate(it, it + chunk_size, int16_t{0});
172172
it += chunk_size;
173173
}
174174
histogram[0] += num_levels - hist1;

cpp/src/parquet/size_statistics_test.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ TEST(SizeStatistics, UpdateLevelHistogram) {
5050
UpdateLevelHistogram(std::vector<int16_t>{}, histogram);
5151
EXPECT_THAT(histogram, ::testing::ElementsAre(3, 5));
5252
}
53+
{
54+
// Cross the chunk boundary used by the max_level = 1 fast path.
55+
std::vector<int16_t> levels(1 << 14, 1);
56+
levels.push_back(0);
57+
std::vector<int64_t> histogram(2, 0);
58+
UpdateLevelHistogram(levels, histogram);
59+
EXPECT_THAT(histogram, ::testing::ElementsAre(1, 1 << 14));
60+
}
5361
{
5462
// max_level > 1
5563
std::vector<int64_t> histogram(3, 0);

0 commit comments

Comments
 (0)