MCPcopy Create free account
hub / github.com/apache/arrow / operator()

Method operator()

cpp/src/arrow/csv/reader.cc:296–351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

294 }
295
296 Result<TransformFlow<CSVBlock>> operator()(std::shared_ptr<Buffer> next_buffer) {
297 if (buffer_ == nullptr) {
298 // EOF
299 return TransformFinish();
300 }
301
302 bool is_final = (next_buffer == nullptr);
303
304 auto current_partial = std::move(partial_);
305 auto current_buffer = std::move(buffer_);
306 int64_t bytes_skipped = 0;
307
308 if (skip_rows_) {
309 auto orig_size = current_buffer->size();
310 bytes_skipped = current_partial->size();
311 RETURN_NOT_OK(chunker_->ProcessSkip(current_partial, current_buffer, is_final,
312 &skip_rows_, &current_buffer));
313 bytes_skipped += orig_size - current_buffer->size();
314 current_partial = std::make_shared<Buffer>(nullptr, 0);
315 if (skip_rows_) {
316 partial_ = std::move(current_buffer);
317 buffer_ = std::move(next_buffer);
318 return TransformYield<CSVBlock>(CSVBlock{current_partial,
319 current_partial,
320 current_partial,
321 block_index_++,
322 is_final,
323 bytes_skipped,
324 {}});
325 }
326 }
327
328 std::shared_ptr<Buffer> whole, completion, next_partial;
329
330 if (is_final) {
331 // End of file reached => compute completion from penultimate block
332 RETURN_NOT_OK(
333 chunker_->ProcessFinal(current_partial, current_buffer, &completion, &whole));
334 } else {
335 // Get completion of partial from previous block.
336 std::shared_ptr<Buffer> starts_with_whole;
337 // Get completion of partial from previous block.
338 RETURN_NOT_OK(chunker_->ProcessWithPartial(current_partial, current_buffer,
339 &completion, &starts_with_whole));
340
341 // Get a complete CSV block inside `partial + block`, and keep
342 // the rest for the next iteration.
343 RETURN_NOT_OK(chunker_->Process(starts_with_whole, &whole, &next_partial));
344 }
345
346 partial_ = std::move(next_partial);
347 buffer_ = std::move(next_buffer);
348
349 return TransformYield<CSVBlock>(CSVBlock{
350 current_partial, completion, whole, block_index_++, is_final, bytes_skipped, {}});
351 }
352};
353

Callers

nothing calls this directly

Calls 6

TransformFinishClass · 0.85
ProcessSkipMethod · 0.80
ProcessFinalMethod · 0.80
ProcessWithPartialMethod · 0.80
sizeMethod · 0.45
ProcessMethod · 0.45

Tested by

no test coverage detected