Skip to content

Commit 8342f80

Browse files
committed
[refactor](be) Strengthen enum type safety in execution and expressions
### What problem does this PR solve? Issue Number: N/A Problem Summary: Unscoped enums and integer interfaces weaken compile-time type checking. Use scoped enums for tablet routing, function state scope and geometry, type Hash Join template parameters and runtime-filter/WKB interfaces, and update callers. Preserve encoded values and leave DateTime value types unchanged. ### Release note None ### Check List (For Author) - Test: No need to test (type-safety refactoring covered by existing tests); clang-format 16, git diff --check and build hygiene passed. Compilation, unit tests, regression tests and clang-tidy were not run. - Behavior changed: No - Does this need documentation: No
1 parent 3b8eb5b commit 8342f80

104 files changed

Lines changed: 785 additions & 689 deletions

File tree

Some content is hidden

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

‎be/benchmark/benchmark_array_range.hpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ static void BM_ArrayRange(benchmark::State& state) {
5454
"array_range", block.get_columns_with_type_and_name(), result_type);
5555
auto context =
5656
FunctionContext::create_context(nullptr, result_type, {int_type, int_type, int_type});
57-
auto status = function->open(context.get(), FunctionContext::FRAGMENT_LOCAL);
57+
auto status =
58+
function->open(context.get(), FunctionContext::FunctionStateScope::FRAGMENT_LOCAL);
5859
if (!status.ok()) {
5960
state.SkipWithError(status.to_string().c_str());
6061
return;
6162
}
62-
status = function->open(context.get(), FunctionContext::THREAD_LOCAL);
63+
status = function->open(context.get(), FunctionContext::FunctionStateScope::THREAD_LOCAL);
6364
if (!status.ok()) {
6465
state.SkipWithError(status.to_string().c_str());
6566
return;
@@ -74,11 +75,11 @@ static void BM_ArrayRange(benchmark::State& state) {
7475
benchmark::DoNotOptimize(block.get_by_position(3).column);
7576
benchmark::ClobberMemory();
7677
}
77-
status = function->close(context.get(), FunctionContext::THREAD_LOCAL);
78+
status = function->close(context.get(), FunctionContext::FunctionStateScope::THREAD_LOCAL);
7879
if (!status.ok()) {
7980
state.SkipWithError(status.to_string().c_str());
8081
}
81-
status = function->close(context.get(), FunctionContext::FRAGMENT_LOCAL);
82+
status = function->close(context.get(), FunctionContext::FunctionStateScope::FRAGMENT_LOCAL);
8283
if (!status.ok()) {
8384
state.SkipWithError(status.to_string().c_str());
8485
}

‎be/benchmark/benchmark_binary_arithmetic.hpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ struct BinaryArithmeticRunner {
6464
}
6565
ctx = FunctionContext::create_context(nullptr, res_type, {type_a, type_b});
6666
ctx->set_check_overflow_for_decimal(true);
67-
if (!func->open(ctx.get(), FunctionContext::FRAGMENT_LOCAL).ok() ||
68-
!func->open(ctx.get(), FunctionContext::THREAD_LOCAL).ok()) {
67+
if (!func->open(ctx.get(), FunctionContext::FunctionStateScope::FRAGMENT_LOCAL).ok() ||
68+
!func->open(ctx.get(), FunctionContext::FunctionStateScope::THREAD_LOCAL).ok()) {
6969
throw std::runtime_error(name + " open failed");
7070
}
7171
block.insert({nullptr, res_type, "result"});

‎be/benchmark/benchmark_character_encoding.hpp‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,27 @@ void BM_character_encoding(benchmark::State& state) {
107107
return;
108108
}
109109
auto context = FunctionContext::create_context(nullptr, result_type, {input_type, string_type});
110-
auto status = function->open(context.get(), FunctionContext::FRAGMENT_LOCAL);
110+
auto status =
111+
function->open(context.get(), FunctionContext::FunctionStateScope::FRAGMENT_LOCAL);
111112
if (!status.ok()) {
112113
state.SkipWithError(status.to_string());
113114
return;
114115
}
115116
Defer close_fragment {[&] {
116-
auto close_status = function->close(context.get(), FunctionContext::FRAGMENT_LOCAL);
117+
auto close_status =
118+
function->close(context.get(), FunctionContext::FunctionStateScope::FRAGMENT_LOCAL);
117119
if (!close_status.ok()) {
118120
state.SkipWithError(close_status.to_string());
119121
}
120122
}};
121-
status = function->open(context.get(), FunctionContext::THREAD_LOCAL);
123+
status = function->open(context.get(), FunctionContext::FunctionStateScope::THREAD_LOCAL);
122124
if (!status.ok()) {
123125
state.SkipWithError(status.to_string());
124126
return;
125127
}
126128
Defer close_thread {[&] {
127-
auto close_status = function->close(context.get(), FunctionContext::THREAD_LOCAL);
129+
auto close_status =
130+
function->close(context.get(), FunctionContext::FunctionStateScope::THREAD_LOCAL);
128131
if (!close_status.ok()) {
129132
state.SkipWithError(close_status.to_string());
130133
}

‎be/benchmark/variant/benchmark_variant_segment.hpp‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,15 @@ Status parse_json_batch(ColumnPtr json, const LayoutConfig& config, uint32_t row
369369
DORIS_CHECK(function != nullptr);
370370
block.insert({nullptr, result_type, "result"});
371371
auto context = FunctionContext::create_context(nullptr, result_type, {input_type});
372-
RETURN_IF_ERROR(function->open(context.get(), FunctionContext::FRAGMENT_LOCAL));
373-
RETURN_IF_ERROR(function->open(context.get(), FunctionContext::THREAD_LOCAL));
372+
RETURN_IF_ERROR(
373+
function->open(context.get(), FunctionContext::FunctionStateScope::FRAGMENT_LOCAL));
374+
RETURN_IF_ERROR(
375+
function->open(context.get(), FunctionContext::FunctionStateScope::THREAD_LOCAL));
374376
Status status = function->execute(context.get(), block, {0}, 1, rows);
375-
Status close_thread = function->close(context.get(), FunctionContext::THREAD_LOCAL);
376-
Status close_fragment = function->close(context.get(), FunctionContext::FRAGMENT_LOCAL);
377+
Status close_thread =
378+
function->close(context.get(), FunctionContext::FunctionStateScope::THREAD_LOCAL);
379+
Status close_fragment =
380+
function->close(context.get(), FunctionContext::FunctionStateScope::FRAGMENT_LOCAL);
377381
RETURN_IF_ERROR(status);
378382
RETURN_IF_ERROR(close_thread);
379383
RETURN_IF_ERROR(close_fragment);

‎be/src/core/column/column_vector.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#pragma once
2222

23+
#include <gen_cpp/PlanNodes_types.h>
2324
#include <glog/logging.h>
2425
#include <sys/types.h>
2526

@@ -54,7 +55,7 @@
5455
class SipHash;
5556

5657
namespace doris {
57-
template <int JoinOpType>
58+
template <TJoinOp::type JoinOpType>
5859
struct ProcessHashTableProbe;
5960
}
6061

@@ -77,7 +78,7 @@ class ColumnVector final : public COWHelper<IColumn, ColumnVector<T>> {
7778
using Self = ColumnVector;
7879
friend class COWHelper<IColumn, Self>;
7980

80-
template <int JoinOpType>
81+
template <TJoinOp::type JoinOpType>
8182
friend struct doris::ProcessHashTableProbe;
8283

8384
struct less;

‎be/src/exec/common/hash_table/join_hash_table.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class JoinHashTable {
4747
return cal_vector_mem(visited) + cal_vector_mem(first) + cal_vector_mem(next);
4848
}
4949

50-
template <int JoinOpType>
50+
template <TJoinOp::type JoinOpType>
5151
void prepare_build(size_t num_elem, int batch_size, bool has_null_key,
5252
uint32_t force_bucket_size) {
5353
_has_null_key = has_null_key;
@@ -99,7 +99,7 @@ class JoinHashTable {
9999
_keep_null_key = keep_null_key;
100100
}
101101

102-
template <int JoinOpType>
102+
template <TJoinOp::type JoinOpType>
103103
auto find_batch(const Key* __restrict keys, const uint32_t* __restrict build_idx_map,
104104
int probe_idx, uint32_t build_idx, int probe_rows,
105105
uint32_t* __restrict probe_idxs, bool& probe_visited,
@@ -196,7 +196,7 @@ class JoinHashTable {
196196
}
197197
}
198198

199-
template <int JoinOpType, bool is_mark_join>
199+
template <TJoinOp::type JoinOpType, bool is_mark_join>
200200
bool iterate_map(ColumnOffset32& build_idxs, ColumnFilterHelper* mark_column_helper) const {
201201
const auto batch_size = max_batch_size;
202202
const auto elem_num = visited.size();
@@ -241,7 +241,7 @@ class JoinHashTable {
241241
return lhs == rhs;
242242
}
243243

244-
template <int JoinOpType>
244+
template <TJoinOp::type JoinOpType>
245245
auto _process_null_aware_left_half_join_for_empty_build_side(int probe_idx, int probe_rows,
246246
uint32_t* __restrict probe_idxs,
247247
uint32_t* __restrict build_idxs) {
@@ -289,7 +289,7 @@ class JoinHashTable {
289289
return std::tuple {probe_idx, 0U, 0U};
290290
}
291291

292-
template <int JoinOpType, bool has_null_map>
292+
template <TJoinOp::type JoinOpType, bool has_null_map>
293293
auto _find_batch_left_semi_anti(const Key* __restrict keys,
294294
const uint32_t* __restrict build_idx_map, int probe_idx,
295295
int probe_rows, uint32_t* __restrict probe_idxs,
@@ -317,7 +317,7 @@ class JoinHashTable {
317317
return std::tuple {probe_idx, 0U, matched_cnt};
318318
}
319319

320-
template <int JoinOpType, bool only_need_to_match_one>
320+
template <TJoinOp::type JoinOpType, bool only_need_to_match_one>
321321
auto _find_batch_conjunct(const Key* __restrict keys, const uint32_t* __restrict build_idx_map,
322322
int probe_idx, uint32_t build_idx, int probe_rows,
323323
uint32_t* __restrict probe_idxs, uint32_t* __restrict build_idxs) {
@@ -370,7 +370,7 @@ class JoinHashTable {
370370
return std::tuple {probe_idx, build_idx, matched_cnt};
371371
}
372372

373-
template <int JoinOpType>
373+
template <TJoinOp::type JoinOpType>
374374
auto _find_batch_inner_outer_join(const Key* __restrict keys,
375375
const uint32_t* __restrict build_idx_map, int probe_idx,
376376
uint32_t build_idx, int probe_rows,

‎be/src/exec/common/join_op_utils.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ inline bool is_asof_join(TJoinOp::type join_op) {
5252
return join_op == TJoinOp::ASOF_LEFT_INNER_JOIN || join_op == TJoinOp::ASOF_LEFT_OUTER_JOIN;
5353
}
5454

55-
template <int JoinOpType>
55+
template <TJoinOp::type JoinOpType>
5656
inline constexpr bool is_asof_join_op_v =
5757
JoinOpType == TJoinOp::ASOF_LEFT_INNER_JOIN || JoinOpType == TJoinOp::ASOF_LEFT_OUTER_JOIN;
5858

59-
template <int JoinOpType>
59+
template <TJoinOp::type JoinOpType>
6060
inline constexpr bool is_asof_outer_join_op_v = JoinOpType == TJoinOp::ASOF_LEFT_OUTER_JOIN;
6161

6262
// ASOF JOIN index with inline values for cache-friendly branchless binary search.

‎be/src/exec/operator/hashjoin_build_sink.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ struct ProcessHashTableBuild {
216216
_batch_size(batch_size),
217217
_state(state) {}
218218

219-
template <int JoinOpType>
219+
template <TJoinOp::type JoinOpType>
220220
Status run(HashTableContext& hash_table_ctx, ConstNullMapPtr null_map, bool* has_null_key,
221221
bool short_circuit_for_null, bool with_other_conjuncts) {
222222
if (null_map) {

‎be/src/exec/operator/hashjoin_probe_operator.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class HashJoinProbeLocalState MOCK_REMOVE(final)
7373
std::vector<uint16_t> _convert_block_to_null(Block& block);
7474
Status _extract_join_column(Block& block, const std::vector<int>& res_col_ids);
7575
friend class HashJoinProbeOperatorX;
76-
template <int JoinOpType>
76+
template <TJoinOp::type JoinOpType>
7777
friend struct ProcessHashTableProbe;
7878

7979
// one probe row may match multiple build rows. and we need output whenever we filled a block.
@@ -184,7 +184,7 @@ class HashJoinProbeOperatorX MOCK_REMOVE(final)
184184
RuntimeProfile::Counter& expr_call_timer,
185185
std::vector<int>& res_col_ids) const;
186186
friend class HashJoinProbeLocalState;
187-
template <int JoinOpType>
187+
template <TJoinOp::type JoinOpType>
188188
friend struct ProcessHashTableProbe;
189189

190190
const TJoinDistributionType::type _join_distribution;

‎be/src/exec/operator/join/process_hash_table_probe.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ using MutableColumns = std::vector<MutableColumnPtr>;
3939
using NullMap = ColumnUInt8::Container;
4040
using ConstNullMapPtr = const NullMap*;
4141

42-
template <int JoinOpType>
42+
template <TJoinOp::type JoinOpType>
4343
struct ProcessHashTableProbe {
4444
ProcessHashTableProbe(HashJoinProbeLocalState* parent, int batch_size);
4545
~ProcessHashTableProbe() = default;

0 commit comments

Comments
 (0)