Skip to content

Commit f98de0c

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 9c0d793 commit f98de0c

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

‎be/src/exprs/function/ai/ai_functions.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class AIFunction : public IFunction {
6767
bool is_blockable() const override { return true; }
6868

6969
Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) override {
70-
if (scope == FunctionContext::THREAD_LOCAL) {
70+
if (scope == FunctionContext::FunctionStateScope::THREAD_LOCAL) {
7171
// Release this execution context's cached clients.
7272
context->set_function_state(scope, nullptr);
7373
}
@@ -181,11 +181,12 @@ class AIFunction : public IFunction {
181181
FunctionContext* context) const {
182182
// Retain the cache across batches/Blocks.
183183
auto* executor = static_cast<AIRequestExecutor*>(
184-
context->get_function_state(FunctionContext::THREAD_LOCAL));
184+
context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL));
185185
if (executor == nullptr) {
186186
auto state = std::make_shared<AIRequestExecutor>();
187187
executor = state.get();
188-
context->set_function_state(FunctionContext::THREAD_LOCAL, std::move(state));
188+
context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL,
189+
std::move(state));
189190
}
190191
return executor->execute(request_body, response, config, *adapter,
191192
context->state()->get_query_ctx());

‎be/test/ai/ai_request_executor_test.cpp‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@ class AIRequestExecutorTest : public testing::Test {
194194
auto second_context = context->clone();
195195
if (share_executor) {
196196
auto shared_executor = std::make_shared<AIRequestExecutor>();
197-
context->set_function_state(FunctionContext::THREAD_LOCAL, shared_executor);
198-
second_context->set_function_state(FunctionContext::THREAD_LOCAL, shared_executor);
197+
context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL,
198+
shared_executor);
199+
second_context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL,
200+
shared_executor);
199201
}
200202
std::mutex gate_mutex;
201203
std::condition_variable gate;
@@ -220,8 +222,9 @@ class AIRequestExecutorTest : public testing::Test {
220222
EXPECT_TRUE(first.get().ok());
221223
EXPECT_TRUE(second.get().ok());
222224
EXPECT_TRUE(both_arrived);
223-
EXPECT_EQ(context->get_function_state(FunctionContext::THREAD_LOCAL) ==
224-
second_context->get_function_state(FunctionContext::THREAD_LOCAL),
225+
EXPECT_EQ(context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL) ==
226+
second_context->get_function_state(
227+
FunctionContext::FunctionStateScope::THREAD_LOCAL),
225228
share_executor);
226229
EXPECT_EQ(connection_count(), 2);
227230
handler.on_request = {};
@@ -308,7 +311,8 @@ TEST_F(AIRequestExecutorTest, ScalarReusesConnectionAcrossBatchesAndBlocksWithNu
308311
EXPECT_NE(handler.bodies[0].find("first"), std::string::npos);
309312
EXPECT_NE(handler.bodies[1].find("second"), std::string::npos);
310313
std::weak_ptr<void> owner = context->_thread_local_fn_state;
311-
ASSERT_TRUE(function.close(context.get(), FunctionContext::THREAD_LOCAL).ok());
314+
ASSERT_TRUE(
315+
function.close(context.get(), FunctionContext::FunctionStateScope::THREAD_LOCAL).ok());
312316
EXPECT_TRUE(owner.expired());
313317
}
314318

‎be/test/exprs/function/function_like_test.cpp‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,10 @@ TEST(FunctionLikeTest, regexp_extract_all_boost_zero_width_match) {
789789
fn_ctx->set_constant_cols(
790790
{nullptr, std::make_shared<ColumnPtrWrapper>(block.get_by_position(1).column)});
791791

792-
ASSERT_EQ(Status::OK(), func->open(fn_ctx, FunctionContext::FRAGMENT_LOCAL));
793-
ASSERT_EQ(Status::OK(), func->open(fn_ctx, FunctionContext::THREAD_LOCAL));
792+
ASSERT_EQ(Status::OK(),
793+
func->open(fn_ctx, FunctionContext::FunctionStateScope::FRAGMENT_LOCAL));
794+
ASSERT_EQ(Status::OK(),
795+
func->open(fn_ctx, FunctionContext::FunctionStateScope::THREAD_LOCAL));
794796
ASSERT_EQ(Status::OK(), func->execute(fn_ctx, block, {0, 1}, 2, 1));
795797

796798
auto result_col = block.get_by_position(2).column;
@@ -799,8 +801,8 @@ TEST(FunctionLikeTest, regexp_extract_all_boost_zero_width_match) {
799801
EXPECT_EQ(expected, return_type->to_string(*result_col, 0))
800802
<< func_name << " input: '" << str << "', pattern: '" << pattern << "'";
801803

802-
static_cast<void>(func->close(fn_ctx, FunctionContext::THREAD_LOCAL));
803-
static_cast<void>(func->close(fn_ctx, FunctionContext::FRAGMENT_LOCAL));
804+
static_cast<void>(func->close(fn_ctx, FunctionContext::FunctionStateScope::THREAD_LOCAL));
805+
static_cast<void>(func->close(fn_ctx, FunctionContext::FunctionStateScope::FRAGMENT_LOCAL));
804806
};
805807

806808
auto string_type = make_nullable(std::make_shared<DataTypeString>());

0 commit comments

Comments
 (0)