Skip to content

Commit a5b1446

Browse files
committed
[refactor](field) Remove nearest type in field
1 parent 38e7ffd commit a5b1446

File tree

76 files changed

+1459
-1204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1459
-1204
lines changed

be/src/exec/es/es_scroll_parser.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Status get_int_value(const rapidjson::Value& col, PrimitiveType type, void* slot
190190

191191
template <PrimitiveType T>
192192
Status get_date_value_int(const rapidjson::Value& col, PrimitiveType type, bool is_date_str,
193-
typename PrimitiveTypeTraits<T>::ColumnItemType* slot,
193+
typename PrimitiveTypeTraits<T>::CppType* slot,
194194
const cctz::time_zone& time_zone) {
195195
constexpr bool is_datetime_v1 = T == TYPE_DATE || T == TYPE_DATETIME;
196196
typename PrimitiveTypeTraits<T>::CppType dt_val;
@@ -271,16 +271,13 @@ Status get_date_value_int(const rapidjson::Value& col, PrimitiveType type, bool
271271
}
272272
}
273273

274-
*reinterpret_cast<typename PrimitiveTypeTraits<T>::ColumnItemType*>(slot) =
275-
binary_cast<typename PrimitiveTypeTraits<T>::CppType,
276-
typename PrimitiveTypeTraits<T>::ColumnItemType>(
277-
*reinterpret_cast<typename PrimitiveTypeTraits<T>::CppType*>(&dt_val));
274+
*slot = *reinterpret_cast<typename PrimitiveTypeTraits<T>::CppType*>(&dt_val);
278275
return Status::OK();
279276
}
280277

281278
template <PrimitiveType T>
282279
Status get_date_int(const rapidjson::Value& col, PrimitiveType type, bool pure_doc_value,
283-
typename PrimitiveTypeTraits<T>::ColumnItemType* slot,
280+
typename PrimitiveTypeTraits<T>::CppType* slot,
284281
const cctz::time_zone& time_zone) {
285282
// this would happend just only when `enable_docvalue_scan = false`, and field has timestamp format date from _source
286283
if (col.IsNumber()) {
@@ -309,7 +306,7 @@ Status get_date_int(const rapidjson::Value& col, PrimitiveType type, bool pure_d
309306
template <PrimitiveType T>
310307
Status fill_date_int(const rapidjson::Value& col, PrimitiveType type, bool pure_doc_value,
311308
vectorized::IColumn* col_ptr, const cctz::time_zone& time_zone) {
312-
typename PrimitiveTypeTraits<T>::ColumnItemType data;
309+
typename PrimitiveTypeTraits<T>::CppType data;
313310
RETURN_IF_ERROR((get_date_int<T>(col, type, pure_doc_value, &data, time_zone)));
314311
col_ptr->insert_data(const_cast<const char*>(reinterpret_cast<char*>(&data)), 0);
315312
return Status::OK();
@@ -426,11 +423,11 @@ Status insert_int_value(const rapidjson::Value& col, PrimitiveType type,
426423

427424
template <PrimitiveType T>
428425
Status handle_value(const rapidjson::Value& col, PrimitiveType sub_type, bool pure_doc_value,
429-
typename PrimitiveTypeTraits<T>::ColumnItemType& val) {
426+
typename PrimitiveTypeTraits<T>::CppType& val) {
430427
if constexpr (T == TYPE_TINYINT || T == TYPE_SMALLINT || T == TYPE_INT || T == TYPE_BIGINT ||
431428
T == TYPE_LARGEINT) {
432-
RETURN_IF_ERROR(get_int_value<typename PrimitiveTypeTraits<T>::ColumnItemType>(
433-
col, sub_type, &val, pure_doc_value));
429+
RETURN_IF_ERROR(get_int_value<typename PrimitiveTypeTraits<T>::CppType>(col, sub_type, &val,
430+
pure_doc_value));
434431
return Status::OK();
435432
}
436433
if constexpr (T == TYPE_FLOAT) {
@@ -457,7 +454,7 @@ Status handle_value(const rapidjson::Value& col, PrimitiveType sub_type, bool pu
457454
}
458455

459456
if (col.IsNumber()) {
460-
val = static_cast<typename PrimitiveTypeTraits<T>::ColumnItemType>(col.GetInt());
457+
val = static_cast<typename PrimitiveTypeTraits<T>::CppType>(col.GetInt());
461458
return Status::OK();
462459
}
463460

@@ -485,7 +482,7 @@ Status handle_value(const rapidjson::Value& col, PrimitiveType sub_type, bool pu
485482
template <PrimitiveType T>
486483
Status process_single_column(const rapidjson::Value& col, PrimitiveType sub_type,
487484
bool pure_doc_value, vectorized::Array& array) {
488-
typename PrimitiveTypeTraits<T>::ColumnItemType val;
485+
typename PrimitiveTypeTraits<T>::CppType val;
489486
RETURN_IF_ERROR(handle_value<T>(col, sub_type, pure_doc_value, val));
490487
array.push_back(vectorized::Field::create_field<T>(val));
491488
return Status::OK();
@@ -514,12 +511,12 @@ template <PrimitiveType T>
514511
Status process_date_column(const rapidjson::Value& col, PrimitiveType sub_type, bool pure_doc_value,
515512
vectorized::Array& array, const cctz::time_zone& time_zone) {
516513
if (!col.IsArray()) {
517-
typename PrimitiveTypeTraits<T>::ColumnItemType data;
514+
typename PrimitiveTypeTraits<T>::CppType data;
518515
RETURN_IF_ERROR((get_date_int<T>(col, sub_type, pure_doc_value, &data, time_zone)));
519516
array.push_back(vectorized::Field::create_field<T>(data));
520517
} else {
521518
for (const auto& sub_col : col.GetArray()) {
522-
typename PrimitiveTypeTraits<T>::ColumnItemType data;
519+
typename PrimitiveTypeTraits<T>::CppType data;
523520
RETURN_IF_ERROR((get_date_int<T>(sub_col, sub_type, pure_doc_value, &data, time_zone)));
524521
array.push_back(vectorized::Field::create_field<T>(data));
525522
}
@@ -533,7 +530,7 @@ Status process_jsonb_column(const rapidjson::Value& col, PrimitiveType sub_type,
533530
JsonBinaryValue jsonb_value;
534531
RETURN_IF_ERROR(jsonb_value.from_json_string(json_value_to_string(col)));
535532
vectorized::JsonbField json(jsonb_value.value(), jsonb_value.size());
536-
array.push_back(vectorized::Field::create_field<TYPE_JSONB>(json));
533+
array.push_back(vectorized::Field::create_field<TYPE_JSONB>(std::move(json)));
537534
} else {
538535
for (const auto& sub_col : col.GetArray()) {
539536
JsonBinaryValue jsonb_value;

be/src/exec/olap_common.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ std::string cast_to_string(T value, int scale) {
9696
template <PrimitiveType primitive_type>
9797
class ColumnValueRange {
9898
public:
99-
using CppType = std::conditional_t<primitive_type == TYPE_HLL, StringRef,
100-
typename PrimitiveTypeTraits<primitive_type>::CppType>;
99+
using CppType =
100+
std::conditional_t<primitive_type == TYPE_HLL || is_string_type(primitive_type),
101+
StringRef, typename PrimitiveTypeTraits<primitive_type>::CppType>;
101102
using SetType = std::set<CppType, doris::Less<CppType>>;
102103
using IteratorType = typename SetType::iterator;
103104

@@ -814,8 +815,9 @@ template <PrimitiveType primitive_type>
814815
Status OlapScanKeys::extend_scan_key(ColumnValueRange<primitive_type>& range,
815816
int32_t max_scan_key_num, bool* exact_value, bool* eos,
816817
bool* should_break) {
817-
using CppType = std::conditional_t<primitive_type == TYPE_HLL, StringRef,
818-
typename PrimitiveTypeTraits<primitive_type>::CppType>;
818+
using CppType =
819+
std::conditional_t<primitive_type == TYPE_HLL || is_string_type(primitive_type),
820+
StringRef, typename PrimitiveTypeTraits<primitive_type>::CppType>;
819821
using ConstIterator = typename ColumnValueRange<primitive_type>::SetType::const_iterator;
820822

821823
// 1. clear ScanKey if some column range is empty

be/src/exprs/create_predicate_function.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,15 @@ class HybridSetTraits {
4848
using BasePtr = HybridSetBase*;
4949
template <PrimitiveType type, size_t N>
5050
static BasePtr get_function(bool null_aware) {
51-
using CppType = typename PrimitiveTypeTraits<type>::CppType;
5251
if constexpr (N >= 1 && N <= FIXED_CONTAINER_MAX_SIZE) {
5352
using Set = std::conditional_t<
54-
std::is_same_v<CppType, StringRef>, StringSet<>,
53+
is_string_type(type), StringSet<>,
5554
HybridSet<type,
5655
FixedContainer<typename PrimitiveTypeTraits<type>::CppType, N>>>;
5756
return new Set(null_aware);
5857
} else {
5958
using Set = std::conditional_t<
60-
std::is_same_v<CppType, StringRef>, StringSet<>,
59+
is_string_type(type), StringSet<>,
6160
HybridSet<type, DynamicContainer<typename PrimitiveTypeTraits<type>::CppType>>>;
6261
return new Set(null_aware);
6362
}

be/src/olap/comparison_predicate.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ template <PrimitiveType Type, PredicateType PT>
3434
class ComparisonPredicateBase final : public ColumnPredicate {
3535
public:
3636
ENABLE_FACTORY_CREATOR(ComparisonPredicateBase);
37-
using T = typename PrimitiveTypeTraits<Type>::CppType;
37+
using T = std::conditional_t<is_string_type(Type), StringRef,
38+
typename PrimitiveTypeTraits<Type>::CppType>;
3839
ComparisonPredicateBase(uint32_t column_id, std::string col_name, const T& value,
3940
bool opposite = false)
4041
: ColumnPredicate(column_id, col_name, Type, opposite), _value(value) {}
@@ -167,19 +168,8 @@ class ComparisonPredicateBase final : public ColumnPredicate {
167168
*/
168169

169170
bool camp_field(const vectorized::Field& min_field, const vectorized::Field& max_field) const {
170-
T min_value;
171-
T max_value;
172-
if constexpr (is_int_or_bool(Type) || is_float_or_double(Type)) {
173-
min_value =
174-
(typename PrimitiveTypeTraits<Type>::CppType)min_field
175-
.template get<typename PrimitiveTypeTraits<Type>::NearestFieldType>();
176-
max_value =
177-
(typename PrimitiveTypeTraits<Type>::CppType)max_field
178-
.template get<typename PrimitiveTypeTraits<Type>::NearestFieldType>();
179-
} else {
180-
min_value = min_field.template get<typename PrimitiveTypeTraits<Type>::CppType>();
181-
max_value = max_field.template get<typename PrimitiveTypeTraits<Type>::CppType>();
182-
}
171+
T min_value = min_field.template get<T>();
172+
T max_value = max_field.template get<T>();
183173

184174
if constexpr (PT == PredicateType::EQ) {
185175
return Compare::less_equal(min_value, _value) &&

be/src/olap/delete_handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ Status parse_to_predicate(const uint32_t index, const std::string col_name,
317317
case TYPE_CHAR:
318318
case TYPE_VARCHAR:
319319
case TYPE_STRING: {
320-
RETURN_IF_ERROR(convert<TYPE_STRING>(type, res.value_str.front(), arena, v));
320+
v = {res.value_str.front().data(), res.value_str.front().size()};
321321
switch (res.condition_op) {
322322
case PredicateType::EQ:
323323
predicate = create_comparison_predicate0<PredicateType::EQ>(index, col_name, type, v,

be/src/olap/in_list_predicate.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ template <PrimitiveType Type, PredicateType PT, int N>
6666
class InListPredicateBase final : public ColumnPredicate {
6767
public:
6868
ENABLE_FACTORY_CREATOR(InListPredicateBase);
69-
using T = typename PrimitiveTypeTraits<Type>::CppType;
69+
using T = std::conditional_t<is_string_type(Type), StringRef,
70+
typename PrimitiveTypeTraits<Type>::CppType>;
7071
using HybridSetType = std::conditional_t<
7172
N >= 1 && N <= FIXED_CONTAINER_MAX_SIZE,
7273
std::conditional_t<
@@ -254,19 +255,8 @@ class InListPredicateBase final : public ColumnPredicate {
254255
}
255256

256257
bool camp_field(const vectorized::Field& min_field, const vectorized::Field& max_field) const {
257-
T min_value;
258-
T max_value;
259-
if constexpr (is_int_or_bool(Type) || is_float_or_double(Type)) {
260-
min_value =
261-
(typename PrimitiveTypeTraits<Type>::CppType)min_field
262-
.template get<typename PrimitiveTypeTraits<Type>::NearestFieldType>();
263-
max_value =
264-
(typename PrimitiveTypeTraits<Type>::CppType)max_field
265-
.template get<typename PrimitiveTypeTraits<Type>::NearestFieldType>();
266-
} else {
267-
min_value = min_field.template get<typename PrimitiveTypeTraits<Type>::CppType>();
268-
max_value = max_field.template get<typename PrimitiveTypeTraits<Type>::CppType>();
269-
}
258+
T min_value = min_field.template get<T>();
259+
T max_value = max_field.template get<T>();
270260

271261
if constexpr (PT == PredicateType::IN_LIST) {
272262
return (Compare::less_equal(min_value, _max_value) &&

be/src/olap/rowset/segment_v2/inverted_index_reader.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,7 @@ class InvertedIndexQueryParamFactory {
405405
} else {
406406
CPP_TYPE cpp_val;
407407
if constexpr (std::is_same_v<ValueType, doris::vectorized::Field>) {
408-
auto field_val =
409-
doris::vectorized::get<doris::vectorized::NearestFieldType<CPP_TYPE>>(
410-
*value);
408+
auto field_val = value->template get<typename PrimitiveTypeTraits<PT>::CppType>();
411409
cpp_val = static_cast<CPP_TYPE>(field_val);
412410
} else {
413411
cpp_val = static_cast<CPP_TYPE>(*value);

be/src/olap/rowset/segment_v2/zone_map_index.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ void TypedZoneMapIndexWriter<Type>::add_values(const void* values, size_t count)
5858
if (count > 0) {
5959
_page_zone_map.has_not_null = true;
6060
}
61-
using ValType = PrimitiveTypeTraits<Type>::StorageFieldType;
61+
using ValType = std::conditional_t<is_string_type(Type), StringRef,
62+
typename PrimitiveTypeTraits<Type>::StorageFieldType>;
6263
const auto* vals = reinterpret_cast<const ValType*>(values);
6364
if constexpr (Type == TYPE_FLOAT || Type == TYPE_DOUBLE) {
6465
ValType min = std::numeric_limits<ValType>::max();

be/src/pipeline/exec/scan_operator.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -954,17 +954,15 @@ Status ScanLocalState<Derived>::_change_value_range(ColumnValueRange<PrimitiveTy
954954
func(temp_range, to_olap_filter_type(fn_name),
955955
reinterpret_cast<const StringRef*>(value));
956956
}
957-
} else if constexpr ((PrimitiveType == TYPE_DECIMALV2) || (PrimitiveType == TYPE_CHAR) ||
958-
(PrimitiveType == TYPE_VARCHAR) || (PrimitiveType == TYPE_DATETIMEV2) ||
957+
} else if constexpr ((PrimitiveType == TYPE_DECIMALV2) || (PrimitiveType == TYPE_DATETIMEV2) ||
959958
(PrimitiveType == TYPE_TINYINT) || (PrimitiveType == TYPE_SMALLINT) ||
960959
(PrimitiveType == TYPE_INT) || (PrimitiveType == TYPE_BIGINT) ||
961960
(PrimitiveType == TYPE_LARGEINT) || (PrimitiveType == TYPE_FLOAT) ||
962961
(PrimitiveType == TYPE_DOUBLE) || (PrimitiveType == TYPE_IPV4) ||
963962
(PrimitiveType == TYPE_IPV6) || (PrimitiveType == TYPE_DECIMAL32) ||
964963
(PrimitiveType == TYPE_DECIMAL64) || (PrimitiveType == TYPE_DECIMAL128I) ||
965-
(PrimitiveType == TYPE_DECIMAL256) || (PrimitiveType == TYPE_STRING) ||
966-
(PrimitiveType == TYPE_BOOLEAN) || (PrimitiveType == TYPE_DATEV2) ||
967-
(PrimitiveType == TYPE_TIMESTAMPTZ)) {
964+
(PrimitiveType == TYPE_DECIMAL256) || (PrimitiveType == TYPE_BOOLEAN) ||
965+
(PrimitiveType == TYPE_DATEV2) || (PrimitiveType == TYPE_TIMESTAMPTZ)) {
968966
if constexpr (IsFixed) {
969967
func(temp_range,
970968
reinterpret_cast<const typename PrimitiveTypeTraits<PrimitiveType>::CppType*>(
@@ -974,6 +972,13 @@ Status ScanLocalState<Derived>::_change_value_range(ColumnValueRange<PrimitiveTy
974972
reinterpret_cast<const typename PrimitiveTypeTraits<PrimitiveType>::CppType*>(
975973
value));
976974
}
975+
} else if constexpr (is_string_type(PrimitiveType)) {
976+
if constexpr (IsFixed) {
977+
func(temp_range, reinterpret_cast<const StringRef*>(value));
978+
} else {
979+
func(temp_range, to_olap_filter_type(fn_name, slot_ref_child),
980+
reinterpret_cast<const StringRef*>(value));
981+
}
977982
} else {
978983
static_assert(always_false_v<PrimitiveType>);
979984
}

0 commit comments

Comments
 (0)