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

yiguolei 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 1ab8911dcdd [chore](function) function catch std:: exception (#53041)
1ab8911dcdd is described below

commit 1ab8911dcdda38f567108fccade670152ec185ae
Author: Mryange <[email protected]>
AuthorDate: Fri Jul 11 07:11:57 2025 +0800

    [chore](function) function catch std:: exception (#53041)
    
    ### What problem does this PR solve?
    
    before
    ```
    mysql> SELECT id, BITMAP_FROM_BASE64(base64_str) AS result FROM 
test_bitmap_from_base64;
    ERROR 1105 (HY000): RpcException, msg: send fragments failed. 
io.grpc.StatusRuntimeException: UNAVAILABLE: io exception, host: 127.0.0.1
    
    terminate called after throwing an instance of 'std::runtime_error'
      what():  failed alloc while reading
    ```
    
    now
    ```
    mysql> SELECT id, BITMAP_FROM_BASE64(base64_str) AS result FROM 
test_bitmap_from_base64;
    ERROR 1105 (HY000): errCode = 2, detailMessage = 
(127.0.0.1)[INTERNAL_ERROR]Function bitmap_from_base64 execute failed: failed 
alloc while reading
    ```
---
 be/src/vec/functions/function.h                    |  9 +++--
 .../vec/function/function_throw_exception_test.cpp | 39 ++++++++++++++++++++++
 2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/be/src/vec/functions/function.h b/be/src/vec/functions/function.h
index d8385b484e9..0d8e72ec08a 100644
--- a/be/src/vec/functions/function.h
+++ b/be/src/vec/functions/function.h
@@ -190,8 +190,13 @@ public:
         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();
+        } catch (const std::exception& e) {
+            if (const auto* doris_e = dynamic_cast<const 
doris::Exception*>(&e)) {
+                return doris_e->to_status();
+            } else {
+                return Status::InternalError("Function {} execute failed: {}", 
get_name(),
+                                             e.what());
+            }
         }
     }
 
diff --git a/be/test/vec/function/function_throw_exception_test.cpp 
b/be/test/vec/function/function_throw_exception_test.cpp
index 3239e53c4a0..898121a2c81 100644
--- a/be/test/vec/function/function_throw_exception_test.cpp
+++ b/be/test/vec/function/function_throw_exception_test.cpp
@@ -17,6 +17,8 @@
 
 #include <gtest/gtest.h>
 
+#include <stdexcept>
+
 #include "runtime/primitive_type.h"
 #include "vec/data_types/data_type_number.h"
 #include "vec/functions/function.h"
@@ -46,8 +48,31 @@ public:
     }
 };
 
+class MockFunctionThrowStdException : public IFunction {
+public:
+    static constexpr auto name = "mock_function_throw_stdexception";
+    static FunctionPtr create() { return 
std::make_shared<MockFunctionThrowStdException>(); }
+    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 std::runtime_error("BEUT TEST: MockFunctionThrowStdException");
+    }
+};
+
 void register_function_throw_exception(SimpleFunctionFactory& factory) {
     factory.register_function<MockFunctionThrowException>();
+    factory.register_function<MockFunctionThrowStdException>();
 }
 
 TEST(FunctionThrowExceptionTest, test_throw_exception) {
@@ -61,4 +86,18 @@ TEST(FunctionThrowExceptionTest, test_throw_exception) {
     EXPECT_EQ(st.code(), ErrorCode::INTERNAL_ERROR);
     EXPECT_EQ(st.msg(), "BEUT TEST: MockFunctionThrowException");
 }
+
+TEST(FunctionThrowExceptionTest, test_throw_std_exception) {
+    auto function = SimpleFunctionFactory::instance().get_function(
+            "mock_function_throw_stdexception", {}, 
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(),
+              "Function mock_function_throw_stdexception execute failed: BEUT 
TEST: "
+              "MockFunctionThrowStdException");
+}
 } // namespace doris::vectorized
\ No newline at end of file


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

Reply via email to