From 4448bacb2f4b4af159eaf91a09aa87f7f5d66ce6 Mon Sep 17 00:00:00 2001 From: Zhigao Tong Date: Tue, 24 May 2022 13:56:46 +0800 Subject: [PATCH] Remove useless template instantiations (#4978) ref pingcap/tiflash#4909 --- .../src/Functions/FunctionsTiDBConversion.cpp | 15 ++ dbms/src/Functions/FunctionsTiDBConversion.h | 20 +-- .../Functions/tests/gtest_tidb_conversion.cpp | 146 +++++++++--------- 3 files changed, 94 insertions(+), 87 deletions(-) diff --git a/dbms/src/Functions/FunctionsTiDBConversion.cpp b/dbms/src/Functions/FunctionsTiDBConversion.cpp index 75c015c4bad..74daca2b7fe 100644 --- a/dbms/src/Functions/FunctionsTiDBConversion.cpp +++ b/dbms/src/Functions/FunctionsTiDBConversion.cpp @@ -46,4 +46,19 @@ void registerFunctionsTiDBConversion(FunctionFactory & factory) factory.registerFunction(); } +FunctionBasePtr FunctionBuilderTiDBCast::buildImpl( + const ColumnsWithTypeAndName & arguments, + const DataTypePtr & return_type, + const TiDB::TiDBCollatorPtr &) const +{ + DataTypes data_types(arguments.size()); + + for (size_t i = 0; i < arguments.size(); ++i) + data_types[i] = arguments[i].type; + + auto monotonicity = getMonotonicityInformation(arguments.front().type, return_type.get()); + return std::make_shared>(context, name, std::move(monotonicity), data_types, return_type, in_union, tidb_tp); +} + + } // namespace DB diff --git a/dbms/src/Functions/FunctionsTiDBConversion.h b/dbms/src/Functions/FunctionsTiDBConversion.h index 30251aac36d..bcd7856ee71 100644 --- a/dbms/src/Functions/FunctionsTiDBConversion.h +++ b/dbms/src/Functions/FunctionsTiDBConversion.h @@ -1743,6 +1743,7 @@ inline bool numberToDateTime(Int64 number, MyDateTime & result, DAGContext * ctx return getDatetime(number, result, ctx); } +template class ExecutableFunctionTiDBCast : public IExecutableFunction { public: @@ -1782,13 +1783,15 @@ class ExecutableFunctionTiDBCast : public IExecutableFunction const Context & context; }; +using MonotonicityForRange = std::function; + /// FunctionTiDBCast implements SQL cast function in TiDB /// The basic idea is to dispatch according to combinations of parameter types +template class FunctionTiDBCast final : public IFunctionBase { public: using WrapperType = std::function; - using MonotonicityForRange = std::function; FunctionTiDBCast(const Context & context, const char * name, MonotonicityForRange && monotonicity_for_range, const DataTypes & argument_types, const DataTypePtr & return_type, bool in_union_, const tipb::FieldType & tidb_tp_) : context(context) @@ -1805,7 +1808,7 @@ class FunctionTiDBCast final : public IFunctionBase ExecutableFunctionPtr prepare(const Block & /*sample_block*/) const override { - return std::make_shared( + return std::make_shared>( prepare(getArgumentTypes()[0], getReturnType()), name, in_union, @@ -2341,8 +2344,6 @@ class FunctionTiDBCast final : public IFunctionBase class FunctionBuilderTiDBCast : public IFunctionBuilder { public: - using MonotonicityForRange = FunctionTiDBCast::MonotonicityForRange; - static constexpr auto name = "tidb_cast"; static FunctionBuilderPtr create(const Context & context) { @@ -2369,16 +2370,7 @@ class FunctionBuilderTiDBCast : public IFunctionBuilder FunctionBasePtr buildImpl( const ColumnsWithTypeAndName & arguments, const DataTypePtr & return_type, - const TiDB::TiDBCollatorPtr &) const override - { - DataTypes data_types(arguments.size()); - - for (size_t i = 0; i < arguments.size(); ++i) - data_types[i] = arguments[i].type; - - auto monotonicity = getMonotonicityInformation(arguments.front().type, return_type.get()); - return std::make_shared(context, name, std::move(monotonicity), data_types, return_type, in_union, tidb_tp); - } + const TiDB::TiDBCollatorPtr &) const override; // use the last const string column's value as the return type name, in string representation like "Float64" DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override diff --git a/dbms/src/Functions/tests/gtest_tidb_conversion.cpp b/dbms/src/Functions/tests/gtest_tidb_conversion.cpp index d67ef49e108..5f885c2716f 100644 --- a/dbms/src/Functions/tests/gtest_tidb_conversion.cpp +++ b/dbms/src/Functions/tests/gtest_tidb_conversion.cpp @@ -1474,76 +1474,76 @@ TEST_F(TestTidbConversion, skipCheckOverflowIntToDeciaml) const ScaleType scale = 0; // int8(max_prec: 3) -> decimal32(max_prec: 9) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int8_ptr, prec_decimal32, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int8_ptr, prec_decimal32, scale)); // int16(max_prec: 5) -> decimal32(max_prec: 9) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int16_ptr, prec_decimal32, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int16_ptr, prec_decimal32, scale)); // int32(max_prec: 10) -> decimal32(max_prec: 9) - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int32_ptr, prec_decimal32, scale)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int32_ptr, prec_decimal32, scale)); // int64(max_prec: 20) -> decimal32(max_prec: 9) - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int64_ptr, prec_decimal32, scale)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int64_ptr, prec_decimal32, scale)); // uint8(max_prec: 3) -> decimal32(max_prec: 9) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint8_ptr, prec_decimal32, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint8_ptr, prec_decimal32, scale)); // uint16(max_prec: 5) -> decimal32(max_prec: 9) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint16_ptr, prec_decimal32, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint16_ptr, prec_decimal32, scale)); // uint32(max_prec: 10) -> decimal32(max_prec: 9) - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint32_ptr, prec_decimal32, scale)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint32_ptr, prec_decimal32, scale)); // uint64(max_prec: 20) -> decimal32(max_prec: 9) - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint64_ptr, prec_decimal32, scale)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint64_ptr, prec_decimal32, scale)); // int8(max_prec: 3) -> decimal64(max_prec: 18) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int8_ptr, prec_decimal64, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int8_ptr, prec_decimal64, scale)); // int16(max_prec: 5) -> decimal64(max_prec: 18) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int16_ptr, prec_decimal64, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int16_ptr, prec_decimal64, scale)); // int32(max_prec: 10) -> decimal64(max_prec: 18) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int32_ptr, prec_decimal64, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int32_ptr, prec_decimal64, scale)); // int64(max_prec: 20) -> decimal64(max_prec: 18) - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int64_ptr, prec_decimal64, scale)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int64_ptr, prec_decimal64, scale)); // uint8(max_prec: 3) -> decimal64(max_prec: 18) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint8_ptr, prec_decimal64, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint8_ptr, prec_decimal64, scale)); // uint16(max_prec: 5) -> decimal64(max_prec: 18) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint16_ptr, prec_decimal64, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint16_ptr, prec_decimal64, scale)); // uint32(max_prec: 10) -> decimal64(max_prec: 18) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint32_ptr, prec_decimal64, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint32_ptr, prec_decimal64, scale)); // uint64(max_prec: 20) -> decimal64(max_prec: 18) - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint64_ptr, prec_decimal64, scale)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint64_ptr, prec_decimal64, scale)); // int8(max_prec: 3) -> decimal128(max_prec: 38) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int8_ptr, prec_decimal128, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int8_ptr, prec_decimal128, scale)); // int16(max_prec: 5) -> decimal128(max_prec: 38) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int16_ptr, prec_decimal128, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int16_ptr, prec_decimal128, scale)); // int32(max_prec: 10) -> decimal128(max_prec: 38) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int32_ptr, prec_decimal128, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int32_ptr, prec_decimal128, scale)); // int64(max_prec: 20) -> decimal128(max_prec: 38) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int64_ptr, prec_decimal128, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int64_ptr, prec_decimal128, scale)); // uint8(max_prec: 3) -> decimal128(max_prec: 38) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint8_ptr, prec_decimal128, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint8_ptr, prec_decimal128, scale)); // uint16(max_prec: 5) -> decimal128(max_prec: 38) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint16_ptr, prec_decimal128, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint16_ptr, prec_decimal128, scale)); // uint32(max_prec: 10) -> decimal128(max_prec: 38) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint32_ptr, prec_decimal128, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint32_ptr, prec_decimal128, scale)); // uint64(max_prec: 20) -> decimal128(max_prec: 38) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint64_ptr, prec_decimal128, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint64_ptr, prec_decimal128, scale)); // int8(max_prec: 3) -> decimal256(max_prec: 65) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int8_ptr, prec_decimal256, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int8_ptr, prec_decimal256, scale)); // int16(max_prec: 5) -> decimal256(max_prec: 65) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int16_ptr, prec_decimal256, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int16_ptr, prec_decimal256, scale)); // int32(max_prec: 10) -> decimal256(max_prec: 65) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int32_ptr, prec_decimal256, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int32_ptr, prec_decimal256, scale)); // int64(max_prec: 20) -> decimal256(max_prec: 65) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int64_ptr, prec_decimal256, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int64_ptr, prec_decimal256, scale)); // uint8(max_prec: 3) -> decimal256(max_prec: 65) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint8_ptr, prec_decimal256, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint8_ptr, prec_decimal256, scale)); // uint16(max_prec: 5) -> decimal256(max_prec: 65) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint16_ptr, prec_decimal256, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint16_ptr, prec_decimal256, scale)); // uint32(max_prec: 10) -> decimal256(max_prec: 65) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint32_ptr, prec_decimal256, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint32_ptr, prec_decimal256, scale)); // uint64(max_prec: 20) -> decimal256(max_prec: 65) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(uint64_ptr, prec_decimal256, scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(uint64_ptr, prec_decimal256, scale)); } TEST_F(TestTidbConversion, skipCheckOverflowDecimalToDeciaml) @@ -1551,24 +1551,24 @@ TEST_F(TestTidbConversion, skipCheckOverflowDecimalToDeciaml) DataTypePtr decimal32_ptr_8_3 = createDecimal(8, 3); DataTypePtr decimal32_ptr_8_2 = createDecimal(8, 2); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(decimal32_ptr_8_2, 8, 3)); - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(decimal32_ptr_8_3, 8, 2)); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(decimal32_ptr_8_2, 7, 5)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(decimal32_ptr_8_2, 8, 3)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(decimal32_ptr_8_3, 8, 2)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(decimal32_ptr_8_2, 7, 5)); - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(decimal32_ptr_8_2, 9, 3)); - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(decimal32_ptr_8_2, 9, 1)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(decimal32_ptr_8_2, 9, 3)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(decimal32_ptr_8_2, 9, 1)); DataTypePtr decimal32_ptr_6_4 = createDecimal(6, 4); // decimal(6, 4) -> decimal(5, 3) // because select cast(99.9999 as decimal(5, 3)); -> 100.000 is greater than 99.999. - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(decimal32_ptr_6_4, 5, 3)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(decimal32_ptr_6_4, 5, 3)); // decimal(6, 4) -> decimal(7, 5) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(decimal32_ptr_6_4, 7, 5)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(decimal32_ptr_6_4, 7, 5)); // decimal(6, 4) -> decimal(6, 5) - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(decimal32_ptr_6_4, 6, 5)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(decimal32_ptr_6_4, 6, 5)); // decimal(6, 4) -> decimal(8, 5) - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(decimal32_ptr_6_4, 8, 5)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(decimal32_ptr_6_4, 8, 5)); } TEST_F(TestTidbConversion, skipCheckOverflowEnumToDecimal) @@ -1583,15 +1583,15 @@ TEST_F(TestTidbConversion, skipCheckOverflowEnumToDecimal) enum16_values.push_back({"b1", 2000}); DataTypePtr enum16_ptr = std::make_shared(enum16_values); - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(enum8_ptr, 3, 0)); - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(enum8_ptr, 4, 1)); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(enum8_ptr, 2, 0)); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(enum8_ptr, 4, 2)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(enum8_ptr, 3, 0)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(enum8_ptr, 4, 1)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(enum8_ptr, 2, 0)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(enum8_ptr, 4, 2)); - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(enum16_ptr, 5, 0)); - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(enum16_ptr, 6, 1)); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(enum16_ptr, 4, 0)); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(enum16_ptr, 6, 2)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(enum16_ptr, 5, 0)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(enum16_ptr, 6, 1)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(enum16_ptr, 4, 0)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(enum16_ptr, 6, 2)); } TEST_F(TestTidbConversion, skipCheckOverflowMyDateTimeToDeciaml) @@ -1600,18 +1600,18 @@ TEST_F(TestTidbConversion, skipCheckOverflowMyDateTimeToDeciaml) DataTypePtr datetime_ptr_fsp_5 = std::make_shared(5); // rule for no fsp: 14 + to_scale <= to_prec. - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(datetime_ptr_no_fsp, 5, 3)); - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(datetime_ptr_no_fsp, 18, 3)); - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(datetime_ptr_no_fsp, 17, 3)); - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(datetime_ptr_no_fsp, 18, 4)); - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(datetime_ptr_no_fsp, 14, 0)); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(datetime_ptr_no_fsp, 14, 1)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(datetime_ptr_no_fsp, 5, 3)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(datetime_ptr_no_fsp, 18, 3)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(datetime_ptr_no_fsp, 17, 3)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(datetime_ptr_no_fsp, 18, 4)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(datetime_ptr_no_fsp, 14, 0)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(datetime_ptr_no_fsp, 14, 1)); // rule for fsp: 20 + scale_diff <= to_prec. // 20 + (3 - 6 + 1) = 18 - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(datetime_ptr_fsp_5, 19, 3)); - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(datetime_ptr_fsp_5, 18, 3)); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(datetime_ptr_fsp_5, 17, 3)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(datetime_ptr_fsp_5, 19, 3)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(datetime_ptr_fsp_5, 18, 3)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(datetime_ptr_fsp_5, 17, 3)); } TEST_F(TestTidbConversion, skipCheckOverflowMyDateToDeciaml) @@ -1619,30 +1619,30 @@ TEST_F(TestTidbConversion, skipCheckOverflowMyDateToDeciaml) DataTypePtr date_ptr = std::make_shared(); // rule: 8 + to_scale <= to_prec. - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(date_ptr, 11, 3)); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(date_ptr, 11, 4)); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(date_ptr, 10, 3)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(date_ptr, 11, 3)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(date_ptr, 11, 4)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(date_ptr, 10, 3)); } TEST_F(TestTidbConversion, skipCheckOverflowOtherToDecimal) { // float and string not support skip overflow check. DataTypePtr string_ptr = std::make_shared(); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(string_ptr, 1, 0)); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(string_ptr, 60, 1)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(string_ptr, 1, 0)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(string_ptr, 60, 1)); DataTypePtr float32_ptr = std::make_shared(); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(float32_ptr, 1, 0)); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(float32_ptr, 60, 1)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(float32_ptr, 1, 0)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(float32_ptr, 60, 1)); DataTypePtr float64_ptr = std::make_shared(); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(float64_ptr, 1, 0)); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(float64_ptr, 60, 1)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(float64_ptr, 1, 0)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(float64_ptr, 60, 1)); // cast duration to decimal is not supported to push down to tiflash for now. DataTypePtr duration_ptr = std::make_shared(); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(duration_ptr, 1, 0)); - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(duration_ptr, 60, 1)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(duration_ptr, 1, 0)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(duration_ptr, 60, 1)); } // check if template argument of CastInternalType is correct or not. @@ -1654,7 +1654,7 @@ try ScaleType to_scale = 3; DataTypePtr int8_ptr = std::make_shared(); // from_prec(3) + to_scale(3) <= Decimal32::prec(9), so we **CAN** skip check overflow. - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int8_ptr, to_prec, to_scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int8_ptr, to_prec, to_scale)); // from_prec(3) + to_scale(3) <= Int32::real_prec(10) - 1, so CastInternalType should be **Int32**. ASSERT_COLUMN_EQ( @@ -1669,7 +1669,7 @@ try to_prec = 9; to_scale = 7; // from_prec(3) + to_scale(7) > Decimal32::prec(9), so we **CANNOT** skip check overflow. - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int8_ptr, to_prec, to_scale)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int8_ptr, to_prec, to_scale)); // from_prec(3) + to_scale(7) > Int32::real_prec(10) - 1, so CastInternalType should be **Int64**. DAGContext * dag_context = context.getDAGContext(); @@ -1690,7 +1690,7 @@ try to_prec = 40; to_scale = 20; DataTypePtr int64_ptr = std::make_shared(); - ASSERT_TRUE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int64_ptr, to_prec, to_scale)); + ASSERT_TRUE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int64_ptr, to_prec, to_scale)); // from_prec(19) + to_scale(20) > Int128::real_prec(39) - 1, so CastInternalType should be **Int256**. ASSERT_COLUMN_EQ( @@ -1705,7 +1705,7 @@ try // from_prec(19) + to_scale(20) > Decimal256::prec(38), so we **CANNOT** skip check overflow. to_prec = 38; to_scale = 20; - ASSERT_FALSE(FunctionTiDBCast::canSkipCheckOverflowForDecimal(int64_ptr, to_prec, to_scale)); + ASSERT_FALSE(FunctionTiDBCast<>::canSkipCheckOverflowForDecimal(int64_ptr, to_prec, to_scale)); // from_prec(19) + to_scale(20) > Int128::real_prec(39) - 1, so CastInternalType should be **Int256**. ASSERT_COLUMN_EQ(