[Refactor] fix some warning in gcc higher than 7 make decimal12_t as a POD type (#5547)

This commit is contained in:
stdpain
2021-03-23 09:37:10 +08:00
committed by GitHub
parent c8afd5646c
commit bfeb717abe
14 changed files with 118 additions and 133 deletions

View File

@ -27,16 +27,6 @@ namespace doris {
// 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) {
integer = int_part;
fraction = frac_part;
}
decimal12_t(const decimal12_t& value) {
integer = value.integer;
fraction = value.fraction;
}
decimal12_t& operator+=(const decimal12_t& value) {
fraction += value.fraction;
@ -62,13 +52,6 @@ struct decimal12_t {
return *this;
}
// call field::copy
decimal12_t& operator=(const decimal12_t& value) {
integer = value.integer;
fraction = value.fraction;
return *this;
}
bool operator<(const decimal12_t& value) const { return cmp(value) < 0; }
bool operator<=(const decimal12_t& value) const { return cmp(value) <= 0; }
@ -156,6 +139,8 @@ struct decimal12_t {
int32_t fraction;
} __attribute__((packed));
static_assert(std::is_trivial<decimal12_t>::value, "decimal12_t should be a POD type");
inline std::ostream& operator<<(std::ostream& os, const decimal12_t& val) {
os << val.to_string();
return os;

View File

@ -186,7 +186,7 @@ public:
static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr,
MemPool* pool) {
decimal12_t decimal_val;
decimal12_t decimal_val = {0, 0};
RETURN_IF_ERROR(KeyCoderTraits<OLAP_FIELD_TYPE_BIGINT>::decode_ascending(
encoded_key, sizeof(decimal_val.integer), (uint8_t*)&decimal_val.integer, pool));
RETURN_IF_ERROR(KeyCoderTraits<OLAP_FIELD_TYPE_INT>::decode_ascending(

View File

@ -601,95 +601,95 @@ void Reader::_init_conditions_param(const ReaderParams& read_params) {
}
}
#define COMPARISON_PREDICATE_CONDITION_VALUE(NAME, PREDICATE) \
ColumnPredicate* Reader::_new_##NAME##_pred(const TabletColumn& column, int index, \
const std::string& cond, bool opposite) const { \
ColumnPredicate* predicate = nullptr; \
switch (column.type()) { \
case OLAP_FIELD_TYPE_TINYINT: { \
std::stringstream ss(cond); \
int32_t value = 0; \
ss >> value; \
predicate = new PREDICATE<int8_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_SMALLINT: { \
std::stringstream ss(cond); \
int16_t value = 0; \
ss >> value; \
predicate = new PREDICATE<int16_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_INT: { \
std::stringstream ss(cond); \
int32_t value = 0; \
ss >> value; \
predicate = new PREDICATE<int32_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_BIGINT: { \
std::stringstream ss(cond); \
int64_t value = 0; \
ss >> value; \
predicate = new PREDICATE<int64_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_LARGEINT: { \
std::stringstream ss(cond); \
int128_t value = 0; \
ss >> value; \
predicate = new PREDICATE<int128_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_DECIMAL: { \
decimal12_t value(0, 0); \
value.from_string(cond); \
predicate = new PREDICATE<decimal12_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_CHAR: { \
StringValue value; \
size_t length = std::max(static_cast<size_t>(column.length()), cond.length()); \
char* buffer = reinterpret_cast<char*>(_predicate_mem_pool->allocate(length)); \
memset(buffer, 0, length); \
memory_copy(buffer, cond.c_str(), cond.length()); \
value.len = length; \
value.ptr = buffer; \
predicate = new PREDICATE<StringValue>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_VARCHAR: { \
StringValue value; \
int32_t length = cond.length(); \
char* buffer = reinterpret_cast<char*>(_predicate_mem_pool->allocate(length)); \
memory_copy(buffer, cond.c_str(), length); \
value.len = length; \
value.ptr = buffer; \
predicate = new PREDICATE<StringValue>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_DATE: { \
uint24_t value = timestamp_from_date(cond); \
predicate = new PREDICATE<uint24_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_DATETIME: { \
uint64_t value = timestamp_from_datetime(cond); \
predicate = new PREDICATE<uint64_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_BOOL: { \
std::stringstream ss(cond); \
bool value = false; \
ss >> value; \
predicate = new PREDICATE<bool>(index, value, opposite); \
break; \
} \
default: \
break; \
} \
\
return predicate; \
#define COMPARISON_PREDICATE_CONDITION_VALUE(NAME, PREDICATE) \
ColumnPredicate* Reader::_new_##NAME##_pred(const TabletColumn& column, int index, \
const std::string& cond, bool opposite) const { \
ColumnPredicate* predicate = nullptr; \
switch (column.type()) { \
case OLAP_FIELD_TYPE_TINYINT: { \
std::stringstream ss(cond); \
int32_t value = 0; \
ss >> value; \
predicate = new PREDICATE<int8_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_SMALLINT: { \
std::stringstream ss(cond); \
int16_t value = 0; \
ss >> value; \
predicate = new PREDICATE<int16_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_INT: { \
std::stringstream ss(cond); \
int32_t value = 0; \
ss >> value; \
predicate = new PREDICATE<int32_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_BIGINT: { \
std::stringstream ss(cond); \
int64_t value = 0; \
ss >> value; \
predicate = new PREDICATE<int64_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_LARGEINT: { \
std::stringstream ss(cond); \
int128_t value = 0; \
ss >> value; \
predicate = new PREDICATE<int128_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_DECIMAL: { \
decimal12_t value = {0, 0}; \
value.from_string(cond); \
predicate = new PREDICATE<decimal12_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_CHAR: { \
StringValue value; \
size_t length = std::max(static_cast<size_t>(column.length()), cond.length()); \
char* buffer = reinterpret_cast<char*>(_predicate_mem_pool->allocate(length)); \
memset(buffer, 0, length); \
memory_copy(buffer, cond.c_str(), cond.length()); \
value.len = length; \
value.ptr = buffer; \
predicate = new PREDICATE<StringValue>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_VARCHAR: { \
StringValue value; \
int32_t length = cond.length(); \
char* buffer = reinterpret_cast<char*>(_predicate_mem_pool->allocate(length)); \
memory_copy(buffer, cond.c_str(), length); \
value.len = length; \
value.ptr = buffer; \
predicate = new PREDICATE<StringValue>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_DATE: { \
uint24_t value = timestamp_from_date(cond); \
predicate = new PREDICATE<uint24_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_DATETIME: { \
uint64_t value = timestamp_from_datetime(cond); \
predicate = new PREDICATE<uint64_t>(index, value, opposite); \
break; \
} \
case OLAP_FIELD_TYPE_BOOL: { \
std::stringstream ss(cond); \
bool value = false; \
ss >> value; \
predicate = new PREDICATE<bool>(index, value, opposite); \
break; \
} \
default: \
break; \
} \
\
return predicate; \
}
COMPARISON_PREDICATE_CONDITION_VALUE(eq, EqualPredicate)
@ -800,7 +800,7 @@ ColumnPredicate* Reader::_parse_to_predicate(const TCondition& condition, bool o
case OLAP_FIELD_TYPE_DECIMAL: {
std::set<decimal12_t> values;
for (auto& cond_val : condition.condition_values) {
decimal12_t value;
decimal12_t value = {0, 0};
value.from_string(cond_val);
values.insert(value);
}

View File

@ -311,7 +311,7 @@ public:
}
case OLAP_FIELD_TYPE_DECIMAL: {
_values = reinterpret_cast<void*>(mem_pool->allocate(size * sizeof(decimal12_t)));
decimal12_t value(0, 0);
decimal12_t value = {0, 0};
value.from_string(_default_value);
for (int i = 0; i < size; ++i) {
((decimal12_t*)_values)[i] = value;

View File

@ -351,7 +351,7 @@ TEST_F(TestEqualPredicate, DECIMAL_COLUMN) {
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
decimal12_t value(5, 5);
decimal12_t value = {5, 5};
ColumnPredicate* pred = new EqualPredicate<decimal12_t>(0, value);
// for VectorizedBatch no nulls
@ -996,7 +996,7 @@ TEST_F(TestLessPredicate, DECIMAL_COLUMN) {
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
decimal12_t value(5, 5);
decimal12_t value = {5, 5};
ColumnPredicate* pred = new LessPredicate<decimal12_t>(0, value);
// for VectorizedBatch no nulls
@ -1013,7 +1013,7 @@ TEST_F(TestLessPredicate, DECIMAL_COLUMN) {
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 5);
uint16_t* sel = _vectorized_batch->selected();
decimal12_t sum(0, 0);
decimal12_t sum = {0, 0};
for (int i = 0; i < _vectorized_batch->size(); ++i) {
sum += *(col_data + sel[i]);
}

View File

@ -24,8 +24,8 @@ namespace doris {
TEST(FieldInfoTest, Add) {
int64_t a_integer = 9223372036854775806L;
int a_fraction = 1;
decimal12_t a(a_integer, a_fraction);
decimal12_t b(1, 0);
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);

View File

@ -439,11 +439,11 @@ TEST_F(TestInListPredicate, DECIMAL_COLUMN) {
}
std::set<decimal12_t> values;
decimal12_t value1(4, 4);
decimal12_t value1 = {4, 4};
values.insert(value1);
decimal12_t value2(5, 5);
decimal12_t value2 = {5, 5};
values.insert(value2);
decimal12_t value3(6, 6);
decimal12_t value3 = {6, 6};
values.insert(value3);
ColumnPredicate* pred = new InListPredicate<decimal12_t>(0, std::move(values));

View File

@ -178,7 +178,7 @@ TEST_F(KeyCoderTest, test_date) {
TEST_F(KeyCoderTest, test_decimal) {
auto key_coder = get_key_coder(OLAP_FIELD_TYPE_DECIMAL);
decimal12_t val1(1, 100000000);
decimal12_t val1 = {1, 100000000};
std::string buf1;
key_coder->encode_ascending(&val1, sizeof(decimal12_t), &buf1);
@ -189,19 +189,19 @@ TEST_F(KeyCoderTest, test_decimal) {
ASSERT_EQ(check_val, val1);
{
decimal12_t val2(-1, -100000000);
decimal12_t val2 = {-1, -100000000};
std::string buf2;
key_coder->encode_ascending(&val2, sizeof(decimal12_t), &buf2);
ASSERT_TRUE(memcmp(buf1.c_str(), buf2.c_str(), buf1.size()) > 0);
}
{
decimal12_t val2(1, 100000001);
decimal12_t val2 = {1, 100000001};
std::string buf2;
key_coder->encode_ascending(&val2, sizeof(decimal12_t), &buf2);
ASSERT_TRUE(memcmp(buf1.c_str(), buf2.c_str(), buf1.size()) < 0);
}
{
decimal12_t val2(0, 0);
decimal12_t val2 = {0, 0};
std::string buf2;
key_coder->encode_ascending(&val2, sizeof(decimal12_t), &buf2);
ASSERT_TRUE(memcmp(buf1.c_str(), buf2.c_str(), buf1.size()) > 0);

View File

@ -463,7 +463,7 @@ TEST_F(TestRowCursor, AggregateWithoutNull) {
int32_t l_int = 10;
int128_t l_largeint = (int128_t)(1) << 100;
double l_double = 8.8;
decimal12_t l_decimal(11, 22);
decimal12_t l_decimal = {11, 22};
Slice l_varchar("beijing");
left.set_field_content(0, reinterpret_cast<char*>(&l_char), _mem_pool.get());
left.set_field_content(1, reinterpret_cast<char*>(&l_int), _mem_pool.get());
@ -483,7 +483,7 @@ TEST_F(TestRowCursor, AggregateWithoutNull) {
int32_t r_int = 10;
int128_t r_largeint = (int128_t)(1) << 100;
double r_double = 5.5;
decimal12_t r_decimal(22, 22);
decimal12_t r_decimal = {22, 22};
Slice r_varchar("shenzhen");
right.set_field_content(0, reinterpret_cast<char*>(&r_char), _mem_pool.get());
right.set_field_content(1, reinterpret_cast<char*>(&r_int), _mem_pool.get());
@ -544,7 +544,7 @@ TEST_F(TestRowCursor, AggregateWithNull) {
int32_t r_int = 10;
int128_t r_largeint = (int128_t)(1) << 100;
double r_double = 5.5;
decimal12_t r_decimal(22, 22);
decimal12_t r_decimal = {22, 22};
right.set_field_content(0, reinterpret_cast<char*>(&r_char), _mem_pool.get());
right.set_field_content(1, reinterpret_cast<char*>(&r_int), _mem_pool.get());
right.set_field_content(2, reinterpret_cast<char*>(&r_largeint), _mem_pool.get());

View File

@ -336,11 +336,11 @@ TEST_F(BitShufflePageTest, TestBitShuffleDecimal12BlockEncoderSeekValue) {
const uint32_t size = 1000;
std::unique_ptr<decimal12_t[]> decimals(new decimal12_t[size]);
for (int i = 0; i < size; i++) {
decimals.get()[i] = decimal12_t(i + 100, random());
decimals.get()[i] = {i + 100, random()};
}
decimal12_t small_than_smallest = decimal12_t(99, 9);
decimal12_t bigger_than_biggest = decimal12_t(1111, 1);
decimal12_t small_than_smallest = {99, 9};
decimal12_t bigger_than_biggest = {1111, 1};
test_seek_at_or_after_value_template<
OLAP_FIELD_TYPE_DECIMAL, segment_v2::BitshufflePageBuilder<OLAP_FIELD_TYPE_DECIMAL>,
segment_v2::BitShufflePageDecoder<OLAP_FIELD_TYPE_DECIMAL>>(

View File

@ -277,11 +277,11 @@ TEST_F(BloomFilterIndexReaderWriterTest, test_decimal) {
decimal12_t* val = new decimal12_t[num];
for (int i = 0; i < num; ++i) {
// there will be 3 bloom filter pages
val[i] = decimal12_t(i + 1, i + 1);
val[i] = {i + 1, i + 1};
}
std::string file_name = "bloom_filter_decimal";
decimal12_t not_exist_value = decimal12_t(666, 666);
decimal12_t not_exist_value = {666, 666};
test_bloom_filter_index_reader_writer_template<OLAP_FIELD_TYPE_DECIMAL>(file_name, val, num, 1,
&not_exist_value);
delete[] val;

View File

@ -585,7 +585,7 @@ TEST_F(ColumnReaderWriterTest, test_types) {
bool_vals[i] = i % 2;
date_vals[i] = i + 33;
datetime_vals[i] = i + 33;
decimal_vals[i] = decimal12_t(i, i); // 1.000000001
decimal_vals[i] = {i, i}; // 1.000000001
set_column_value_by_type(OLAP_FIELD_TYPE_VARCHAR, i, (char*)&varchar_vals[i], &_pool);
set_column_value_by_type(OLAP_FIELD_TYPE_CHAR, i, (char*)&char_vals[i], &_pool, 8);
@ -665,7 +665,7 @@ TEST_F(ColumnReaderWriterTest, test_default_value) {
test_read_default_value<OLAP_FIELD_TYPE_DATETIME>(v_datetime, &result_datetime);
std::string v_decimal("102418.000000002");
decimal12_t decimal(102418, 2);
decimal12_t decimal = {102418, 2};
test_read_default_value<OLAP_FIELD_TYPE_DECIMAL>(v_decimal, &decimal);
}

View File

@ -649,7 +649,7 @@ TEST_F(TestColumn, ConvertDoubleToVarchar) {
}
TEST_F(TestColumn, ConvertDecimalToVarchar) {
decimal12_t val(456, 789000000);
decimal12_t val = {456, 789000000};
test_convert_to_varchar<decimal12_t>("Decimal", 12, val, "456.789000000", OLAP_SUCCESS);
}

View File

@ -134,7 +134,7 @@ TEST(TypesTest, copy_and_equal) {
common_test<OLAP_FIELD_TYPE_LARGEINT>(int128_val);
common_test<OLAP_FIELD_TYPE_FLOAT>(1.11);
common_test<OLAP_FIELD_TYPE_DOUBLE>(12221.11);
decimal12_t decimal_val(123, 2345);
decimal12_t decimal_val = {123, 2345};
common_test<OLAP_FIELD_TYPE_DECIMAL>(decimal_val);
common_test<OLAP_FIELD_TYPE_DATE>((1988 << 9) | (2 << 5) | 1);