Flushes the result to the insert_chunk.
170340 {
170341 bool continue_processing;
170342 do {
170343 continue_processing = false;
170345
170346 auto &parse_chunk = process_result.ToChunk();
170347 insert_chunk.
Reset();
170348
170350 if (parse_chunk.size() == 0) {
170351 return;
170352 }
170353
170354 insert_chunk.SetCardinality(parse_chunk);
170355
170356
170357 D_ASSERT(csv_file_scan);
170358
170359 auto &names = csv_file_scan->GetNames();
170360
170361 for (
idx_t i = 0; i < csv_file_scan->column_ids.size(); i++) {
170362 idx_t result_idx = i;
170363 if (!csv_file_scan->projection_ids.empty()) {
170364 result_idx = csv_file_scan->projection_ids[i].second;
170365 }
170366 if (i >= parse_chunk.ColumnCount()) {
170367 throw InvalidInputException("Mismatch between the schema of different files");
170368 }
170369 auto &parse_vector = parse_chunk.data[i];
170370 auto &result_vector = insert_chunk.
data[result_idx];
170371 auto &type = result_vector.GetType();
170372 auto &parse_type = parse_vector.GetType();
170373 if (!type.IsJSONType() && (type == LogicalType::VARCHAR ||
170374 (type != LogicalType::VARCHAR && parse_type != LogicalType::VARCHAR))) {
170375
170376 result_vector.Reinterpret(parse_vector);
170377 } else {
170378 string error_message;
170379 idx_t line_error = 0;
170381 &error_message, false, true)) {
170382 continue;
170383 }
170384
170385 UnifiedVectorFormat inserted_column_data;
170386 result_vector.ToUnifiedFormat(parse_chunk.size(), inserted_column_data);
170387 UnifiedVectorFormat parse_column_data;
170388 parse_vector.ToUnifiedFormat(parse_chunk.size(), parse_column_data);
170389
170390 for (; line_error < parse_chunk.size(); line_error++) {
170391 if (!inserted_column_data.validity.RowIsValid(line_error) &&
170392 parse_column_data.validity.RowIsValid(line_error)) {
170393 break;
170394 }
170395 }
170396 {
170398 vector<Value> row;
170399 for (
idx_t col = 0; col < parse_chunk.ColumnCount(); col++) {
170400 row.push_back(parse_chunk.GetValue(col, line_error));
170401 }
170402 }
170404 LinesPerBoundary lines_per_batch(
iterator.GetBoundaryIdx(),
170405 lines_read - parse_chunk.size() + line_error);
170406 bool first_nl = false;
170407 auto borked_line = result.line_positions_per_row[line_error].ReconstructCurrentLine(
170408 first_nl, result.buffer_handles, result.PrintErrorLine());
170409 std::ostringstream error;
170410 error << "Could not convert string \"" << parse_vector.GetValue(line_error) << "\" to \'"
170411 << type.ToString() << "\'";
170412 string error_msg = error.str();
170413 FullLinePosition::SanitizeError(error_msg);
170414 idx_t row_byte_pos = 0;
170415 if (!(result.line_positions_per_row[line_error].begin ==
170416 result.line_positions_per_row[line_error].end)) {
170417 row_byte_pos = result.line_positions_per_row[line_error].begin.GetGlobalPosition(
170418 result.result_size, first_nl);
170419 }
170421 state_machine->options, names[i], error_msg, i, borked_line, lines_per_batch, row_byte_pos,
170422 optional_idx::Invalid(), result_vector.GetType().id(), result.path);
170424 }
170425 }
170426 result.borked_rows.insert(line_error++);
170427 D_ASSERT(
state_machine->options.ignore_errors.GetValue());
170428
170429 for (; line_error < parse_chunk.size(); line_error++) {
170430 if (!inserted_column_data.validity.RowIsValid(line_error) &&
170431 parse_column_data.validity.RowIsValid(line_error)) {
170432 result.borked_rows.insert(line_error);
170433 vector<Value> row;
170434 for (
idx_t col = 0; col < parse_chunk.ColumnCount(); col++) {
170435 row.push_back(parse_chunk.GetValue(col, line_error));
170436 }
170438 LinesPerBoundary lines_per_batch(
iterator.GetBoundaryIdx(),
170439 lines_read - parse_chunk.size() + line_error);
170440 bool first_nl = false;
170441 auto borked_line = result.line_positions_per_row[line_error].ReconstructCurrentLine(
170442 first_nl, result.buffer_handles, result.PrintErrorLine());
170443 std::ostringstream error;
170444
170445 error << "Could not convert string \"" << parse_vector.GetValue(line_error) << "\" to \'"
170446 << LogicalTypeIdToString(type.id()) << "\'";
170447 string error_msg = error.str();
170448 FullLinePosition::SanitizeError(error_msg);
170450 state_machine->options, names[i], error_msg, i, borked_line, lines_per_batch,
170451 result.line_positions_per_row[line_error].begin.GetGlobalPosition(result.result_size,
170452 first_nl),
170453 optional_idx::Invalid(), result_vector.GetType().id(), result.path);
170455 }
170456 }
170457 }
170458 }
170459 }
170460 if (!result.borked_rows.empty()) {
170461
170462 SelectionVector successful_rows(parse_chunk.size());
170463 idx_t sel_idx = 0;
170464 for (
idx_t row_idx = 0; row_idx < parse_chunk.size(); row_idx++) {
170465 if (result.borked_rows.find(row_idx) == result.borked_rows.end()) {
170466 successful_rows.set_index(sel_idx++, row_idx);
170467 }
170468 }
170469
170470 insert_chunk.Slice(successful_rows, sel_idx);
170471 result.borked_rows.clear();
170472 }
170479 }
170480 } else {
170482 }
170483 if (
iterator.pos.buffer_pos < to_pos) {
170484
170485
170486 continue_processing = true;
170487 }
170488 }
170489 } while (continue_processing);
170490}
static CSVError CastError(const CSVReaderOptions &options, const string &column_name, string &cast_error, idx_t column_idx, string &csv_row, LinesPerBoundary error_info, idx_t row_byte_position, optional_idx byte_position, LogicalTypeId type, const String ¤t_path)
Produces error messages for casting errors.
Definition duckdb.cpp:175857
DUCKDB_API void Reset()
Definition duckdb.cpp:116840
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
StringValueResult & ParseChunk() override
Parses data into an output_chunk.
Definition duckdb.cpp:170334
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static DUCKDB_API bool TryCast(CastFunctionSet &set, GetCastFunctionInput &input, Vector &source, Vector &result, idx_t count, string *error_message, bool strict=false, const bool nullify_parent=false)
Definition duckdb.cpp:143445