Fix the bug of += decimal in olap engine (#1226)
* Fix the bug of += decimal in olap engine [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.
This commit is contained in:
@ -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) {
|
||||
@ -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);
|
||||
|
||||
@ -43,3 +43,4 @@ ADD_BE_TEST(delta_writer_test)
|
||||
ADD_BE_TEST(serialize_test)
|
||||
ADD_BE_TEST(olap_meta_test)
|
||||
ADD_BE_TEST(olap_header_manager_test)
|
||||
ADD_BE_TEST(field_info_test)
|
||||
|
||||
46
be/test/olap/field_info_test.cpp
Normal file
46
be/test/olap/field_info_test.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
#include "olap/field_info.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace doris {
|
||||
|
||||
TEST(FieldInfoTest, HandleNoneZeroInput) {
|
||||
int64_t a_integer = 9223372036854775806L;
|
||||
int a_fraction = 1;
|
||||
decimal12_t a(a_integer, a_fraction);
|
||||
decimal12_t b(1, 0);
|
||||
a += b;
|
||||
ASSERT_EQ(a_integer + 1, a.integer);
|
||||
ASSERT_EQ(a_fraction, a.fraction);
|
||||
|
||||
a.integer = -9223372036854775807L;
|
||||
a.fraction = -1;
|
||||
b.integer = 0;
|
||||
a += b;
|
||||
ASSERT_EQ(-9223372036854775807L, a.integer);
|
||||
ASSERT_EQ(-1, a.fraction);
|
||||
}
|
||||
|
||||
} // namespace doris
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@ -217,6 +217,7 @@ ${DORIS_TEST_BINARY_DIR}/olap/serialize_test
|
||||
${DORIS_TEST_BINARY_DIR}/olap/olap_header_manager_test
|
||||
${DORIS_TEST_BINARY_DIR}/olap/olap_meta_test
|
||||
${DORIS_TEST_BINARY_DIR}/olap/delta_writer_test
|
||||
${DORIS_TEST_BINARY_DIR}/olap/field_info_test
|
||||
|
||||
# Running routine load test
|
||||
${DORIS_TEST_BINARY_DIR}/runtime/kafka_consumer_pipe_test
|
||||
|
||||
Reference in New Issue
Block a user