169509 {
169510 if (HandleTooManyColumnsError(value_ptr, size)) {
169511 return;
169512 }
169514 if (!state_machine.state_machine_options.strict_mode.GetValue()) {
169515 used_unstrictness = true;
169516 return;
169517 }
169518 bool error = true;
169520
169521 bool is_value_null = false;
169522 for (
idx_t i = 0; i < null_str_count; i++) {
169523 is_value_null = is_value_null || IsValueNull(null_str_ptr[i], value_ptr, size);
169524 }
169525 error = !is_value_null;
169526 }
169527 if (error) {
169528
169530 cur_col_id++;
169531 }
169532 return;
169533 }
169534
169535 if (projecting_columns) {
169537 cur_col_id++;
169538 return;
169539 }
169540 }
169541
169542 if (((
quoted && state_machine.options.allow_quoted_nulls) || !
quoted)) {
169543
169544 const bool check_unquoted_escaped_null =
169545 state_machine.state_machine_options.strict_mode.GetValue() ==
false &&
escaped && !
quoted &&
size == 1;
169546 for (
idx_t i = 0; i < null_str_count; i++) {
169547 bool is_null = false;
169548 if (null_str_size[i] == 2 && null_str_ptr[i][0] == state_machine.state_machine_options.escape.GetValue()) {
169549 is_null = check_unquoted_escaped_null && null_str_ptr[i][1] == value_ptr[0];
169550 } else if (size == null_str_size[i] && !check_unquoted_escaped_null) {
169551 is_null = IsValueNull(null_str_ptr[i], value_ptr, size);
169552 }
169553 if (is_null) {
169554 bool empty = false;
169555 if (chunk_col_id < state_machine.options.force_not_null.size()) {
169556 empty = state_machine.options.force_not_null[chunk_col_id];
169557 }
169558 if (empty) {
169559 if (parse_types[chunk_col_id].type_id != LogicalTypeId::VARCHAR) {
169560
169561 current_errors.Insert(CAST_ERROR, cur_col_id, chunk_col_id, last_position);
169562 } else {
169563 static_cast<string_t *
>(
vector_ptr[chunk_col_id])[number_of_rows] = string_t();
169564 }
169565 } else {
169567
169568 return;
169569 }
169570 validity_mask[chunk_col_id]->SetInvalid(
static_cast<idx_t>(number_of_rows));
169571 }
169572 cur_col_id++;
169573 chunk_col_id++;
169574 return;
169575 }
169576 }
169577 }
169578 bool success = true;
169579 string strip_thousands;
169580 if (LogicalType::IsNumeric(parse_types[chunk_col_id].type_id) &&
169581 state_machine.options.thousands_separator != '\0') {
169582
169584 value_ptr = strip_thousands.c_str();
169585 size = strip_thousands.size();
169586 }
169587 switch (parse_types[chunk_col_id].type_id) {
169588 case LogicalTypeId::BOOLEAN:
169589 success =
169590 TryCastStringBool(value_ptr, size,
static_cast<bool *
>(
vector_ptr[chunk_col_id])[number_of_rows],
false);
169591 break;
169592 case LogicalTypeId::TINYINT:
169593 success = TrySimpleIntegerCast(value_ptr, size,
static_cast<int8_t *
>(
vector_ptr[chunk_col_id])[number_of_rows],
169594 false);
169595 break;
169596 case LogicalTypeId::SMALLINT:
169597 success = TrySimpleIntegerCast(value_ptr, size,
169599 break;
169600 case LogicalTypeId::INTEGER:
169601 success = TrySimpleIntegerCast(value_ptr, size,
169603 break;
169604 case LogicalTypeId::BIGINT:
169605 success = TrySimpleIntegerCast(value_ptr, size,
169607 break;
169608 case LogicalTypeId::UTINYINT:
169609 success = TrySimpleIntegerCast<uint8_t, false>(
169610 value_ptr, size,
static_cast<uint8_t *
>(
vector_ptr[chunk_col_id])[number_of_rows],
false);
169611 break;
169612 case LogicalTypeId::USMALLINT:
169613 success = TrySimpleIntegerCast<uint16_t, false>(
169614 value_ptr, size,
static_cast<uint16_t *
>(
vector_ptr[chunk_col_id])[number_of_rows],
false);
169615 break;
169616 case LogicalTypeId::UINTEGER:
169617 success = TrySimpleIntegerCast<uint32_t, false>(
169618 value_ptr, size,
static_cast<uint32_t *
>(
vector_ptr[chunk_col_id])[number_of_rows],
false);
169619 break;
169620 case LogicalTypeId::UBIGINT:
169621 success = TrySimpleIntegerCast<uint64_t, false>(
169622 value_ptr, size,
static_cast<uint64_t *
>(
vector_ptr[chunk_col_id])[number_of_rows],
false);
169623 break;
169624 case LogicalTypeId::DOUBLE:
169625 success =
169626 TryDoubleCast<double>(value_ptr, size,
static_cast<double *
>(
vector_ptr[chunk_col_id])[number_of_rows],
169627 false, state_machine.options.decimal_separator[0]);
169628 break;
169629 case LogicalTypeId::FLOAT:
169630 success = TryDoubleCast<float>(value_ptr, size,
static_cast<float *
>(
vector_ptr[chunk_col_id])[number_of_rows],
169631 false, state_machine.options.decimal_separator[0]);
169632 break;
169633 case LogicalTypeId::DATE: {
169634 if (!date_format.Empty()) {
169635 success = date_format.TryParseDate(value_ptr, size,
169636 static_cast<date_t *
>(
vector_ptr[chunk_col_id])[number_of_rows]);
169637 } else {
169639 bool special;
169641 static_cast<date_t *
>(
vector_ptr[chunk_col_id])[number_of_rows], special,
169642 false) == DateCastResult::SUCCESS;
169643 }
169644 break;
169645 }
169646 case LogicalTypeId::TIME: {
169648 success = Time::TryConvertTime(value_ptr, size, pos,
169649 static_cast<dtime_t *
>(
vector_ptr[chunk_col_id])[number_of_rows],
false);
169650 break;
169651 }
169652 case LogicalTypeId::TIMESTAMP:
169653 case LogicalTypeId::TIMESTAMP_TZ: {
169654 if (!timestamp_format.Empty()) {
169655 success = timestamp_format.TryParseTimestamp(
169656 value_ptr, size,
static_cast<timestamp_t *
>(
vector_ptr[chunk_col_id])[number_of_rows]);
169657 } else {
169658 const bool use_offset = (parse_types[chunk_col_id].type_id == LogicalTypeId::TIMESTAMP_TZ);
169660 value_ptr, size,
static_cast<timestamp_t *
>(
vector_ptr[chunk_col_id])[number_of_rows],
169661 use_offset) == TimestampCastResult::SUCCESS;
169662 }
169663 break;
169664 }
169665 case LogicalTypeId::DECIMAL: {
169666 if (decimal_separator == ',') {
169667 switch (parse_types[chunk_col_id].internal_type) {
169669 success = TryDecimalStringCast<int16_t, ','>(
169670 value_ptr, size,
static_cast<int16_t *
>(
vector_ptr[chunk_col_id])[number_of_rows],
169671 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169672 break;
169674 success = TryDecimalStringCast<int32_t, ','>(
169675 value_ptr, size,
static_cast<int32_t *
>(
vector_ptr[chunk_col_id])[number_of_rows],
169676 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169677 break;
169679 success = TryDecimalStringCast<int64_t, ','>(
169680 value_ptr, size,
static_cast<int64_t *
>(
vector_ptr[chunk_col_id])[number_of_rows],
169681 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169682 break;
169683 case PhysicalType::INT128:
169684 success = TryDecimalStringCast<hugeint_t, ','>(
169685 value_ptr, size,
static_cast<hugeint_t *
>(
vector_ptr[chunk_col_id])[number_of_rows],
169686 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169687 break;
169688 default:
169689 throw InternalException("Invalid Physical Type for Decimal Value. Physical Type: " +
169690 TypeIdToString(parse_types[chunk_col_id].internal_type));
169691 }
169692
169693 } else if (decimal_separator == '.') {
169694 switch (parse_types[chunk_col_id].internal_type) {
169696 success = TryDecimalStringCast(value_ptr, size,
169698 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169699 break;
169701 success = TryDecimalStringCast(value_ptr, size,
169703 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169704 break;
169706 success = TryDecimalStringCast(value_ptr, size,
169708 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169709 break;
169710 case PhysicalType::INT128:
169711 success = TryDecimalStringCast(value_ptr, size,
169712 static_cast<hugeint_t *
>(
vector_ptr[chunk_col_id])[number_of_rows],
169713 parse_types[chunk_col_id].width, parse_types[chunk_col_id].scale);
169714 break;
169715 default:
169716 throw InternalException("Invalid Physical Type for Decimal Value. Physical Type: " +
169717 TypeIdToString(parse_types[chunk_col_id].internal_type));
169718 }
169719 } else {
169720 throw InvalidInputException("Decimals can only have ',' and '.' as decimal separators");
169721 }
169722 break;
169723 }
169724 default: {
169725
169726
169727 if (parse_types[chunk_col_id].validate_utf8 &&
169729 bool force_error = !state_machine.options.ignore_errors.GetValue() && sniffing;
169730
169731 if (force_error) {
169733 }
169734
169737 parse_chunk.data[chunk_col_id], string_t(value_ptr, UnsafeNumericCast<uint32_t>(0)));
169738 break;
169739 }
169740 if (allocate) {
169741
169743 parse_chunk.data[chunk_col_id], string_t(value_ptr, UnsafeNumericCast<uint32_t>(size)));
169744 } else {
169745 static_cast<string_t *
>(
vector_ptr[chunk_col_id])[number_of_rows] =
169746 string_t(value_ptr, UnsafeNumericCast<uint32_t>(size));
169747 }
169748 break;
169749 }
169750 }
169751 if (!success) {
169752 current_errors.Insert(CAST_ERROR, cur_col_id, chunk_col_id, last_position);
169753 if (!state_machine.options.IgnoreErrors()) {
169754
169755 std::ostringstream error;
169756
169757 error << "Could not convert string \"" << std::string(value_ptr, size) << "\" to \'"
169758 << LogicalTypeIdToString(parse_types[chunk_col_id].type_id) << "\'";
169759 auto error_string = error.str();
169760 FullLinePosition::SanitizeError(error_string);
169761
169763 }
169764 }
169765 cur_col_id++;
169766 chunk_col_id++;
169767}
static string RemoveSeparator(const char *value_ptr, const idx_t size, char thousands_separator)
Removes thousands separator.
Definition duckdb.cpp:168369
static DUCKDB_API DateCastResult TryConvertDate(const char *buf, idx_t len, idx_t &pos, date_t &result, bool &special, bool strict=false)
Definition duckdb.cpp:117363
bool escaped
If the current value has been escaped.
Definition duckdb.cpp:167224
void HandleUnicodeError(idx_t col_idx, LinePosition &error_position)
Force the throw of a Unicode error.
Definition duckdb.cpp:169936
static DUCKDB_API TimestampCastResult TryConvertTimestamp(const char *str, idx_t len, timestamp_t &result, const bool use_offset, optional_ptr< int32_t > nanos=nullptr, bool strict=false)
Strict Timestamp does not accept offsets.
Definition duckdb.cpp:129558
static bool IsValid(const char *s, size_t len)
Returns whether or not the UTF8 string is valid.
Definition duckdb.cpp:507383
@ INT64
Signed 64-bit little-endian integer.
Definition duckdb.hpp:2767
@ INT16
Signed 16-bit little-endian integer.
Definition duckdb.hpp:2755
@ INT32
Signed 32-bit little-endian integer.
Definition duckdb.hpp:2761
@ INVALID_ENCODING
If the null_padding option is set, and we have quoted new values in parallel.
Definition duckdb.cpp:166193
static DUCKDB_API string_t AddStringOrBlob(Vector &vector, const char *data, idx_t len)
Definition duckdb.cpp:137893