| 1 | #include "duckdb/function/cast/default_casts.hpp" |
| 2 | #include "duckdb/function/cast/vector_cast_helpers.hpp" |
| 3 | #include "duckdb/common/operator/string_cast.hpp" |
| 4 | #include "duckdb/common/operator/numeric_cast.hpp" |
| 5 | |
| 6 | namespace duckdb { |
| 7 | |
| 8 | template <class SRC> |
| 9 | static BoundCastInfo InternalNumericCastSwitch(const LogicalType &source, const LogicalType &target) { |
| 10 | // now switch on the result type |
| 11 | switch (target.id()) { |
| 12 | case LogicalTypeId::BOOLEAN: |
| 13 | return BoundCastInfo(&VectorCastHelpers::TryCastLoop<SRC, bool, duckdb::NumericTryCast>); |
| 14 | case LogicalTypeId::TINYINT: |
| 15 | return BoundCastInfo(&VectorCastHelpers::TryCastLoop<SRC, int8_t, duckdb::NumericTryCast>); |
| 16 | case LogicalTypeId::SMALLINT: |
| 17 | return BoundCastInfo(&VectorCastHelpers::TryCastLoop<SRC, int16_t, duckdb::NumericTryCast>); |
| 18 | case LogicalTypeId::INTEGER: |
| 19 | return BoundCastInfo(&VectorCastHelpers::TryCastLoop<SRC, int32_t, duckdb::NumericTryCast>); |
| 20 | case LogicalTypeId::BIGINT: |
| 21 | return BoundCastInfo(&VectorCastHelpers::TryCastLoop<SRC, int64_t, duckdb::NumericTryCast>); |
| 22 | case LogicalTypeId::UTINYINT: |
| 23 | return BoundCastInfo(&VectorCastHelpers::TryCastLoop<SRC, uint8_t, duckdb::NumericTryCast>); |
| 24 | case LogicalTypeId::USMALLINT: |
| 25 | return BoundCastInfo(&VectorCastHelpers::TryCastLoop<SRC, uint16_t, duckdb::NumericTryCast>); |
| 26 | case LogicalTypeId::UINTEGER: |
| 27 | return BoundCastInfo(&VectorCastHelpers::TryCastLoop<SRC, uint32_t, duckdb::NumericTryCast>); |
| 28 | case LogicalTypeId::UBIGINT: |
| 29 | return BoundCastInfo(&VectorCastHelpers::TryCastLoop<SRC, uint64_t, duckdb::NumericTryCast>); |
| 30 | case LogicalTypeId::HUGEINT: |
| 31 | return BoundCastInfo(&VectorCastHelpers::TryCastLoop<SRC, hugeint_t, duckdb::NumericTryCast>); |
| 32 | case LogicalTypeId::FLOAT: |
| 33 | return BoundCastInfo(&VectorCastHelpers::TryCastLoop<SRC, float, duckdb::NumericTryCast>); |
| 34 | case LogicalTypeId::DOUBLE: |
| 35 | return BoundCastInfo(&VectorCastHelpers::TryCastLoop<SRC, double, duckdb::NumericTryCast>); |
| 36 | case LogicalTypeId::DECIMAL: |
| 37 | return BoundCastInfo(&VectorCastHelpers::ToDecimalCast<SRC>); |
| 38 | case LogicalTypeId::VARCHAR: |
| 39 | return BoundCastInfo(&VectorCastHelpers::StringCast<SRC, duckdb::StringCast>); |
| 40 | default: |
| 41 | return DefaultCasts::TryVectorNullCast; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | BoundCastInfo DefaultCasts::NumericCastSwitch(BindCastInput &input, const LogicalType &source, |
| 46 | const LogicalType &target) { |
| 47 | switch (source.id()) { |
| 48 | case LogicalTypeId::BOOLEAN: |
| 49 | return InternalNumericCastSwitch<bool>(source, target); |
| 50 | case LogicalTypeId::TINYINT: |
| 51 | return InternalNumericCastSwitch<int8_t>(source, target); |
| 52 | case LogicalTypeId::SMALLINT: |
| 53 | return InternalNumericCastSwitch<int16_t>(source, target); |
| 54 | case LogicalTypeId::INTEGER: |
| 55 | return InternalNumericCastSwitch<int32_t>(source, target); |
| 56 | case LogicalTypeId::BIGINT: |
| 57 | return InternalNumericCastSwitch<int64_t>(source, target); |
| 58 | case LogicalTypeId::UTINYINT: |
| 59 | return InternalNumericCastSwitch<uint8_t>(source, target); |
| 60 | case LogicalTypeId::USMALLINT: |
| 61 | return InternalNumericCastSwitch<uint16_t>(source, target); |
| 62 | case LogicalTypeId::UINTEGER: |
| 63 | return InternalNumericCastSwitch<uint32_t>(source, target); |
| 64 | case LogicalTypeId::UBIGINT: |
| 65 | return InternalNumericCastSwitch<uint64_t>(source, target); |
| 66 | case LogicalTypeId::HUGEINT: |
| 67 | return InternalNumericCastSwitch<hugeint_t>(source, target); |
| 68 | case LogicalTypeId::FLOAT: |
| 69 | return InternalNumericCastSwitch<float>(source, target); |
| 70 | case LogicalTypeId::DOUBLE: |
| 71 | return InternalNumericCastSwitch<double>(source, target); |
| 72 | default: |
| 73 | throw InternalException("NumericCastSwitch called with non-numeric argument" ); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | } // namespace duckdb |
| 78 | |