Skip to content

Commit 89035d7

Browse files
authored
[refactor](type) Use PrimitiveType to replace TypeIndex (PART II) (apache#50700)
### What problem does this PR solve? Issue Number: close #xxx Related PR: #xxx Problem Summary: ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason <!-- Add your reason? --> - Behavior changed: - [ ] No. - [ ] Yes. <!-- Explain the behavior change --> - Does this need documentation? - [ ] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
1 parent 125e8ec commit 89035d7

File tree

128 files changed

+1320
-1361
lines changed

Some content is hidden

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

128 files changed

+1320
-1361
lines changed

be/src/olap/rowset/segment_creator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Status SegmentFlusher::_internal_parse_variant_columns(vectorized::Block& block)
9393
std::vector<int> variant_column_pos;
9494
for (int i = 0; i < block.columns(); ++i) {
9595
const auto& entry = block.get_by_position(i);
96-
if (vectorized::is_variant_type(remove_nullable(entry.type))) {
96+
if (entry.type->get_primitive_type() == TYPE_VARIANT) {
9797
variant_column_pos.push_back(i);
9898
}
9999
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ class Segment : public std::enable_shared_from_this<Segment>, public MetadataAdd
204204
// Default column iterator
205205
return true;
206206
}
207-
if (vectorized::WhichDataType(vectorized::remove_nullable(storage_column_type))
208-
.is_variant_type()) {
207+
if (storage_column_type->get_primitive_type() == TYPE_VARIANT) {
209208
// Predicate should nerver apply on variant type
210209
return false;
211210
}

be/src/pipeline/exec/aggregation_source_operator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ Status AggLocalState::_get_without_key_result(RuntimeState* state, vectorized::B
405405
for (int i = 0; i < block_schema.size(); ++i) {
406406
const auto column_type = block_schema[i].type;
407407
if (!column_type->equals(*data_types[i])) {
408-
if (!vectorized::is_array(remove_nullable(column_type))) {
408+
if (column_type->get_primitive_type() != TYPE_ARRAY) {
409409
if (!column_type->is_nullable() || data_types[i]->is_nullable() ||
410410
!remove_nullable(column_type)->equals(*data_types[i])) {
411411
return Status::InternalError(

be/src/runtime/primitive_type.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ constexpr bool is_date_type(PrimitiveType type) {
100100
type == TYPE_DATEV2;
101101
}
102102

103+
constexpr bool is_date_or_datetime(PrimitiveType type) {
104+
return type == TYPE_DATETIME || type == TYPE_DATE;
105+
}
106+
107+
constexpr bool is_date_v2_or_datetime_v2(PrimitiveType type) {
108+
return type == TYPE_DATETIMEV2 || type == TYPE_DATEV2;
109+
}
110+
111+
constexpr bool is_ip(PrimitiveType type) {
112+
return type == TYPE_IPV4 || type == TYPE_IPV6;
113+
}
114+
103115
constexpr bool is_string_type(PrimitiveType type) {
104116
return type == TYPE_CHAR || type == TYPE_VARCHAR || type == TYPE_STRING;
105117
}
@@ -120,16 +132,24 @@ constexpr bool is_float_or_double(PrimitiveType type) {
120132
return type == TYPE_FLOAT || type == TYPE_DOUBLE;
121133
}
122134

135+
constexpr bool is_int(PrimitiveType type) {
136+
return type == TYPE_TINYINT || type == TYPE_SMALLINT || type == TYPE_INT ||
137+
type == TYPE_BIGINT || type == TYPE_LARGEINT;
138+
}
139+
123140
constexpr bool is_int_or_bool(PrimitiveType type) {
124-
return type == TYPE_BOOLEAN || type == TYPE_TINYINT || type == TYPE_SMALLINT ||
125-
type == TYPE_INT || type == TYPE_BIGINT || type == TYPE_LARGEINT;
141+
return type == TYPE_BOOLEAN || is_int(type);
126142
}
127143

128144
constexpr bool is_decimal(PrimitiveType type) {
129145
return type == TYPE_DECIMAL32 || type == TYPE_DECIMAL64 || type == TYPE_DECIMAL128I ||
130146
type == TYPE_DECIMAL256 || type == TYPE_DECIMALV2;
131147
}
132148

149+
constexpr bool is_number(PrimitiveType type) {
150+
return is_int_or_bool(type) || is_float_or_double(type) || is_decimal(type);
151+
}
152+
133153
PrimitiveType thrift_to_type(TPrimitiveType::type ttype);
134154
TPrimitiveType::type to_thrift(PrimitiveType ptype);
135155
std::string type_to_string(PrimitiveType t);

be/src/vec/aggregate_functions/aggregate_function_corr.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ AggregateFunctionPtr create_aggregate_corr_welford_function(const std::string& n
3939
const AggregateFunctionAttr& attr) {
4040
assert_binary(name, argument_types);
4141

42-
WhichDataType which0(remove_nullable(argument_types[0]));
43-
WhichDataType which1(remove_nullable(argument_types[1]));
44-
45-
if (!which0.is_float64() || !which1.is_float64()) {
42+
if (argument_types[0]->get_primitive_type() != TYPE_DOUBLE ||
43+
argument_types[1]->get_primitive_type() != TYPE_DOUBLE) {
4644
throw doris::Exception(ErrorCode::INTERNAL_ERROR,
4745
"Aggregate function {} only support double", name);
4846
}

be/src/vec/aggregate_functions/aggregate_function_count_by_enum.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ AggregateFunctionPtr create_aggregate_function_count_by_enum(const std::string&
4343
type = assert_cast<const DataTypeNullable*>(type)->get_nested_type().get();
4444
}
4545

46-
WhichDataType which(*type);
47-
48-
if (which.is_string()) {
46+
if (is_string_type(type->get_primitive_type())) {
4947
return std::make_shared<AggregateFunctionCountByEnum<AggregateFunctionCountByEnumData>>(
5048
argument_types);
5149
}

be/src/vec/aggregate_functions/aggregate_function_group_array_intersect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ AggregateFunctionPtr create_aggregate_function_group_array_intersect(
101101
assert_unary(name, argument_types);
102102
const DataTypePtr& argument_type = remove_nullable(argument_types[0]);
103103

104-
if (!WhichDataType(argument_type).is_array())
104+
if (argument_type->get_primitive_type() != TYPE_ARRAY)
105105
throw Exception(ErrorCode::INVALID_ARGUMENT,
106106
"Aggregate function groupArrayIntersect accepts only array type argument. "
107107
"Provided argument type: " +

be/src/vec/aggregate_functions/aggregate_function_map.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ AggregateFunctionPtr create_aggregate_function_map_agg(const std::string& name,
3535
const DataTypes& argument_types,
3636
const bool result_is_nullable,
3737
const AggregateFunctionAttr& attr) {
38-
WhichDataType type(remove_nullable(argument_types[0]));
3938
switch (argument_types[0]->get_primitive_type()) {
4039
case PrimitiveType::TYPE_BOOLEAN:
4140
return create_agg_function_map_agg<UInt8>(argument_types, result_is_nullable);

be/src/vec/aggregate_functions/aggregate_function_orthogonal_bitmap.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,13 @@ AggregateFunctionPtr create_aggregate_function_orthogonal(const std::string& nam
4545
return creator_without_type::create<AggFunctionOrthBitmapFunc<Impl<StringRef>>>(
4646
argument_types, result_is_nullable);
4747
} else {
48-
WhichDataType which(*remove_nullable(argument_types[1]));
49-
5048
AggregateFunctionPtr res(
5149
creator_with_type_base<true, true, false, 1>::create<AggFunctionOrthBitmapFunc,
5250
Impl>(argument_types,
5351
result_is_nullable));
5452
if (res) {
5553
return res;
56-
} else if (which.is_string_or_fixed_string()) {
54+
} else if (is_string_type(argument_types[1]->get_primitive_type())) {
5755
res = creator_without_type::create<AggFunctionOrthBitmapFunc<Impl<std::string_view>>>(
5856
argument_types, result_is_nullable);
5957
return res;

be/src/vec/aggregate_functions/aggregate_function_rpc.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -297,22 +297,25 @@ struct AggregateRpcUdafData {
297297
result_type =
298298
reinterpret_cast<const DataTypeNullable*>(return_type.get())->get_nested_type();
299299
}
300-
WhichDataType which(result_type);
301-
if (which.is_float32()) {
300+
switch (result_type->get_primitive_type()) {
301+
case TYPE_FLOAT:
302302
GETDATA(float, float);
303-
} else if (which.is_float64()) {
303+
break;
304+
case TYPE_DOUBLE:
304305
GETDATA(double, double);
305-
} else if (which.is_int32()) {
306+
break;
307+
case TYPE_INT:
306308
GETDATA(int32_t, int32);
307-
} else if (which.is_uint32()) {
308-
GETDATA(uint32_t, uint32);
309-
} else if (which.is_int64()) {
309+
break;
310+
case TYPE_BIGINT:
310311
GETDATA(int64_t, int64);
311-
} else if (which.is_uint64()) {
312-
GETDATA(uint64_t, uint64);
313-
} else if (which.is_uint8()) {
312+
break;
313+
case TYPE_BOOLEAN:
314314
GETDATA(uint8_t, bool);
315-
} else if (which.is_string()) {
315+
break;
316+
case TYPE_STRING:
317+
case TYPE_CHAR:
318+
case TYPE_VARCHAR: {
316319
if (response.result_size() > 0 && response.result(0).string_value_size() > 0) {
317320
std::string ret = response.result(0).string_value(0);
318321
to.insert_data(ret.c_str(), ret.size());
@@ -322,7 +325,9 @@ struct AggregateRpcUdafData {
322325
"result is empty";
323326
to.insert_default();
324327
}
325-
} else {
328+
break;
329+
}
330+
default:
326331
LOG(ERROR) << "failed to get result cause unkown return type";
327332
to.insert_default();
328333
}

0 commit comments

Comments
 (0)