This is an automated email from the ASF dual-hosted git repository.

zclll pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 8d0830793c3 [refine](function) function catch throw exception  (#52511)
8d0830793c3 is described below

commit 8d0830793c3934efc35bb9db87fc366120f9cc8c
Author: Mryange <[email protected]>
AuthorDate: Tue Jul 8 14:34:04 2025 +0800

    [refine](function) function catch throw exception  (#52511)
    
    ### What problem does this PR solve?
    
    
    ### Release note
    
    None
    
    ### Check List (For Author)
    
    - Test <!-- At least one of them must be included. -->
        - [ ] Regression test
        - [x] 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:
        - [x] No.
        - [ ] Yes. <!-- Explain the behavior change -->
    
    - Does this need documentation?
        - [x] No.
    - [ ] Yes. <!-- Add document PR link here. eg:
    https://github.com/apache/doris-website/pull/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 -->
---
 be/src/vec/functions/function.h                    | 13 +++--
 be/src/vec/functions/function_rpc.cpp              |  7 ---
 be/src/vec/functions/function_rpc.h                | 20 +++++--
 be/src/vec/functions/simple_function_factory.h     |  7 +++
 .../vec/function/function_throw_exception_test.cpp | 64 ++++++++++++++++++++++
 be/test/vec/function/function_time_test.cpp        | 24 ++++----
 6 files changed, 107 insertions(+), 28 deletions(-)

diff --git a/be/src/vec/functions/function.h b/be/src/vec/functions/function.h
index 43b1dd979ab..d4a03374a74 100644
--- a/be/src/vec/functions/function.h
+++ b/be/src/vec/functions/function.h
@@ -191,11 +191,14 @@ public:
         return Status::OK();
     }
 
-    /// TODO: make const
-    virtual Status execute(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
-                           uint32_t result, size_t input_rows_count, bool 
dry_run = false) const {
-        return prepare(context, block, arguments, result)
-                ->execute(context, block, arguments, result, input_rows_count, 
dry_run);
+    Status execute(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                   uint32_t result, size_t input_rows_count, bool dry_run = 
false) const {
+        try {
+            return prepare(context, block, arguments, result)
+                    ->execute(context, block, arguments, result, 
input_rows_count, dry_run);
+        } catch (const Exception& e) {
+            return e.to_status();
+        }
     }
 
     virtual Status evaluate_inverted_index(
diff --git a/be/src/vec/functions/function_rpc.cpp 
b/be/src/vec/functions/function_rpc.cpp
index f8e77f7607c..75e0bed743e 100644
--- a/be/src/vec/functions/function_rpc.cpp
+++ b/be/src/vec/functions/function_rpc.cpp
@@ -107,11 +107,4 @@ Status FunctionRPC::open(FunctionContext* context, 
FunctionContext::FunctionStat
     }
     return Status::OK();
 }
-
-Status FunctionRPC::execute(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
-                            uint32_t result, size_t input_rows_count, bool 
dry_run) const {
-    auto* fn = reinterpret_cast<RPCFnImpl*>(
-            context->get_function_state(FunctionContext::FRAGMENT_LOCAL));
-    return fn->vec_call(context, block, arguments, result, input_rows_count);
-}
 } // namespace doris::vectorized
diff --git a/be/src/vec/functions/function_rpc.h 
b/be/src/vec/functions/function_rpc.h
index 97c769e8bfc..5d6a3432392 100644
--- a/be/src/vec/functions/function_rpc.h
+++ b/be/src/vec/functions/function_rpc.h
@@ -64,6 +64,21 @@ private:
     TFunction _fn;
 };
 
+class RPCPreparedFunction : public IPreparedFunction {
+public:
+    ~RPCPreparedFunction() override = default;
+
+    /// Get the main function name.
+    String get_name() const override { return "RPCPreparedFunction: "; }
+
+    Status execute(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                   uint32_t result, size_t input_rows_count, bool dry_run) 
const override {
+        auto* fn = reinterpret_cast<RPCFnImpl*>(
+                context->get_function_state(FunctionContext::FRAGMENT_LOCAL));
+        return fn->vec_call(context, block, arguments, result, 
input_rows_count);
+    }
+};
+
 class FunctionRPC : public IFunctionBase {
 public:
     FunctionRPC(const TFunction& fn, const DataTypes& argument_types,
@@ -89,14 +104,11 @@ public:
 
     PreparedFunctionPtr prepare(FunctionContext* context, const Block& 
sample_block,
                                 const ColumnNumbers& arguments, uint32_t 
result) const override {
-        return nullptr;
+        return std::make_shared<RPCPreparedFunction>();
     }
 
     Status open(FunctionContext* context, FunctionContext::FunctionStateScope 
scope) override;
 
-    Status execute(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
-                   uint32_t result, size_t input_rows_count, bool dry_run = 
false) const override;
-
     bool is_use_default_implementation_for_constants() const override { return 
true; }
 
 private:
diff --git a/be/src/vec/functions/simple_function_factory.h 
b/be/src/vec/functions/simple_function_factory.h
index b98e69820e4..224e1c1ee60 100644
--- a/be/src/vec/functions/simple_function_factory.h
+++ b/be/src/vec/functions/simple_function_factory.h
@@ -116,6 +116,10 @@ void register_function_bit_test(SimpleFunctionFactory& 
factory);
 void register_function_dict_get(SimpleFunctionFactory& factory);
 void register_function_dict_get_many(SimpleFunctionFactory& factory);
 
+#ifdef BE_TEST
+void register_function_throw_exception(SimpleFunctionFactory& factory);
+#endif
+
 class SimpleFunctionFactory {
     using Creator = std::function<FunctionBuilderPtr()>;
     using FunctionCreators = phmap::flat_hash_map<std::string, Creator>;
@@ -320,6 +324,9 @@ public:
             register_function_compress(instance);
             register_function_dict_get(instance);
             register_function_dict_get_many(instance);
+#ifdef BE_TEST
+            register_function_throw_exception(instance);
+#endif
         });
         return instance;
     }
diff --git a/be/test/vec/function/function_throw_exception_test.cpp 
b/be/test/vec/function/function_throw_exception_test.cpp
new file mode 100644
index 00000000000..3239e53c4a0
--- /dev/null
+++ b/be/test/vec/function/function_throw_exception_test.cpp
@@ -0,0 +1,64 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest.h>
+
+#include "runtime/primitive_type.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/functions/function.h"
+#include "vec/functions/simple_function_factory.h"
+
+namespace doris::vectorized {
+
+class MockFunctionThrowException : public IFunction {
+public:
+    static constexpr auto name = "mock_function_throw_exception";
+    static FunctionPtr create() { return 
std::make_shared<MockFunctionThrowException>(); }
+    String get_name() const override { return name; }
+    bool skip_return_type_check() const override { return true; }
+    bool use_default_implementation_for_constants() const override { return 
false; }
+
+    size_t get_number_of_arguments() const override { return 0; }
+
+    bool is_variadic() const override { return true; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return std::make_shared<DataTypeFloat64>();
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        uint32_t result, size_t input_rows_count) const 
override {
+        throw doris::Exception(ErrorCode::INTERNAL_ERROR, "BEUT TEST: 
MockFunctionThrowException");
+    }
+};
+
+void register_function_throw_exception(SimpleFunctionFactory& factory) {
+    factory.register_function<MockFunctionThrowException>();
+}
+
+TEST(FunctionThrowExceptionTest, test_throw_exception) {
+    auto function = SimpleFunctionFactory::instance().get_function(
+            "mock_function_throw_exception", {}, 
std::make_shared<DataTypeFloat64>(), {false},
+            BeExecVersionManager::get_newest_version());
+
+    Block block;
+    auto st = function->execute(nullptr, block, {}, 0, 1);
+
+    EXPECT_EQ(st.code(), ErrorCode::INTERNAL_ERROR);
+    EXPECT_EQ(st.msg(), "BEUT TEST: MockFunctionThrowException");
+}
+} // namespace doris::vectorized
\ No newline at end of file
diff --git a/be/test/vec/function/function_time_test.cpp 
b/be/test/vec/function/function_time_test.cpp
index d53229edb93..fbefde56924 100644
--- a/be/test/vec/function/function_time_test.cpp
+++ b/be/test/vec/function/function_time_test.cpp
@@ -366,8 +366,8 @@ TEST(VTimestampFunctionsTest, years_add_test) {
     {
         DataSet data_set = {{{std::string("2020-05-23 00:00:00"), 8000}, 
Null()}};
 
-        EXPECT_ANY_THROW(static_cast<void>(
-                check_function<DataTypeDateTime, true>(func_name, input_types, 
data_set)));
+        static_cast<void>(
+                check_function<DataTypeDateTime, true>(func_name, input_types, 
data_set, true));
     }
 }
 
@@ -389,8 +389,8 @@ TEST(VTimestampFunctionsTest, years_sub_test) {
     {
         DataSet data_set = {{{std::string("2020-05-23 00:00:00"), 3000}, 
Null()}};
 
-        EXPECT_ANY_THROW(static_cast<void>(
-                check_function<DataTypeDateTime, true>(func_name, input_types, 
data_set)));
+        static_cast<void>(
+                check_function<DataTypeDateTime, true>(func_name, input_types, 
data_set, true));
     }
 }
 
@@ -1088,8 +1088,8 @@ TEST(VTimestampFunctionsTest, years_add_v2_test) {
 
         DataSet data_set = {{{std::string("2020-05-23"), 8000}, Null()}};
 
-        EXPECT_ANY_THROW(static_cast<void>(
-                check_function<DataTypeDateV2, true>(func_name, input_types, 
data_set)));
+        static_cast<void>(
+                check_function<DataTypeDateV2, true>(func_name, input_types, 
data_set, true));
     }
 
     {
@@ -1110,8 +1110,8 @@ TEST(VTimestampFunctionsTest, years_add_v2_test) {
 
         DataSet data_set = {{{std::string("2020-05-23 00:00:11.123"), 8000}, 
Null()}};
 
-        EXPECT_ANY_THROW(static_cast<void>(
-                check_function<DataTypeDateTimeV2, true>(func_name, 
input_types, data_set)));
+        static_cast<void>(
+                check_function<DataTypeDateTimeV2, true>(func_name, 
input_types, data_set, true));
     }
 }
 
@@ -1133,8 +1133,8 @@ TEST(VTimestampFunctionsTest, years_sub_v2_test) {
 
         DataSet data_set = {{{std::string("2020-05-23"), 3000}, Null()}};
 
-        EXPECT_ANY_THROW(static_cast<void>(
-                check_function<DataTypeDateV2, true>(func_name, input_types, 
data_set)));
+        static_cast<void>(
+                check_function<DataTypeDateV2, true>(func_name, input_types, 
data_set, true));
     }
 
     {
@@ -1155,8 +1155,8 @@ TEST(VTimestampFunctionsTest, years_sub_v2_test) {
 
         DataSet data_set = {{{std::string("2020-05-23 00:00:11.123"), 3000}, 
Null()}};
 
-        EXPECT_ANY_THROW(static_cast<void>(
-                check_function<DataTypeDateTimeV2, true>(func_name, 
input_types, data_set)));
+        static_cast<void>(
+                check_function<DataTypeDateTimeV2, true>(func_name, 
input_types, data_set, true));
     }
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to