Skip to content

Commit 8bda0cb

Browse files
authored
[BugFix] Fix array_map common-expression crash (StarRocks#52909)
Signed-off-by: stdpain <drfeng08@gmail.com>
1 parent 0dcbbd8 commit 8bda0cb

4 files changed

Lines changed: 22 additions & 1 deletion

File tree

be/src/exprs/array_map_expr.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ Status ArrayMapExpr::prepare(RuntimeState* state, ExprContext* context) {
6060

6161
return Status::OK();
6262
}
63+
Status ArrayMapExpr::open(RuntimeState* state, ExprContext* context, FunctionContext::FunctionStateScope scope) {
64+
RETURN_IF_ERROR(Expr::open(state, context, scope));
65+
for (auto [_, expr] : _outer_common_exprs) {
66+
RETURN_IF_ERROR(expr->open(state, context, scope));
67+
}
68+
return Status::OK();
69+
}
70+
71+
void ArrayMapExpr::close(RuntimeState* state, ExprContext* context, FunctionContext::FunctionStateScope scope) {
72+
for (auto [_, expr] : _outer_common_exprs) {
73+
expr->close(state, context, scope);
74+
}
75+
Expr::close(state, context, scope);
76+
}
6377

6478
template <bool all_const_input, bool independent_lambda_expr>
6579
StatusOr<ColumnPtr> ArrayMapExpr::evaluate_lambda_expr(ExprContext* context, Chunk* chunk,

be/src/exprs/array_map_expr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class ArrayMapExpr final : public Expr {
3737
explicit ArrayMapExpr(TypeDescriptor type);
3838

3939
Status prepare(RuntimeState* state, ExprContext* context) override;
40+
Status open(RuntimeState* state, ExprContext* context, FunctionContext::FunctionStateScope scope) override;
41+
void close(RuntimeState* state, ExprContext* context, FunctionContext::FunctionStateScope scope) override;
4042
Expr* clone(ObjectPool* pool) const override { return pool->add(new ArrayMapExpr(*this)); }
4143

4244
StatusOr<ColumnPtr> evaluate_checked(ExprContext* context, Chunk* ptr) override;

test/sql/test_array_fn/R/test_array_map_2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ select array_length(array_map((x,y)->x > y, @arr,@arr)) from table(generate_seri
5050
1000000
5151
1000000
5252
-- !result
53+
select count(*) from array_map_test where array_map((a1) -> concat(split(id, 'd'), split(id, 'd')), arr_str) is not null;
54+
-- result:
55+
1
56+
-- !result
5357
-- name: test_array_map_3
5458
CREATE TABLE `t` (
5559
`k` bigint NOT NULL COMMENT "",

test/sql/test_array_fn/T/test_array_map_2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ select count(array_map(x->array_length(array_concat(arr_str,[])), arr_largeint))
2222

2323
set @arr=array_repeat("12345",1000000);
2424
select array_length(array_map((x,y)->x > y, @arr,@arr)) from table(generate_series(1,10,1));
25+
select count(*) from array_map_test where array_map((a1) -> concat(split(id, 'd'), split(id, 'd')), arr_str) is not null;
2526

2627
-- name: test_array_map_3
2728
CREATE TABLE `t` (
@@ -72,4 +73,4 @@ select array_map(arg0 -> array_map(arg1 -> array_map(arg2 -> array_map(arg3 -> a
7273
select array_map(arg0 -> array_map(arg1 -> array_map(arg2 -> array_map(arg3 -> array_map(arg4->array_length(arg2) + arg4, arg3), arg2), arg1), arg0), [[[[[1,2]]]]] );
7374

7475
set @arr=array_generate(1,10000);
75-
select /*+ SET_VAR(query_mem_limit=104857600)*/array_sum(array_map(x->array_contains(@arr,x), array_generate(1,100000)));
76+
select /*+ SET_VAR(query_mem_limit=104857600)*/array_sum(array_map(x->array_contains(@arr,x), array_generate(1,100000)));

0 commit comments

Comments
 (0)