| 66 | : fragment_(std::move(fragment)), options_(std::move(options)) {} |
| 67 | |
| 68 | Result<RecordBatchIterator> Execute() { |
| 69 | struct Impl { |
| 70 | static Result<RecordBatchIterator> Make(const FileSource& source, |
| 71 | const FileFormat& format, |
| 72 | const ScanOptions& scan_options) { |
| 73 | ARROW_ASSIGN_OR_RAISE( |
| 74 | auto reader, |
| 75 | OpenORCReader(source, std::make_shared<ScanOptions>(scan_options))); |
| 76 | |
| 77 | auto materialized_fields = scan_options.MaterializedFields(); |
| 78 | // filter out virtual columns |
| 79 | std::vector<std::string> included_fields; |
| 80 | ARROW_ASSIGN_OR_RAISE(auto schema, reader->ReadSchema()); |
| 81 | for (const auto& ref : materialized_fields) { |
| 82 | ARROW_ASSIGN_OR_RAISE(auto match, ref.FindOneOrNone(*schema)); |
| 83 | if (match.indices().empty()) continue; |
| 84 | |
| 85 | included_fields.push_back(schema->field(match.indices()[0])->name()); |
| 86 | } |
| 87 | |
| 88 | std::shared_ptr<RecordBatchReader> record_batch_reader; |
| 89 | ARROW_ASSIGN_OR_RAISE( |
| 90 | record_batch_reader, |
| 91 | reader->GetRecordBatchReader(scan_options.batch_size, included_fields)); |
| 92 | |
| 93 | return RecordBatchIterator(Impl{std::move(record_batch_reader)}); |
| 94 | } |
| 95 | |
| 96 | Result<std::shared_ptr<RecordBatch>> Next() { |
| 97 | std::shared_ptr<RecordBatch> batch; |
| 98 | RETURN_NOT_OK(record_batch_reader_->ReadNext(&batch)); |
| 99 | return batch; |
| 100 | } |
| 101 | |
| 102 | std::shared_ptr<RecordBatchReader> record_batch_reader_; |
| 103 | }; |
| 104 | |
| 105 | return Impl::Make(fragment_->source(), |
| 106 | *checked_pointer_cast<FileFragment>(fragment_)->format(), |
| 107 | *options_); |
| 108 | } |
| 109 | |
| 110 | private: |
| 111 | std::shared_ptr<FileFragment> fragment_; |
no test coverage detected