| 505 | } |
| 506 | |
| 507 | Status OrcStructReader::TopLevelReadValueBatch(ScratchTupleBatch* scratch_batch, |
| 508 | MemPool* pool) { |
| 509 | // Validate row batch if needed. |
| 510 | if (row_validator_) DCHECK(scanner_->row_batches_need_validation_); |
| 511 | if (row_validator_ && !row_validator_->IsRowBatchValid()) { |
| 512 | row_idx_ = NumElements(); |
| 513 | return Status::OK(); |
| 514 | } |
| 515 | // Saving the initial value of num_tuples because each child->ReadValueBatch() will |
| 516 | // update it. |
| 517 | int scratch_batch_idx = scratch_batch->num_tuples; |
| 518 | int item_count = -1; |
| 519 | for (OrcColumnReader* child : children_) { |
| 520 | RETURN_IF_ERROR( |
| 521 | child->ReadValueBatch(row_idx_, scratch_batch, pool, scratch_batch_idx)); |
| 522 | // Check if each column reader reads the same amount of values. |
| 523 | if (item_count == -1) item_count = scratch_batch->num_tuples; |
| 524 | if (item_count != scratch_batch->num_tuples) { |
| 525 | return Status(Substitute("Corrupt ORC file '$0': Expected number of items in " |
| 526 | "each column: $1 Actual number in col '$2': $3", scanner_->filename(), |
| 527 | item_count, orc_column_id_, scratch_batch->num_tuples)); |
| 528 | } |
| 529 | } |
| 530 | int num_rows_read = scratch_batch->num_tuples - scratch_batch_idx; |
| 531 | if (children_.empty()) { |
| 532 | // We allow empty 'children_' in all cases. |
| 533 | DCHECK_EQ(0, num_rows_read); |
| 534 | num_rows_read = std::min(scratch_batch->capacity - scratch_batch->num_tuples, |
| 535 | NumElements() - row_idx_); |
| 536 | scratch_batch->num_tuples += num_rows_read; |
| 537 | } |
| 538 | if (scanner_->file_position_ != nullptr) { |
| 539 | FillVirtualRowIdColumn(scratch_batch, scratch_batch_idx, num_rows_read); |
| 540 | } |
| 541 | row_idx_ += num_rows_read; |
| 542 | return Status::OK(); |
| 543 | } |
| 544 | |
| 545 | void OrcStructReader::FillVirtualRowIdColumn(ScratchTupleBatch* scratch_batch, |
| 546 | int scratch_batch_idx, int num_rows) { |
no test coverage detected