This is an automated email from the ASF dual-hosted git repository. panxiaolei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 77e241cbb0 [refactor](date) Use uint32 as predicate type for date type (#11708) 77e241cbb0 is described below commit 77e241cbb0b907a99fb61dbf82925908ef093e96 Author: Gabriel <gabrielleeb...@gmail.com> AuthorDate: Mon Aug 15 11:12:33 2022 +0800 [refactor](date) Use uint32 as predicate type for date type (#11708) Use uint32 as predicate type for date type --- be/src/olap/comparison_predicate.h | 111 +++++++++++++++++++---------- be/src/olap/in_list_predicate.h | 75 +++++++++---------- be/src/olap/predicate_creator.h | 44 ++++++------ be/src/util/date_func.cpp | 9 +-- be/src/util/date_func.h | 2 +- be/test/olap/comparison_predicate_test.cpp | 28 +++++--- be/test/olap/in_list_predicate_test.cpp | 10 +-- 7 files changed, 159 insertions(+), 120 deletions(-) diff --git a/be/src/olap/comparison_predicate.h b/be/src/olap/comparison_predicate.h index ad36d59503..f953f196f2 100644 --- a/be/src/olap/comparison_predicate.h +++ b/be/src/olap/comparison_predicate.h @@ -27,17 +27,9 @@ namespace doris { template <PrimitiveType Type, PredicateType PT> class ComparisonPredicateBase : public ColumnPredicate { public: - using T = std::conditional_t<Type == TYPE_DATE, uint24_t, - typename PredicatePrimitiveTypeTraits<Type>::PredicateFieldType>; + using T = typename PredicatePrimitiveTypeTraits<Type>::PredicateFieldType; ComparisonPredicateBase(uint32_t column_id, const T& value, bool opposite = false) - : ColumnPredicate(column_id, opposite), _value(value) { - if constexpr (std::is_same_v<T, uint24_t>) { - _value_real = 0; - memory_copy(&_value_real, _value.get_data(), sizeof(T)); - } else { - _value_real = _value; - } - } + : ColumnPredicate(column_id, opposite), _value(value) {} PredicateType type() const override { return PT; } @@ -47,17 +39,34 @@ public: for (uint16_t i = 0; i < *size; ++i) { uint16_t idx = sel[i]; sel[new_size] = idx; - const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); - auto result = (!block->cell(idx).is_null() && _operator(*cell_value, _value)); - new_size += _opposite ? !result : result; + if constexpr (Type == TYPE_DATE) { + T tmp_uint32_value = 0; + memcpy((char*)(&tmp_uint32_value), block->cell(idx).cell_ptr(), + sizeof(uint24_t)); + auto result = + (!block->cell(idx).is_null() && _operator(tmp_uint32_value, _value)); + new_size += _opposite ? !result : result; + } else { + const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); + auto result = (!block->cell(idx).is_null() && _operator(*cell_value, _value)); + new_size += _opposite ? !result : result; + } } } else { for (uint16_t i = 0; i < *size; ++i) { uint16_t idx = sel[i]; sel[new_size] = idx; - const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); - auto result = _operator(*cell_value, _value); - new_size += _opposite ? !result : result; + if constexpr (Type == TYPE_DATE) { + T tmp_uint32_value = 0; + memcpy((char*)(&tmp_uint32_value), block->cell(idx).cell_ptr(), + sizeof(uint24_t)); + auto result = _operator(tmp_uint32_value, _value); + new_size += _opposite ? !result : result; + } else { + const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); + auto result = _operator(*cell_value, _value); + new_size += _opposite ? !result : result; + } } } *size = new_size; @@ -70,9 +79,18 @@ public: continue; } uint16_t idx = sel[i]; - const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); - auto result = (!block->cell(idx).is_null() && _operator(*cell_value, _value)); - flags[i] = flags[i] | (_opposite ? !result : result); + if constexpr (Type == TYPE_DATE) { + T tmp_uint32_value = 0; + memcpy((char*)(&tmp_uint32_value), block->cell(idx).cell_ptr(), + sizeof(uint24_t)); + auto result = + (!block->cell(idx).is_null() && _operator(tmp_uint32_value, _value)); + flags[i] = flags[i] | (_opposite ? !result : result); + } else { + const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); + auto result = (!block->cell(idx).is_null() && _operator(*cell_value, _value)); + flags[i] = flags[i] | (_opposite ? !result : result); + } } } else { for (uint16_t i = 0; i < size; ++i) { @@ -80,9 +98,17 @@ public: continue; } uint16_t idx = sel[i]; - const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); - auto result = _operator(*cell_value, _value); - flags[i] = flags[i] | (_opposite ? !result : result); + if constexpr (Type == TYPE_DATE) { + T tmp_uint32_value = 0; + memcpy((char*)(&tmp_uint32_value), block->cell(idx).cell_ptr(), + sizeof(uint24_t)); + auto result = _operator(tmp_uint32_value, _value); + flags[i] = flags[i] | (_opposite ? !result : result); + } else { + const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); + auto result = _operator(*cell_value, _value); + flags[i] = flags[i] | (_opposite ? !result : result); + } } } } @@ -95,9 +121,18 @@ public: continue; } uint16_t idx = sel[i]; - const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); - auto result = (!block->cell(idx).is_null() && _operator(*cell_value, _value)); - flags[i] = flags[i] & (_opposite ? !result : result); + if constexpr (Type == TYPE_DATE) { + T tmp_uint32_value = 0; + memcpy((char*)(&tmp_uint32_value), block->cell(idx).cell_ptr(), + sizeof(uint24_t)); + auto result = + (!block->cell(idx).is_null() && _operator(tmp_uint32_value, _value)); + flags[i] = flags[i] & (_opposite ? !result : result); + } else { + const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); + auto result = (!block->cell(idx).is_null() && _operator(*cell_value, _value)); + flags[i] = flags[i] & (_opposite ? !result : result); + } } } else { for (uint16_t i = 0; i < size; ++i) { @@ -105,9 +140,17 @@ public: continue; } uint16_t idx = sel[i]; - const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); - auto result = _operator(*cell_value, _value); - flags[i] = flags[i] & (_opposite ? !result : result); + if constexpr (Type == TYPE_DATE) { + T tmp_uint32_value = 0; + memcpy((char*)(&tmp_uint32_value), block->cell(idx).cell_ptr(), + sizeof(uint24_t)); + auto result = _operator(tmp_uint32_value, _value); + flags[i] = flags[i] & (_opposite ? !result : result); + } else { + const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); + auto result = _operator(*cell_value, _value); + flags[i] = flags[i] & (_opposite ? !result : result); + } } } } @@ -193,7 +236,7 @@ public: .get_data() .data(); - _base_loop_vec<true, is_and>(size, flags, null_map.data(), data_array, _value_real); + _base_loop_vec<true, is_and>(size, flags, null_map.data(), data_array, _value); } } else { if (column.is_column_dictionary()) { @@ -216,7 +259,7 @@ public: ->get_data() .data(); - _base_loop_vec<false, is_and>(size, flags, nullptr, data_array, _value_real); + _base_loop_vec<false, is_and>(size, flags, nullptr, data_array, _value); } } @@ -238,8 +281,6 @@ public: } private: - using TReal = typename PredicatePrimitiveTypeTraits<Type>::PredicateFieldType; - template <typename LeftT, typename RightT> bool _operator(const LeftT& lhs, const RightT& rhs) const { if constexpr (PT == PredicateType::EQ) { @@ -395,8 +436,7 @@ private: ->get_data() .data(); - _base_loop_bit<is_nullable, is_and>(sel, size, flags, null_map, data_array, - _value_real); + _base_loop_bit<is_nullable, is_and>(sel, size, flags, null_map, data_array, _value); } } @@ -442,12 +482,11 @@ private: ->get_data() .data(); - return _base_loop<is_nullable>(sel, size, null_map, data_array, _value_real); + return _base_loop<is_nullable>(sel, size, null_map, data_array, _value); } } T _value; - TReal _value_real; }; } //namespace doris diff --git a/be/src/olap/in_list_predicate.h b/be/src/olap/in_list_predicate.h index 2a7658621a..6341de6ff6 100644 --- a/be/src/olap/in_list_predicate.h +++ b/be/src/olap/in_list_predicate.h @@ -79,8 +79,7 @@ namespace doris { template <PrimitiveType Type, PredicateType PT> class InListPredicateBase : public ColumnPredicate { public: - using T = std::conditional_t<Type == TYPE_DATE, uint24_t, - typename PredicatePrimitiveTypeTraits<Type>::PredicateFieldType>; + using T = typename PredicatePrimitiveTypeTraits<Type>::PredicateFieldType; InListPredicateBase(uint32_t column_id, phmap::flat_hash_set<T>&& values, bool is_opposite = false) : ColumnPredicate(column_id, is_opposite), _values(std::move(values)) {} @@ -197,12 +196,25 @@ private: for (uint16_t i = 0; i < *size; ++i) { uint16_t idx = sel[i]; sel[new_size] = idx; - const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); - if constexpr (is_nullable) { - new_size += _opposite ^ (!block->cell(idx).is_null() && - _operator(_values.find(*cell_value), _values.end())); + if constexpr (Type == TYPE_DATE) { + T tmp_uint32_value = 0; + memcpy((char*)(&tmp_uint32_value), block->cell(idx).cell_ptr(), sizeof(uint24_t)); + if constexpr (is_nullable) { + new_size += + _opposite ^ (!block->cell(idx).is_null() && + _operator(_values.find(tmp_uint32_value), _values.end())); + } else { + new_size += + _opposite ^ _operator(_values.find(tmp_uint32_value), _values.end()); + } } else { - new_size += _opposite ^ _operator(_values.find(*cell_value), _values.end()); + const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); + if constexpr (is_nullable) { + new_size += _opposite ^ (!block->cell(idx).is_null() && + _operator(_values.find(*cell_value), _values.end())); + } else { + new_size += _opposite ^ _operator(_values.find(*cell_value), _values.end()); + } } } *size = new_size; @@ -217,12 +229,21 @@ private: } uint16_t idx = sel[i]; - const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); auto result = true; - if constexpr (is_nullable) { - result &= !block->cell(idx).is_null(); + if constexpr (Type == TYPE_DATE) { + T tmp_uint32_value = 0; + memcpy((char*)(&tmp_uint32_value), block->cell(idx).cell_ptr(), sizeof(uint24_t)); + if constexpr (is_nullable) { + result &= !block->cell(idx).is_null(); + } + result &= _operator(_values.find(tmp_uint32_value), _values.end()); + } else { + const T* cell_value = reinterpret_cast<const T*>(block->cell(idx).cell_ptr()); + if constexpr (is_nullable) { + result &= !block->cell(idx).is_null(); + } + result &= _operator(_values.find(*cell_value), _values.end()); } - result &= _operator(_values.find(*cell_value), _values.end()); if constexpr (is_and) { flags[i] &= _opposite ^ result; @@ -238,37 +259,7 @@ private: uint16_t* sel, uint16_t size) const { uint16_t new_size = 0; - if constexpr (std::is_same_v<T, uint24_t>) { - auto* nested_col_ptr = - vectorized::check_and_get_column<vectorized::PredicateColumnType<TYPE_DATE>>( - column); - auto& data_array = nested_col_ptr->get_data(); - - uint24_t tmp_uint24_value; - for (uint16_t i = 0; i < size; i++) { - uint16_t idx = sel[i]; - if constexpr (is_nullable) { - if ((*null_map)[idx]) { - if constexpr (is_opposite) { - sel[new_size++] = idx; - } - continue; - } - } - - memcpy((char*)(&tmp_uint24_value), (char*)(&(data_array[idx])), sizeof(uint24_t)); - if constexpr (!is_opposite) { - if (_operator(_values.find(tmp_uint24_value), _values.end())) { - sel[new_size++] = idx; - } - } else { - if (!_operator(_values.find(tmp_uint24_value), _values.end())) { - sel[new_size++] = idx; - } - } - } - - } else if (column->is_column_dictionary()) { + if (column->is_column_dictionary()) { if constexpr (std::is_same_v<T, StringValue>) { auto* nested_col_ptr = vectorized::check_and_get_column< vectorized::ColumnDictionary<vectorized::Int32>>(column); diff --git a/be/src/olap/predicate_creator.h b/be/src/olap/predicate_creator.h index b222a6272a..89c26fbd53 100644 --- a/be/src/olap/predicate_creator.h +++ b/be/src/olap/predicate_creator.h @@ -37,9 +37,10 @@ public: virtual ~PredicateCreator() = default; }; -template <PrimitiveType Type, typename CppType, PredicateType PT, typename ConditionType> +template <PrimitiveType Type, PredicateType PT, typename ConditionType> class IntegerPredicateCreator : public PredicateCreator<ConditionType> { public: + using CppType = typename PredicatePrimitiveTypeTraits<Type>::PredicateFieldType; ColumnPredicate* create(const TabletColumn& column, int index, const ConditionType& conditions, bool opposite, MemPool* pool) override { if constexpr (PredicateTypeTraits::is_list(PT)) { @@ -62,9 +63,10 @@ private: } }; -template <PrimitiveType Type, typename CppType, PredicateType PT, typename ConditionType> +template <PrimitiveType Type, PredicateType PT, typename ConditionType> class DecimalPredicateCreator : public PredicateCreator<ConditionType> { public: + using CppType = typename PredicatePrimitiveTypeTraits<Type>::PredicateFieldType; ColumnPredicate* create(const TabletColumn& column, int index, const ConditionType& conditions, bool opposite, MemPool* pool) override { if constexpr (PredicateTypeTraits::is_list(PT)) { @@ -125,9 +127,10 @@ private: } }; -template <PrimitiveType Type, typename CppType, PredicateType PT, typename ConditionType> +template <PrimitiveType Type, PredicateType PT, typename ConditionType> struct CustomPredicateCreator : public PredicateCreator<ConditionType> { public: + using CppType = typename PredicatePrimitiveTypeTraits<Type>::PredicateFieldType; CustomPredicateCreator(const std::function<CppType(const std::string& condition)>& convert) : _convert(convert) {}; @@ -153,25 +156,22 @@ template <PredicateType PT, typename ConditionType> inline std::unique_ptr<PredicateCreator<ConditionType>> get_creator(const FieldType& type) { switch (type) { case OLAP_FIELD_TYPE_TINYINT: { - return std::make_unique<IntegerPredicateCreator<TYPE_TINYINT, int8_t, PT, ConditionType>>(); + return std::make_unique<IntegerPredicateCreator<TYPE_TINYINT, PT, ConditionType>>(); } case OLAP_FIELD_TYPE_SMALLINT: { - return std::make_unique< - IntegerPredicateCreator<TYPE_SMALLINT, int16_t, PT, ConditionType>>(); + return std::make_unique<IntegerPredicateCreator<TYPE_SMALLINT, PT, ConditionType>>(); } case OLAP_FIELD_TYPE_INT: { - return std::make_unique<IntegerPredicateCreator<TYPE_INT, int32_t, PT, ConditionType>>(); + return std::make_unique<IntegerPredicateCreator<TYPE_INT, PT, ConditionType>>(); } case OLAP_FIELD_TYPE_BIGINT: { - return std::make_unique<IntegerPredicateCreator<TYPE_BIGINT, int64_t, PT, ConditionType>>(); + return std::make_unique<IntegerPredicateCreator<TYPE_BIGINT, PT, ConditionType>>(); } case OLAP_FIELD_TYPE_LARGEINT: { - return std::make_unique< - IntegerPredicateCreator<TYPE_LARGEINT, int128_t, PT, ConditionType>>(); + return std::make_unique<IntegerPredicateCreator<TYPE_LARGEINT, PT, ConditionType>>(); } case OLAP_FIELD_TYPE_DECIMAL: { - return std::make_unique< - CustomPredicateCreator<TYPE_DECIMALV2, decimal12_t, PT, ConditionType>>( + return std::make_unique<CustomPredicateCreator<TYPE_DECIMALV2, PT, ConditionType>>( [](const std::string& condition) { decimal12_t value = {0, 0}; value.from_string(condition); @@ -179,16 +179,13 @@ inline std::unique_ptr<PredicateCreator<ConditionType>> get_creator(const FieldT }); } case OLAP_FIELD_TYPE_DECIMAL32: { - return std::make_unique< - DecimalPredicateCreator<TYPE_DECIMAL32, int32_t, PT, ConditionType>>(); + return std::make_unique<DecimalPredicateCreator<TYPE_DECIMAL32, PT, ConditionType>>(); } case OLAP_FIELD_TYPE_DECIMAL64: { - return std::make_unique< - DecimalPredicateCreator<TYPE_DECIMAL64, int64_t, PT, ConditionType>>(); + return std::make_unique<DecimalPredicateCreator<TYPE_DECIMAL64, PT, ConditionType>>(); } case OLAP_FIELD_TYPE_DECIMAL128: { - return std::make_unique< - DecimalPredicateCreator<TYPE_DECIMAL128, int128_t, PT, ConditionType>>(); + return std::make_unique<DecimalPredicateCreator<TYPE_DECIMAL128, PT, ConditionType>>(); } case OLAP_FIELD_TYPE_CHAR: { return std::make_unique<StringPredicateCreator<TYPE_CHAR, PT, ConditionType>>(true); @@ -198,24 +195,23 @@ inline std::unique_ptr<PredicateCreator<ConditionType>> get_creator(const FieldT return std::make_unique<StringPredicateCreator<TYPE_STRING, PT, ConditionType>>(false); } case OLAP_FIELD_TYPE_DATE: { - return std::make_unique<CustomPredicateCreator<TYPE_DATE, uint24_t, PT, ConditionType>>( + return std::make_unique<CustomPredicateCreator<TYPE_DATE, PT, ConditionType>>( timestamp_from_date); } case OLAP_FIELD_TYPE_DATEV2: { - return std::make_unique<CustomPredicateCreator<TYPE_DATEV2, uint32_t, PT, ConditionType>>( + return std::make_unique<CustomPredicateCreator<TYPE_DATEV2, PT, ConditionType>>( timestamp_from_date_v2); } case OLAP_FIELD_TYPE_DATETIME: { - return std::make_unique<CustomPredicateCreator<TYPE_DATETIME, uint64_t, PT, ConditionType>>( + return std::make_unique<CustomPredicateCreator<TYPE_DATETIME, PT, ConditionType>>( timestamp_from_datetime); } case OLAP_FIELD_TYPE_DATETIMEV2: { - return std::make_unique< - CustomPredicateCreator<TYPE_DATETIMEV2, uint64_t, PT, ConditionType>>( + return std::make_unique<CustomPredicateCreator<TYPE_DATETIMEV2, PT, ConditionType>>( timestamp_from_datetime_v2); } case OLAP_FIELD_TYPE_BOOL: { - return std::make_unique<CustomPredicateCreator<TYPE_BOOLEAN, bool, PT, ConditionType>>( + return std::make_unique<CustomPredicateCreator<TYPE_BOOLEAN, PT, ConditionType>>( [](const std::string& condition) { int32_t ivalue = 0; auto result = std::from_chars(condition.data(), diff --git a/be/src/util/date_func.cpp b/be/src/util/date_func.cpp index bebb691afd..2c0ebdd811 100644 --- a/be/src/util/date_func.cpp +++ b/be/src/util/date_func.cpp @@ -41,19 +41,20 @@ uint64_t timestamp_from_datetime(const std::string& datetime_str) { return value; } -uint24_t timestamp_from_date(const std::string& date_str) { +uint32_t timestamp_from_date(const std::string& date_str) { tm time_tm; char* res = strptime(date_str.c_str(), "%Y-%m-%d", &time_tm); - int value = 0; + uint32_t value = 0; if (nullptr != res) { - value = (time_tm.tm_year + 1900) * 16 * 32 + (time_tm.tm_mon + 1) * 32 + time_tm.tm_mday; + value = (uint32_t)((time_tm.tm_year + 1900) * 16 * 32 + (time_tm.tm_mon + 1) * 32 + + time_tm.tm_mday); } else { // 1400 - 01 - 01 value = 716833; } - return uint24_t(value); + return value; } uint32_t timestamp_from_date_v2(const std::string& date_str) { diff --git a/be/src/util/date_func.h b/be/src/util/date_func.h index a10bfd45d4..e5843b64af 100644 --- a/be/src/util/date_func.h +++ b/be/src/util/date_func.h @@ -27,7 +27,7 @@ namespace doris { uint64_t timestamp_from_datetime(const std::string& datetime_str); -uint24_t timestamp_from_date(const std::string& date_str); +uint32_t timestamp_from_date(const std::string& date_str); int32_t time_to_buffer_from_double(double time, char* buffer); uint32_t timestamp_from_date_v2(const std::string& date_str); uint64_t timestamp_from_datetime_v2(const std::string& date_str); diff --git a/be/test/olap/comparison_predicate_test.cpp b/be/test/olap/comparison_predicate_test.cpp index 4095784029..ab61b59fa7 100644 --- a/be/test/olap/comparison_predicate_test.cpp +++ b/be/test/olap/comparison_predicate_test.cpp @@ -34,12 +34,12 @@ namespace doris { namespace datetime { -static uint24_t to_date_timestamp(const char* date_string) { +static uint32_t to_date_timestamp(const char* date_string) { tm time_tm; strptime(date_string, "%Y-%m-%d", &time_tm); int value = (time_tm.tm_year + 1900) * 16 * 32 + (time_tm.tm_mon + 1) * 32 + time_tm.tm_mday; - return uint24_t(value); + return uint32_t(value); } static uint64_t to_datetime_timestamp(const std::string& value_string) { @@ -340,7 +340,7 @@ TEST_F(TestEqualPredicate, DATE_COLUMN) { for (int i = 0; i < tablet_schema->num_columns(); ++i) { return_columns.push_back(i); } - uint24_t value = datetime::to_date_timestamp("2017-09-10"); + uint32_t value = datetime::to_date_timestamp("2017-09-10"); ColumnPredicate* pred = new ComparisonPredicateBase<TYPE_DATE, PredicateType::EQ>(0, value); std::vector<std::string> date_array; @@ -358,7 +358,10 @@ TEST_F(TestEqualPredicate, DATE_COLUMN) { ColumnBlockView col_block_view(&col_block); for (int i = 0; i < size; ++i, col_block_view.advance(1)) { col_block_view.set_null_bits(1, false); - uint24_t timestamp = datetime::to_date_timestamp(date_array[i].c_str()); + const uint32_t tmp = datetime::to_date_timestamp(date_array[i].c_str()); + uint24_t timestamp = 0; + memcpy(reinterpret_cast<void*>(×tamp), reinterpret_cast<const void*>(&tmp), + sizeof(uint24_t)); *reinterpret_cast<uint24_t*>(col_block_view.data()) = timestamp; } pred->evaluate(&col_block, _row_block->selection_vector(), &select_size); @@ -374,7 +377,10 @@ TEST_F(TestEqualPredicate, DATE_COLUMN) { col_block_view.set_null_bits(1, true); } else { col_block_view.set_null_bits(1, false); - uint24_t timestamp = datetime::to_date_timestamp(date_array[i].c_str()); + const uint32_t tmp = datetime::to_date_timestamp(date_array[i].c_str()); + uint24_t timestamp = 0; + memcpy(reinterpret_cast<void*>(×tamp), reinterpret_cast<const void*>(&tmp), + sizeof(uint24_t)); *reinterpret_cast<uint24_t*>(col_block_view.data()) = timestamp; } } @@ -670,7 +676,7 @@ TEST_F(TestLessPredicate, DATE_COLUMN) { for (int i = 0; i < tablet_schema->num_columns(); ++i) { return_columns.push_back(i); } - uint24_t value = datetime::to_date_timestamp("2017-09-10"); + uint32_t value = datetime::to_date_timestamp("2017-09-10"); ColumnPredicate* pred = new ComparisonPredicateBase<TYPE_DATE, PredicateType::LT>(0, value); std::vector<std::string> date_array; @@ -688,7 +694,10 @@ TEST_F(TestLessPredicate, DATE_COLUMN) { ColumnBlockView col_block_view(&col_block); for (int i = 0; i < size; ++i, col_block_view.advance(1)) { col_block_view.set_null_bits(1, false); - uint24_t timestamp = datetime::to_date_timestamp(date_array[i].c_str()); + const uint32_t tmp = datetime::to_date_timestamp(date_array[i].c_str()); + uint24_t timestamp = 0; + memcpy(reinterpret_cast<void*>(×tamp), reinterpret_cast<const void*>(&tmp), + sizeof(uint24_t)); *reinterpret_cast<uint24_t*>(col_block_view.data()) = timestamp; } pred->evaluate(&col_block, _row_block->selection_vector(), &select_size); @@ -704,7 +713,10 @@ TEST_F(TestLessPredicate, DATE_COLUMN) { col_block_view.set_null_bits(1, true); } else { col_block_view.set_null_bits(1, false); - uint24_t timestamp = datetime::to_date_timestamp(date_array[i].c_str()); + const uint32_t tmp = datetime::to_date_timestamp(date_array[i].c_str()); + uint24_t timestamp = 0; + memcpy(reinterpret_cast<void*>(×tamp), reinterpret_cast<const void*>(&tmp), + sizeof(uint24_t)); *reinterpret_cast<uint24_t*>(col_block_view.data()) = timestamp; } } diff --git a/be/test/olap/in_list_predicate_test.cpp b/be/test/olap/in_list_predicate_test.cpp index 4719adf0d2..5d80f7ec49 100644 --- a/be/test/olap/in_list_predicate_test.cpp +++ b/be/test/olap/in_list_predicate_test.cpp @@ -33,12 +33,12 @@ namespace doris { namespace datetime { -static uint24_t timestamp_from_date(const char* date_string) { +static uint32_t timestamp_from_date(const char* date_string) { tm time_tm; strptime(date_string, "%Y-%m-%d", &time_tm); int value = (time_tm.tm_year + 1900) * 16 * 32 + (time_tm.tm_mon + 1) * 32 + time_tm.tm_mday; - return uint24_t(value); + return uint32_t(value); } static uint32_t timestamp_from_date_v2(const char* date_string) { @@ -525,7 +525,7 @@ TEST_F(TestInListPredicate, DATE_COLUMN) { for (int i = 0; i < tablet_schema->num_columns(); ++i) { return_columns.push_back(i); } - phmap::flat_hash_set<uint24_t> values; + phmap::flat_hash_set<uint32_t> values; uint24_t value1 = datetime::timestamp_from_date("2017-09-09"); values.insert(value1); @@ -552,7 +552,7 @@ TEST_F(TestInListPredicate, DATE_COLUMN) { ColumnBlockView col_block_view(&col_block); for (int i = 0; i < size; ++i, col_block_view.advance(1)) { col_block_view.set_null_bits(1, false); - uint24_t timestamp = datetime::timestamp_from_date(date_array[i].c_str()); + uint24_t timestamp = uint24_t(datetime::timestamp_from_date(date_array[i].c_str())); *reinterpret_cast<uint24_t*>(col_block_view.data()) = timestamp; } pred->evaluate(&col_block, _row_block->selection_vector(), &select_size); @@ -574,7 +574,7 @@ TEST_F(TestInListPredicate, DATE_COLUMN) { col_block_view.set_null_bits(1, true); } else { col_block_view.set_null_bits(1, false); - uint24_t timestamp = datetime::timestamp_from_date(date_array[i].c_str()); + uint24_t timestamp = uint24_t(datetime::timestamp_from_date(date_array[i].c_str())); *reinterpret_cast<uint24_t*>(col_block_view.data()) = timestamp; } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org