Skip to content

Commit

Permalink
[BugFix] Fix Expr::open crash when evaluate const throw exception (#5…
Browse files Browse the repository at this point in the history
…2752)

Signed-off-by: stdpain <drfeng08@gmail.com>
(cherry picked from commit 130facd)
  • Loading branch information
stdpain authored and mergify[bot] committed Nov 11, 2024
1 parent 3c04b18 commit 1d3a736
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion be/src/exprs/expr_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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<ExprContext*> evals, RuntimeState* state) {
Expand Down
12 changes: 12 additions & 0 deletions test/sql/test_exception/R/test_number_overflow
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/sql/test_exception/T/test_number_overflow
Original file line number Diff line number Diff line change
@@ -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)));

0 comments on commit 1d3a736

Please sign in to comment.