Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/expr/calc/casting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <>
Expand Down
16 changes: 14 additions & 2 deletions test/rel/test_rel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
4 changes: 4 additions & 0 deletions test/types/test_type_decimal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Loading