MCPcopy Create free account
hub / github.com/apache/arrow / LeafReader

Class LeafReader

cpp/src/parquet/arrow/reader.cc:461–796  ·  view source on GitHub ↗

Leaf reader is for primitive arrays and primitive children of nested arrays

Source from the content-addressed store, hash-verified

459
460// Leaf reader is for primitive arrays and primitive children of nested arrays
461class LeafReader : public ColumnReaderImpl {
462 public:
463 LeafReader(std::shared_ptr<ReaderContext> ctx, std::shared_ptr<Field> field,
464 std::unique_ptr<FileColumnIterator> input,
465 ::parquet::internal::LevelInfo leaf_info)
466 : ctx_(std::move(ctx)),
467 field_(std::move(field)),
468 input_(std::move(input)),
469 descr_(input_->descr()) {
470 const auto type_id = field_->type()->id();
471 // If binary-like, RecordReader is able to read directly as the concrete type
472 // so as to avoid offset limitations.
473 std::shared_ptr<DataType> type_for_reading =
474 (::arrow::is_base_binary_like(type_id) || ::arrow::is_binary_view_like(type_id))
475 ? field_->type()
476 : nullptr;
477 record_reader_ = RecordReader::Make(
478 descr_, leaf_info, ctx_->pool,
479 /*read_dictionary=*/field_->type()->id() == ::arrow::Type::DICTIONARY,
480 /*read_dense_for_nullable=*/false, /*arrow_type=*/type_for_reading);
481 NextRowGroup();
482 }
483
484 Status GetDefLevels(const int16_t** data, int64_t* length) final {
485 *data = record_reader_->def_levels();
486 *length = record_reader_->levels_position();
487 return Status::OK();
488 }
489
490 Status GetRepLevels(const int16_t** data, int64_t* length) final {
491 *data = record_reader_->rep_levels();
492 *length = record_reader_->levels_position();
493 return Status::OK();
494 }
495
496 bool IsOrHasRepeatedChild() const final { return false; }
497
498 Status LoadBatch(int64_t records_to_read) final {
499 BEGIN_PARQUET_CATCH_EXCEPTIONS
500 out_ = nullptr;
501 record_reader_->Reset();
502 // Pre-allocation gives much better performance for flat columns
503 record_reader_->Reserve(records_to_read);
504 const bool should_load_statistics = ctx_->reader_properties->should_load_statistics();
505 int64_t num_target_row_groups = 0;
506 while (records_to_read > 0) {
507 if (!record_reader_->HasMoreData()) {
508 break;
509 }
510 int64_t records_read = record_reader_->ReadRecords(records_to_read);
511 records_to_read -= records_read;
512 if (records_read == 0) {
513 NextRowGroup();
514 } else {
515 num_target_row_groups++;
516 // We can't mix multiple row groups when we load statistics
517 // because statistics are associated with a row group. If we
518 // want to mix multiple row groups and keep valid statistics,

Callers

nothing calls this directly

Calls 14

ListReaderClass · 0.85
VisitBitRunsFunction · 0.85
push_backMethod · 0.80
fieldFunction · 0.70
InvalidFunction · 0.50
OKFunction · 0.50
MakeArrayFunction · 0.50
sizeMethod · 0.45
typeMethod · 0.45
dataMethod · 0.45
list_sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected