Skip to content

Commit 8234515

Browse files
committed
[refactor](field) Remove nearest type in field
1 parent b1303c3 commit 8234515

File tree

60 files changed

+788
-1022
lines changed

Some content is hidden

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

60 files changed

+788
-1022
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/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, const T& value, bool opposite = false)
3940
: ColumnPredicate(column_id, Type, opposite), _value(value) {}
4041
ComparisonPredicateBase(const ComparisonPredicateBase<Type, PT>& other, uint32_t col_id)
@@ -166,19 +167,8 @@ class ComparisonPredicateBase final : public ColumnPredicate {
166167
*/
167168

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

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

be/src/olap/delete_handler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ Status parse_to_predicate(const uint32_t index, const vectorized::DataTypePtr& t
315315
case TYPE_CHAR:
316316
case TYPE_VARCHAR:
317317
case TYPE_STRING: {
318-
RETURN_IF_ERROR(convert<TYPE_STRING>(type, res.value_str.front(), arena, v));
318+
auto tmp = vectorized::String(v.data, v.size);
319+
RETURN_IF_ERROR(convert<TYPE_STRING>(type, res.value_str.front(), arena, tmp));
319320
switch (res.condition_op) {
320321
case PredicateType::EQ:
321322
predicate =

be/src/olap/in_list_predicate.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -276,19 +276,8 @@ class InListPredicateBase final : public ColumnPredicate {
276276
}
277277

278278
bool camp_field(const vectorized::Field& min_field, const vectorized::Field& max_field) const {
279-
T min_value;
280-
T max_value;
281-
if constexpr (is_int_or_bool(Type) || is_float_or_double(Type)) {
282-
min_value =
283-
(typename PrimitiveTypeTraits<Type>::CppType)min_field
284-
.template get<typename PrimitiveTypeTraits<Type>::NearestFieldType>();
285-
max_value =
286-
(typename PrimitiveTypeTraits<Type>::CppType)max_field
287-
.template get<typename PrimitiveTypeTraits<Type>::NearestFieldType>();
288-
} else {
289-
min_value = min_field.template get<typename PrimitiveTypeTraits<Type>::CppType>();
290-
max_value = max_field.template get<typename PrimitiveTypeTraits<Type>::CppType>();
291-
}
279+
T min_value = min_field.template get<typename PrimitiveTypeTraits<Type>::CppType>();
280+
T max_value = max_field.template get<typename PrimitiveTypeTraits<Type>::CppType>();
292281

293282
if constexpr (PT == PredicateType::IN_LIST) {
294283
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();

0 commit comments

Comments
 (0)