| 790 | |
| 791 | template <typename OutType> |
| 792 | std::shared_ptr<CastFunction> GetCastToInteger(std::string name) { |
| 793 | auto func = std::make_shared<CastFunction>(std::move(name), OutType::type_id); |
| 794 | auto out_ty = TypeTraits<OutType>::type_singleton(); |
| 795 | |
| 796 | for (const std::shared_ptr<DataType>& in_ty : IntTypes()) { |
| 797 | DCHECK_OK(func->AddKernel(in_ty->id(), {in_ty}, out_ty, CastIntegerToInteger)); |
| 798 | } |
| 799 | |
| 800 | // Cast from floating point |
| 801 | for (const std::shared_ptr<DataType>& in_ty : FloatingPointTypes()) { |
| 802 | DCHECK_OK(func->AddKernel(in_ty->id(), {in_ty}, out_ty, CastFloatingToInteger)); |
| 803 | } |
| 804 | |
| 805 | // Cast from half-float |
| 806 | DCHECK_OK(func->AddKernel(Type::HALF_FLOAT, {InputType(Type::HALF_FLOAT)}, out_ty, |
| 807 | CastFloatingToInteger)); |
| 808 | |
| 809 | // From other numbers to integer |
| 810 | AddCommonNumberCasts<OutType>(out_ty, func.get()); |
| 811 | |
| 812 | // From decimal to integer |
| 813 | DCHECK_OK(func->AddKernel(Type::DECIMAL, {InputType(Type::DECIMAL)}, out_ty, |
| 814 | CastFunctor<OutType, Decimal128Type>::Exec)); |
| 815 | DCHECK_OK(func->AddKernel(Type::DECIMAL32, {InputType(Type::DECIMAL32)}, out_ty, |
| 816 | CastFunctor<OutType, Decimal32Type>::Exec)); |
| 817 | DCHECK_OK(func->AddKernel(Type::DECIMAL64, {InputType(Type::DECIMAL64)}, out_ty, |
| 818 | CastFunctor<OutType, Decimal64Type>::Exec)); |
| 819 | DCHECK_OK(func->AddKernel(Type::DECIMAL256, {InputType(Type::DECIMAL256)}, out_ty, |
| 820 | CastFunctor<OutType, Decimal256Type>::Exec)); |
| 821 | return func; |
| 822 | } |
| 823 | |
| 824 | template <typename OutType> |
| 825 | std::shared_ptr<CastFunction> GetCastToFloating(std::string name) { |
nothing calls this directly
no test coverage detected