173463 {
173464 if (is_null) {
173465 return true;
173466 }
173467 auto value_ptr = value.GetData();
173468 auto value_size = value.GetSize();
173469 string strip_thousands;
173470 if (type.IsNumeric() && thousands_separator != '\0') {
173471
173473 value_ptr = strip_thousands.c_str();
173474 value_size = strip_thousands.size();
173475 }
173476 switch (type.id()) {
173477 case LogicalTypeId::BOOLEAN: {
173478 bool dummy_value;
173479 return TryCastStringBool(value_ptr, value_size, dummy_value, true);
173480 }
173481 case LogicalTypeId::TINYINT: {
173483 return TrySimpleIntegerCast(value_ptr, value_size, dummy_value, false);
173484 }
173485 case LogicalTypeId::SMALLINT: {
173487 return TrySimpleIntegerCast(value_ptr, value_size, dummy_value, true);
173488 }
173489 case LogicalTypeId::INTEGER: {
173491 return TrySimpleIntegerCast(value_ptr, value_size, dummy_value, true);
173492 }
173493 case LogicalTypeId::BIGINT: {
173495 return TrySimpleIntegerCast(value_ptr, value_size, dummy_value, true);
173496 }
173497 case LogicalTypeId::UTINYINT: {
173499 return TrySimpleIntegerCast(value_ptr, value_size, dummy_value, true);
173500 }
173501 case LogicalTypeId::USMALLINT: {
173503 return TrySimpleIntegerCast(value_ptr, value_size, dummy_value, true);
173504 }
173505 case LogicalTypeId::UINTEGER: {
173507 return TrySimpleIntegerCast(value_ptr, value_size, dummy_value, true);
173508 }
173509 case LogicalTypeId::UBIGINT: {
173511 return TrySimpleIntegerCast(value_ptr, value_size, dummy_value, true);
173512 }
173513 case LogicalTypeId::DOUBLE: {
173514 double dummy_value;
173515 return TryDoubleCast<double>(value_ptr, value_size, dummy_value, true, decimal_separator);
173516 }
173517 case LogicalTypeId::FLOAT: {
173518 float dummy_value;
173519 return TryDoubleCast<float>(value_ptr, value_size, dummy_value, true, decimal_separator);
173520 }
173521 case LogicalTypeId::DATE: {
173522 if (!dialect_options.date_format.find(LogicalTypeId::DATE)->second.GetValue().Empty()) {
173523 date_t result;
173524 string error_message;
173525 return dialect_options.date_format.find(LogicalTypeId::DATE)
173526 ->second.GetValue()
173527 .TryParseDate(value, result, error_message);
173528 }
173530 bool special;
173531 date_t dummy_value;
173532 return Date::TryConvertDate(value_ptr, value_size, pos, dummy_value, special,
true) == DateCastResult::SUCCESS;
173533 }
173534 case LogicalTypeId::TIMESTAMP: {
173535 timestamp_t dummy_value;
173536 if (!dialect_options.date_format.find(LogicalTypeId::TIMESTAMP)->second.GetValue().Empty()) {
173537 string error_message;
173538 return dialect_options.date_format.find(LogicalTypeId::TIMESTAMP)
173539 ->second.GetValue()
173540 .TryParseTimestamp(value, dummy_value, error_message);
173541 }
173543 TimestampCastResult::SUCCESS;
173544 }
173545 case LogicalTypeId::TIME: {
173547 dtime_t dummy_value;
173548 return Time::TryConvertTime(value_ptr, value_size, pos, dummy_value, true);
173549 }
173550 case LogicalTypeId::DECIMAL: {
173552 type.GetDecimalProperties(width, scale);
173553 if (decimal_separator == ',') {
173554 switch (type.InternalType()) {
173557 return TryDecimalStringCast<int16_t, ','>(value_ptr, value_size, dummy_value, width, scale);
173558 }
173559
173562 return TryDecimalStringCast<int32_t, ','>(value_ptr, value_size, dummy_value, width, scale);
173563 }
173564
173567 return TryDecimalStringCast<int64_t, ','>(value_ptr, value_size, dummy_value, width, scale);
173568 }
173569
173570 case PhysicalType::INT128: {
173571 hugeint_t dummy_value;
173572 return TryDecimalStringCast<hugeint_t, ','>(value_ptr, value_size, dummy_value, width, scale);
173573 }
173574
173575 default:
173576 throw InternalException("Invalid Physical Type for Decimal Value. Physical Type: " +
173577 TypeIdToString(type.InternalType()));
173578 }
173579
173580 } else if (decimal_separator == '.') {
173581 switch (type.InternalType()) {
173584 return TryDecimalStringCast(value_ptr, value_size, dummy_value, width, scale);
173585 }
173586
173589 return TryDecimalStringCast(value_ptr, value_size, dummy_value, width, scale);
173590 }
173591
173594 return TryDecimalStringCast(value_ptr, value_size, dummy_value, width, scale);
173595 }
173596
173597 case PhysicalType::INT128: {
173598 hugeint_t dummy_value;
173599 return TryDecimalStringCast(value_ptr, value_size, dummy_value, width, scale);
173600 }
173601
173602 default:
173603 throw InternalException("Invalid Physical Type for Decimal Value. Physical Type: " +
173604 TypeIdToString(type.InternalType()));
173605 }
173606 }
173607 throw InvalidInputException("Decimals can only have ',' and '.' as decimal separators");
173608 }
173609 case LogicalTypeId::VARCHAR:
173610 return true;
173611 default: {
173612
173613 Value new_value;
173614 string error_message;
173615 Value str_value(value);
173616 bool success = str_value.TryCastAs(context, type, new_value, &error_message, true);
173617 return success && error_message.empty();
173618 }
173619 }
173620}
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
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
void scale(cv::Mat &mat, const cv::Mat &range, const T min, const T max)
@ 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