Skip to content

Commit

Permalink
[Bug][Vectorized] fix core dump on vcase_expr::close
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaopeng committed May 31, 2022
1 parent 54e9d49 commit 5e59261
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 23 deletions.
3 changes: 0 additions & 3 deletions be/src/vec/exec/volap_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
#include <memory>

#include "runtime/runtime_state.h"
#include "vec/columns/column_complex.h"
#include "vec/columns/column_nullable.h"
#include "vec/columns/column_string.h"
#include "vec/columns/column_vector.h"
#include "vec/common/assert_cast.h"
#include "vec/core/block.h"
#include "vec/exec/volap_scan_node.h"
Expand Down
16 changes: 12 additions & 4 deletions be/src/vec/exprs/vcase_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,23 @@ Status VCaseExpr::open(RuntimeState* state, VExprContext* context,
FunctionContext::FunctionStateScope scope) {
RETURN_IF_ERROR(VExpr::open(state, context, scope));
RETURN_IF_ERROR(VExpr::init_function_context(context, scope, _function));

CaseState* case_state = new CaseState {_data_type};
context->fn_context(_fn_context_index)->set_function_state(scope, case_state);

if (scope == doris_udf::FunctionContext::FRAGMENT_LOCAL) {
auto* case_state = new CaseState {_data_type};
context->fn_context(_fn_context_index)
->set_function_state(FunctionContext::FRAGMENT_LOCAL, case_state);
}
return Status::OK();
}

void VCaseExpr::close(RuntimeState* state, VExprContext* context,
FunctionContext::FunctionStateScope scope) {
if (scope == doris_udf::FunctionContext::FRAGMENT_LOCAL) {
auto* case_state = reinterpret_cast<CaseState*>(
context->fn_context(_fn_context_index)
->get_function_state(FunctionContext::FRAGMENT_LOCAL));
delete case_state;
}

VExpr::close_function_context(context, scope, _function);
VExpr::close(state, context, scope);
}
Expand Down
5 changes: 1 addition & 4 deletions be/src/vec/exprs/vexpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ class VExpr {
VExpr* parent, int* node_idx, VExpr** root_expr,
VExprContext** ctx);
const std::vector<VExpr*>& children() const { return _children; }
void set_children(RuntimeState* state, VExprContext* ctx, std::vector<VExpr*> children) {
close(state, ctx, ctx->get_function_state_scope());
_children = children;
}
void set_children(std::vector<VExpr*> children) { _children = children; }
virtual std::string debug_string() const;
static std::string debug_string(const std::vector<VExpr*>& exprs);
static std::string debug_string(const std::vector<VExprContext*>& ctxs);
Expand Down
11 changes: 1 addition & 10 deletions be/src/vec/functions/function_case.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,21 +327,12 @@ class FunctionCase : public IFunction {

Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
size_t result, size_t input_rows_count) override {
CaseState* case_state = reinterpret_cast<CaseState*>(
auto* case_state = reinterpret_cast<CaseState*>(
context->get_function_state(FunctionContext::FRAGMENT_LOCAL));

return execute_get_type(case_state->result_type, block, arguments, result,
input_rows_count);
}

Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) override {
if (scope == FunctionContext::THREAD_LOCAL) {
auto* state = reinterpret_cast<CaseState*>(
context->get_function_state(FunctionContext::THREAD_LOCAL));
delete state;
}
return Status::OK();
}
};

} // namespace doris::vectorized
8 changes: 6 additions & 2 deletions be/src/vec/utils/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,19 @@ class VectorizedUtils {
static constexpr auto is_leaf = [](VExpr* expr) { return !expr->is_and_expr(); };

if (is_leaf(expr)) {
return checker(leaf_index++) ? nullptr : expr;
if (checker(leaf_index++)) {
expr->close(state, context, context->get_function_state_scope());
return nullptr;
}
return expr;
} else {
VExpr* left_child =
dfs_peel_conjunct(state, context, expr->children()[0], leaf_index, checker);
VExpr* right_child =
dfs_peel_conjunct(state, context, expr->children()[1], leaf_index, checker);

if (left_child != nullptr && right_child != nullptr) {
expr->set_children(state, context, {left_child, right_child});
expr->set_children({left_child, right_child});
return expr;
}
// here do not close Expr* now
Expand Down

0 comments on commit 5e59261

Please sign in to comment.