rok commented on code in PR #55577:
URL: https://github.com/apache/arrow/pull/55577#discussion_r4623246843
##########
cpp/src/parquet/column_reader.cc:
##########
@@ -2172,13 +2305,17 @@ template <typename DT, typename VS>
void TypedRecordReader<DT, VS>::Reserve(int64_t extra_values) {
value_sink_.ReserveValues(extra_values);
valid_bits_.ReserveValues(extra_values); // potentially no-op if void
- def_levels_.ReserveValues(extra_values); // potentially no-op if void
- rep_levels_.ReserveValues(extra_values); // potentially no-op if void
+ if (fixed_width_ == 0 || generic_batch_) {
+ def_levels_.ReserveValues(extra_values); // potentially no-op if void
+ rep_levels_.ReserveValues(extra_values); // potentially no-op if void
+ }
}
template <typename DT, typename VS>
void TypedRecordReader<DT, VS>::Reset() {
null_count_ = 0;
+ fixed_levels_ = 0;
+ generic_batch_ = has_buffered_levels() || !at_record_start_;
Review Comment:
This is where fast versus generic is decided, once per batch. See "Design",
point 1, in the summary: I'd move this decision to the start of each page, so a
page that falls back doesn't turn the fast path off for the rest of the batch.
##########
cpp/src/parquet/column_reader.cc:
##########
@@ -1764,13 +1793,21 @@ class TypedRecordReader : public
ColumnChunkReader<TypedRecordReaderTraits<DType
}
}
- int16_t* def_levels() const final { return def_levels_.data(); }
+ int16_t* def_levels() const final {
+ const_cast<TypedRecordReader*>(this)->MaterializeFixedLevels();
Review Comment:
This is one of the exits from the fast path (see "Design", point 2, in the
summary). Mutating inside a `const` accessor is surprising. If the lazy
materialization stays, please route it through the same hand-off as the other
exits, and document on `def_levels()`/`rep_levels()` that this is where the
levels get written.
##########
cpp/src/parquet/column_reader.h:
##########
@@ -336,6 +336,11 @@ class PARQUET_EXPORT RecordReader {
/// \return number of records read
virtual int64_t ReadRecords(int64_t num_records) = 0;
+ // Internal Arrow list-reader contract. Ordinary record-reader callers retain
+ // fully materialized levels unless they explicitly configure a known width.
+ virtual bool SetFixedSizeList(int32_t /*width*/) { return false; }
+ virtual bool dense_fixed_size_list() const { return false; }
Review Comment:
See "Interface" in the summary. This adds to the vtable of an exported class
just to carry an Arrow-reader detail.
##########
cpp/src/parquet/column_reader.cc:
##########
@@ -2190,6 +2327,8 @@ void TypedRecordReader<DT, VS>::Reset() {
template <typename DT, typename VS>
void TypedRecordReader<DT, VS>::SetPageReader(std::unique_ptr<PageReader>
reader) {
at_record_start_ = true;
+ fixed_phase_ = 0;
Review Comment:
**Blocking.** This reset is only safe if the previous column chunk ended on
a list boundary. When the chunk ends while `fixed_phase_ != 0`, its last list
is short. The phase is reset here, but the unmaterialized `fixed_levels_` still
assumes one continuous pattern, so the short list disappears when the levels
are rebuilt (see the review summary). One possible fix is to hand off to the
generic path in the end-of-data branch of `ReadRecords` (line 2027, which isn't
part of the diff):
```cpp
if (!this->EnsureDataPage()) {
if (fixed_phase_ != 0) {
// The column chunk ended inside a list. Keep that short list visible
// to the generic path instead of hiding it at the next chunk.
MaterializeFixedLevels();
generic_batch_ = true;
fixed_phase_ = 0;
}
if (!at_record_start_) {
```
With that change the regression test in the summary passes, and so do the
rest of `parquet-arrow-reader-writer-test` and `parquet-reader-test`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]