| 114 | } |
| 115 | |
| 116 | static Future<std::shared_ptr<FragmentScanner>> Make( |
| 117 | const CsvFragmentScanOptions& csv_options, const FragmentScanRequest& scan_request, |
| 118 | const CsvInspectedFragment& inspected_fragment, Executor* cpu_executor) { |
| 119 | auto read_options = csv_options.read_options; |
| 120 | |
| 121 | int num_batches = static_cast<int>(bit_util::CeilDiv( |
| 122 | inspected_fragment.num_bytes, static_cast<int64_t>(read_options.block_size))); |
| 123 | // Could be better, but a reasonable starting point. CSV presumably takes up more |
| 124 | // space than an in-memory format so this should be conservative. |
| 125 | int64_t best_guess_bytes_per_batch = read_options.block_size; |
| 126 | ARROW_ASSIGN_OR_RAISE( |
| 127 | csv::ConvertOptions convert_options, |
| 128 | GetConvertOptions(csv_options, scan_request, inspected_fragment)); |
| 129 | |
| 130 | return csv::StreamingReader::MakeAsync( |
| 131 | io::default_io_context(), inspected_fragment.input_stream, cpu_executor, |
| 132 | read_options, csv_options.parse_options, convert_options) |
| 133 | .Then([num_batches, best_guess_bytes_per_batch]( |
| 134 | const std::shared_ptr<csv::StreamingReader>& reader) |
| 135 | -> std::shared_ptr<FragmentScanner> { |
| 136 | return std::make_shared<CsvFileScanner>(reader, num_batches, |
| 137 | best_guess_bytes_per_batch); |
| 138 | }); |
| 139 | } |
| 140 | |
| 141 | private: |
| 142 | std::shared_ptr<csv::StreamingReader> reader_; |