| 945 | } |
| 946 | |
| 947 | std::shared_ptr<CastFunction> GetCastToDecimal128() { |
| 948 | OutputType sig_out_ty(ResolveOutputFromOptions); |
| 949 | |
| 950 | auto func = std::make_shared<CastFunction>("cast_decimal", Type::DECIMAL128); |
| 951 | AddCommonCasts(Type::DECIMAL128, sig_out_ty, func.get()); |
| 952 | |
| 953 | // Cast from floating point |
| 954 | DCHECK_OK(func->AddKernel(Type::FLOAT, {float32()}, sig_out_ty, |
| 955 | CastFunctor<Decimal128Type, FloatType>::Exec)); |
| 956 | DCHECK_OK(func->AddKernel(Type::DOUBLE, {float64()}, sig_out_ty, |
| 957 | CastFunctor<Decimal128Type, DoubleType>::Exec)); |
| 958 | |
| 959 | // Cast from integer |
| 960 | for (const std::shared_ptr<DataType>& in_ty : IntTypes()) { |
| 961 | auto exec = GenerateInteger<CastFunctor, Decimal128Type>(in_ty->id()); |
| 962 | DCHECK_OK(func->AddKernel(in_ty->id(), {in_ty}, sig_out_ty, std::move(exec))); |
| 963 | } |
| 964 | |
| 965 | // Cast from other strings |
| 966 | for (const std::shared_ptr<DataType>& in_ty : BaseBinaryTypes()) { |
| 967 | auto exec = GenerateVarBinaryBase<CastFunctor, Decimal128Type>(in_ty->id()); |
| 968 | DCHECK_OK(func->AddKernel(in_ty->id(), {in_ty}, sig_out_ty, std::move(exec))); |
| 969 | } |
| 970 | for (const std::shared_ptr<DataType>& in_ty : BinaryViewTypes()) { |
| 971 | auto exec = GenerateVarBinaryViewBase<CastFunctor, Decimal128Type>(in_ty->id()); |
| 972 | DCHECK_OK(func->AddKernel(in_ty->id(), {in_ty}, sig_out_ty, std::move(exec))); |
| 973 | } |
| 974 | |
| 975 | // Cast from other decimal |
| 976 | auto exec = CastFunctor<Decimal128Type, Decimal32Type>::Exec; |
| 977 | // We resolve the output type of this kernel from the CastOptions |
| 978 | DCHECK_OK( |
| 979 | func->AddKernel(Type::DECIMAL32, {InputType(Type::DECIMAL32)}, sig_out_ty, exec)); |
| 980 | exec = CastFunctor<Decimal128Type, Decimal64Type>::Exec; |
| 981 | DCHECK_OK( |
| 982 | func->AddKernel(Type::DECIMAL64, {InputType(Type::DECIMAL64)}, sig_out_ty, exec)); |
| 983 | exec = CastFunctor<Decimal128Type, Decimal128Type>::Exec; |
| 984 | DCHECK_OK( |
| 985 | func->AddKernel(Type::DECIMAL128, {InputType(Type::DECIMAL128)}, sig_out_ty, exec)); |
| 986 | exec = CastFunctor<Decimal128Type, Decimal256Type>::Exec; |
| 987 | DCHECK_OK( |
| 988 | func->AddKernel(Type::DECIMAL256, {InputType(Type::DECIMAL256)}, sig_out_ty, exec)); |
| 989 | return func; |
| 990 | } |
| 991 | |
| 992 | std::shared_ptr<CastFunction> GetCastToDecimal256() { |
| 993 | OutputType sig_out_ty(ResolveOutputFromOptions); |
no test coverage detected