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

Method ParseLine

cpp/src/arrow/csv/parser.cc:289–521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287 template <typename SpecializedOptions, bool UseBulkFilter, bool IgnoreExtraColumns,
288 typename ValueDescWriter, typename DataWriter, typename BulkFilter>
289 Status ParseLine(ValueDescWriter* values_writer, DataWriter* parsed_writer,
290 const char* data, const char* data_end, bool is_final,
291 const char** out_data, const BulkFilter& bulk_filter) {
292 int32_t num_cols = 0;
293 char c;
294 const auto start = data;
295
296 DCHECK_GT(data_end, data);
297
298 bool ignoring_extra_field = false;
299
300 auto IsExtraField = [&]() {
301 if constexpr (!IgnoreExtraColumns) {
302 return false;
303 }
304 return batch_.num_cols_ >= 0 && num_cols >= batch_.num_cols_;
305 };
306 auto StartField = [&](bool quoted) {
307 if (ARROW_PREDICT_TRUE(ShouldWrite<IgnoreExtraColumns>(ignoring_extra_field))) {
308 if (ARROW_PREDICT_FALSE(IsExtraField())) {
309 ignoring_extra_field = true;
310 } else {
311 values_writer->StartField(quoted);
312 }
313 }
314 };
315 auto FinishField = [&]() {
316 if (ARROW_PREDICT_TRUE(ShouldWrite<IgnoreExtraColumns>(ignoring_extra_field))) {
317 values_writer->FinishField(parsed_writer);
318 }
319 };
320
321 values_writer->BeginLine();
322 parsed_writer->BeginLine();
323
324 // The parsing state machine
325
326 // Special case empty lines: do we start with a newline separator?
327 c = *data;
328 if (ARROW_PREDICT_FALSE(IsControlChar(c))) {
329 if (c == '\r') {
330 data++;
331 if (data < data_end && *data == '\n') {
332 data++;
333 }
334 goto EmptyLine;
335 }
336 if (c == '\n') {
337 data++;
338 goto EmptyLine;
339 }
340 }
341
342 FieldStart:
343 // At the start of a field
344 if (*data == options_.delimiter) {
345 // Empty cells are very common in some files, shortcut them
346 StartField(false /* quoted */);

Callers

nothing calls this directly

Calls 8

IsControlCharFunction · 0.85
StartFieldMethod · 0.80
FinishFieldMethod · 0.80
PushFieldCharMethod · 0.80
push_backMethod · 0.80
OKFunction · 0.50
BeginLineMethod · 0.45
RollbackLineMethod · 0.45

Tested by

no test coverage detected