diff --git a/src/expr/calc/casting.cc b/src/expr/calc/casting.cc index 63f3cbd..7883446 100644 --- a/src/expr/calc/casting.cc +++ b/src/expr/calc/casting.cc @@ -188,14 +188,12 @@ DecimalP Cast(bool v) { template <> DecimalP Cast(float v) { - String const f2s = CastFloat(v); - return DecimalP(*f2s.GetPtr()); + return DecimalP(v); } template <> DecimalP Cast(double v) { - String const d2s = CastDouble(v); - return DecimalP(*d2s.GetPtr()); + return DecimalP(v); } template <> diff --git a/test/rel/test_rel.cc b/test/rel/test_rel.cc index 5b7a665..e4a299c 100644 --- a/test/rel/test_rel.cc +++ b/test/rel/test_rel.cc @@ -203,20 +203,32 @@ INSTANTIATE_TEST_SUITE_P( new Tuple{nullptr}, } ), + /* create table t1(id int, a double, primary key(id); + * insert into t1 values(1, 5.8); + * select * from t1 where a >= 5.8 and a <= 5.8. + * The expected result is null. + * It is compatible with mysql and dingodb scenario when making decimal pushdown disable. + */ std::make_tuple( "713501F0651603352E3892063501F0651603352E3894065200", MakeDataForDoubleToDecimal(), Data{ //The origin string is longer than range. - new Tuple{1, 5.8}, + nullptr, } ), + /* create table t1(id int, a double, primary key(id); + * insert into t1 values(1, 5.8); + * select * from t1 where a >= 5.8 and a <= 5.8. + * The expected result is null. + * It is compatible with mysql and dingodb scenario when making decimal pushdown disable. + */ std::make_tuple( "713401F0641603352E3892063401F0641603352E3894065200", MakeDataForFloatToDecimal(), Data{ //The origin string is longer than range. - new Tuple{1, (float)5.8}, + nullptr, } ), // PROJECT(input, instr($[1])) diff --git a/test/types/test_type_decimal.cc b/test/types/test_type_decimal.cc index 069bf95..690e652 100644 --- a/test/types/test_type_decimal.cc +++ b/test/types/test_type_decimal.cc @@ -385,6 +385,10 @@ TEST(TestTypeDecimal, DecimalTest) { //Test -dec 0. ASSERT_EQ((-Decimal(std::string("0"))).toLong(), 0); + //Test decimal to double + DecimalP dp = DecimalP((double)32.91); + ASSERT_EQ(dp.GetPtr()->toString(), std::string("32.9099999999999965894")); + //DecimalP p = DecimalP((float)12.34); ASSERT_EQ(DecimalP((long)12).GetPtr()->toString(10,4), std::string("12.0000")); ASSERT_EQ(DecimalP((float)12.34).GetPtr()->toString(10,4), std::string("12.3400"));