Skip to content

Commit

Permalink
[BugFix] Fix the bug of VectorizedInConstPredicate::clone (#53938)
Browse files Browse the repository at this point in the history
Signed-off-by: trueeyu <[email protected]>
  • Loading branch information
trueeyu authored Dec 13, 2024
1 parent 3801c62 commit f6d536e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
8 changes: 7 additions & 1 deletion be/src/exprs/in_const_predicate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@ class VectorizedInConstPredicate final : public Predicate {

VectorizedInConstPredicate(const TExprNode& node) : Predicate(node), _is_not_in(node.in_predicate.is_not_in) {}

// _string_values is ColumnPtr, not deep copied, so once opened, should not be modified.
VectorizedInConstPredicate(const VectorizedInConstPredicate& other)
: Predicate(other),
_is_not_in(other._is_not_in),
_is_prepare(other._is_prepare),
_null_in_set(other._null_in_set),
_is_join_runtime_filter(other._is_join_runtime_filter),
_eq_null(other._eq_null),
_array_size(other._array_size) {}
_array_size(other._array_size),
_array_buffer(other._array_buffer),
_hash_set(other._hash_set),
_string_values(other._string_values) {}

~VectorizedInConstPredicate() override = default;

Expand Down Expand Up @@ -547,6 +551,8 @@ class VectorizedInConstPredicateBuilder {
: _state(state), _pool(pool), _expr(expr) {}

Status create();
// For string type, this interface will only copy the slice array, not add ColumnPtr,
// so be careful to manage the life cycle of source ColumnPtr.
void add_values(const ColumnPtr& column, size_t column_offset);
void use_array_set(size_t array_size) { _array_size = array_size; }
void use_as_join_runtime_filter() { _is_join_runtime_filter = true; }
Expand Down
1 change: 1 addition & 0 deletions be/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ set(EXEC_FILES
./exprs/subfield_expr_test.cpp
./exprs/vectorized_literal_test.cpp
./exprs/min_max_predicate_test.cpp
./exprs/in_const_predicate_test.cpp
./formats/csv/array_converter_test.cpp
./formats/csv/boolean_converter_test.cpp
./formats/csv/csv_file_writer_test.cpp
Expand Down
56 changes: 56 additions & 0 deletions be/test/exprs/in_const_predicate_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2021-present StarRocks, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "exprs/in_const_predicate.hpp"

#include <gtest/gtest.h>

#include "exprs/column_ref.h"
#include "runtime/runtime_state.h"
#include "testutil/column_test_helper.h"
#include "types/logical_type.h"

namespace starrocks {

class InConstPredicateTest : public ::testing::Test {
public:
void SetUp() override {}

protected:
ObjectPool _pool;
RuntimeState _runtime_state;
};

TEST_F(InConstPredicateTest, clone) {
ColumnRef* col_ref = _pool.add(new ColumnRef(TYPE_INT_DESC, 1));
VectorizedInConstPredicateBuilder builder(&_runtime_state, &_pool, col_ref);
builder.set_null_in_set(true);
builder.use_as_join_runtime_filter();
Status st = builder.create();

std::vector<int32_t> values{1, 3, 5, 7, 9};
ColumnPtr col = ColumnTestHelper::build_column(values);
builder.add_values(col, 0);

ExprContext* expr_ctx = builder.get_in_const_predicate();
Expr* new_expr = expr_ctx->root()->clone(&_pool);
auto* new_in_const_pred = (VectorizedInConstPredicate<TYPE_INT>*)new_expr;

ASSERT_TRUE(new_in_const_pred->null_in_set());
ASSERT_TRUE(new_in_const_pred->is_join_runtime_filter());
const auto& new_values = new_in_const_pred->hash_set();
ASSERT_EQ(new_values.size(), 5);
}

} // namespace starrocks

0 comments on commit f6d536e

Please sign in to comment.