Skip to content

Commit

Permalink
Fix the bug of += decimal in olap engine
Browse files Browse the repository at this point in the history
[ISSUE-1225] This change fix the olap engine bug of decimal agg. Using ^ instead of * to judge result is less then zero.
The result of * will be less then zero when the result is overflow. So the answer of += is incorrect.
  • Loading branch information
EmmyMiao87 committed May 30, 2019
1 parent fa4ac9f commit 796eade
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion be/src/olap/field_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ inline std::ostream& operator<<(std::ostream& os, const uint24_t& val) {
return os;
}

// the sign of integer must be same as fraction
struct decimal12_t {
decimal12_t() : integer(0), fraction(0) {}
decimal12_t(int64_t int_part, int32_t frac_part) {
Expand All @@ -147,7 +148,8 @@ struct decimal12_t {
fraction += FRAC_RATIO;
}

if (fraction * integer < 0) {
// if sign of fraction is different from integer
if ((fraction ^ integer) < 0) {
bool sign = integer < 0;
integer += (sign ? 1 : -1);
fraction += (sign ? -FRAC_RATIO : FRAC_RATIO);
Expand Down
15 changes: 15 additions & 0 deletions be/test/olap/field_info_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <gtest/gtest.h>
#include <olap/field_info.h>

TEST_F(){
decimal12_t a = decimal12_t(INT_MAX + 1, INT_MAX);
decimal12_t b = decimal12_t(0,0);

ASSERT_EQ(a, a+=b);
delete
}

int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit 796eade

Please sign in to comment.