From a1b204395d5de54323db2639d4e374c7fd54e46d Mon Sep 17 00:00:00 2001 From: stdpain <34912776+stdpain@users.noreply.github.com> Date: Mon, 11 Nov 2024 10:50:39 +0800 Subject: [PATCH] [BugFix] Fix Expr::open crash when evaluate const throw exception (#52752) Signed-off-by: stdpain (cherry picked from commit 130facd991cb002cc2c9db0fc3f8c7b9d6a39a88) --- be/src/exprs/expr_context.cpp | 6 +++++- test/sql/test_exception/R/test_number_overflow | 12 ++++++++++++ test/sql/test_exception/T/test_number_overflow | 7 +++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/sql/test_exception/R/test_number_overflow create mode 100644 test/sql/test_exception/T/test_number_overflow diff --git a/be/src/exprs/expr_context.cpp b/be/src/exprs/expr_context.cpp index 6aa07b543fd6b..ca45ec943ea4d 100644 --- a/be/src/exprs/expr_context.cpp +++ b/be/src/exprs/expr_context.cpp @@ -83,7 +83,11 @@ Status ExprContext::open(RuntimeState* state) { // original's fragment state and only need to have thread-local state initialized. FunctionContext::FunctionStateScope scope = _is_clone ? FunctionContext::THREAD_LOCAL : FunctionContext::FRAGMENT_LOCAL; - return _root->open(state, this, scope); + try { + return _root->open(state, this, scope); + } catch (std::runtime_error& e) { + return Status::RuntimeError(fmt::format("Expr evaluate meet error: {}", e.what())); + } } Status ExprContext::open(std::vector evals, RuntimeState* state) { diff --git a/test/sql/test_exception/R/test_number_overflow b/test/sql/test_exception/R/test_number_overflow new file mode 100644 index 0000000000000..693ff351c2c14 --- /dev/null +++ b/test/sql/test_exception/R/test_number_overflow @@ -0,0 +1,12 @@ +-- name: test_number_overflow +set sql_mode="ERROR_IF_OVERFLOW"; +-- result: +-- !result +select cast(abs(1234567890123456789) as decimal(4,3)); +-- result: +[REGEX].*Expr evaluate meet error: The type cast from other types to decimal overflows.* +-- !result +select 1 in (cast(abs(1234567890123456789) as decimal(4,3)), cast(abs(1234567890123456789) as decimal(4,3))); +-- result: +[REGEX].*Expr evaluate meet error: The type cast from other types to decimal overflows.* +-- !result \ No newline at end of file diff --git a/test/sql/test_exception/T/test_number_overflow b/test/sql/test_exception/T/test_number_overflow new file mode 100644 index 0000000000000..0b6615c9b0559 --- /dev/null +++ b/test/sql/test_exception/T/test_number_overflow @@ -0,0 +1,7 @@ +-- name: test_number_overflow +set sql_mode="ERROR_IF_OVERFLOW"; + +-- exception in evaluate +select cast(abs(1234567890123456789) as decimal(4,3)); +-- exception in open +select 1 in (cast(abs(1234567890123456789) as decimal(4,3)), cast(abs(1234567890123456789) as decimal(4,3))); \ No newline at end of file