GH-55900: [C++][Parquet] Use validity bitmap runs when encoding and decoding nullable values #55901
@ursabot please benchmark lang=C++
Benchmark runs are scheduled for commit 57e4f90ac5a25cee878fc36556a98fff5e9132b3. Watch https://buildkite.com/apache-arrow and https://conbench.arrow-dev.org for updates. A comment will be posted here when the runs are complete.
<!-- ccr-overview-v2 -->
🟢 Approval recommended
No active review issues are reported for the nullable Parquet encoding and decoding optimizations.
No open issues 🎉
<details>
<summary><strong>What changed in this PR</strong></summary>
Optimizes nullable Parquet encoding and decoding by processing validity runs, reducing per-value checks and temporary copies.
Changes:
| File | Description |
| ---- | ----------- |
| cpp/src/parquet/encoding_test.cc | Tests batched decoding with non-byte-aligned offsets. |
| cpp/src/parquet/encoder.cc | Shares helpers for valid runs and direct buffer compaction. |
| cpp/src/parquet/decoder.cc | Shares batched dictionary decoding and null-run appends. |
| cpp/src/parquet/column_writer.cc | Converts nullable values using validity runs. |
| cpp/src/arrow/buffer_builder.h | Copies and counts short bitmap segments in one pass. |
</details>
<sub>Review effort: Balanced</sub>
@ursabot please benchmark lang=C++
Benchmark runs are scheduled for commit 6bbb7de20c5ad3c36e95b158072ba3a9ebd0dc80. Watch https://buildkite.com/apache-arrow and https://conbench.arrow-dev.org for updates. A comment will be posted here when the runs are complete.
nit: move the if check out of the loop by setting violated = violated || (!truncation_allowed && values[i] % factor != 0) and then check violated in the end. Or simply add ARROW_PREDICT_FALSE just like below?
Why this change?
Does this comment relate to /estimated_data_length=/{} below?
Why do we need to use two different error messages? Just to keep the original behavior? Is it better to use the same one?
Although I did not modify PlainDecoder, I discovered that my changes cause the inlining of the AppendValue call within PlainDecoder to be lost. This is a performance optimization.
Approved these changes.
@pitrou Do you want to take a look?
This change should be reverted after #55940 is merged.
@ursabot please benchmark lang=C++
Benchmark runs are scheduled for commit 4690168cc40bc4d103161dd261599088378ab285. Watch https://buildkite.com/apache-arrow and https://conbench.arrow-dev.org for updates. A comment will be posted here when the runs are complete.
wgtmac
HuaHuaY
Rationale for this change
Reduce per-value validity checks and temporary copies in Parquet encoding and decoding.
What changes are included in this PR?
Are these changes tested?
Yes.
Are there any user-facing changes?
No.
Was AI used for this PR?
In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.
PR code and description written by:
Reviewed before submission by: