github-actions[bot] commented on code in PR #26138: URL: https://github.com/apache/doris/pull/26138#discussion_r1379889656
########## be/src/vec/exec/vmysql_scan_node.cpp: ########## @@ -227,7 +227,8 @@ void VMysqlScanNode::debug_string(int indentation_level, std::stringstream* out) } } -Status VMysqlScanNode::set_scan_ranges(const std::vector<TScanRangeParams>& scan_ranges) { +Status VMysqlScanNode::set_scan_ranges(RuntimeState* state, Review Comment: warning: method 'set_scan_ranges' can be made static [readability-convert-member-functions-to-static] ```suggestion static Status VMysqlScanNode::set_scan_ranges(RuntimeState* state, ``` ########## be/src/vec/data_types/serde/data_type_struct_serde.cpp: ########## @@ -370,7 +370,8 @@ Status DataTypeStructSerDe::write_column_to_mysql(const IColumn& column, return _write_column_to_mysql(column, row_buffer, row_idx, col_const); } -Status DataTypeStructSerDe::write_column_to_orc(const IColumn& column, const NullMap* null_map, +Status DataTypeStructSerDe::write_column_to_orc(const std::string& timezone, const IColumn& column, Review Comment: warning: method 'write_column_to_orc' can be made static [readability-convert-member-functions-to-static] ```suggestion static Status DataTypeStructSerDe::write_column_to_orc(const std::string& timezone, const IColumn& column, ``` be/src/vec/data_types/serde/data_type_struct_serde.cpp:376: ```diff - std::vector<StringRef>& buffer_list) const { + std::vector<StringRef>& buffer_list) { ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } + + void find_batch(BitmapFilterFuncBase* func) { Review Comment: warning: method 'find_batch' can be made static [readability-convert-member-functions-to-static] ```suggestion static void find_batch(BitmapFilterFuncBase* func) { ``` ########## be/src/vec/exec/vschema_scan_node.cpp: ########## @@ -302,7 +302,8 @@ void VSchemaScanNode::debug_string(int indentation_level, std::stringstream* out } } -Status VSchemaScanNode::set_scan_ranges(const std::vector<TScanRangeParams>& scan_ranges) { +Status VSchemaScanNode::set_scan_ranges(RuntimeState* state, Review Comment: warning: method 'set_scan_ranges' can be made static [readability-convert-member-functions-to-static] ```suggestion static Status VSchemaScanNode::set_scan_ranges(RuntimeState* state, ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } + + void find_batch(BitmapFilterFuncBase* func) { + const std::vector<int32_t> to_find = create_vector(); + std::vector<uint8_t> results(to_find.size()); + func->find_batch(reinterpret_cast<const char*>(to_find.data()), nullptr, to_find.size(), + results.data()); + EXPECT_EQ(results[0], 1); + EXPECT_EQ(results[1], 1); + EXPECT_EQ(results[2], 0); + EXPECT_EQ(results[3], 1); + EXPECT_EQ(results[4], 1); + EXPECT_EQ(results[5], 0); + EXPECT_EQ(results[6], 0); + EXPECT_EQ(results[7], 1); + } +}; + +TEST_F(BitmapFilterPredicateTest, insert) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + EXPECT_TRUE(func->empty()); + + BitmapValue bitmap_value = create_bitmap_value(); + func->insert(&bitmap_value); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, insert_many) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + std::vector<const BitmapValue*> bitmaps; + + func->insert_many(bitmaps); + EXPECT_TRUE(func->empty()); + + auto bitmap = create_bitmap_value(); + bitmaps.emplace_back(&bitmap); + + func->insert_many(bitmaps); + EXPECT_FALSE(func->empty()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, assign) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, contains_any) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + auto* filter = assert_cast<BitmapFilterFunc<PrimitiveType::TYPE_INT>*>(func.get()); + + EXPECT_TRUE(filter->contains_any(1, 5)); + EXPECT_FALSE(filter->contains_any(5, 7)); Review Comment: warning: 5 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp EXPECT_FALSE(filter->contains_any(5, 7)); ^ ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } + + void find_batch(BitmapFilterFuncBase* func) { + const std::vector<int32_t> to_find = create_vector(); + std::vector<uint8_t> results(to_find.size()); + func->find_batch(reinterpret_cast<const char*>(to_find.data()), nullptr, to_find.size(), + results.data()); + EXPECT_EQ(results[0], 1); + EXPECT_EQ(results[1], 1); + EXPECT_EQ(results[2], 0); + EXPECT_EQ(results[3], 1); + EXPECT_EQ(results[4], 1); + EXPECT_EQ(results[5], 0); + EXPECT_EQ(results[6], 0); + EXPECT_EQ(results[7], 1); + } +}; + +TEST_F(BitmapFilterPredicateTest, insert) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + EXPECT_TRUE(func->empty()); + + BitmapValue bitmap_value = create_bitmap_value(); + func->insert(&bitmap_value); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, insert_many) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + std::vector<const BitmapValue*> bitmaps; + + func->insert_many(bitmaps); + EXPECT_TRUE(func->empty()); + + auto bitmap = create_bitmap_value(); + bitmaps.emplace_back(&bitmap); + + func->insert_many(bitmaps); + EXPECT_FALSE(func->empty()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, assign) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, contains_any) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + auto* filter = assert_cast<BitmapFilterFunc<PrimitiveType::TYPE_INT>*>(func.get()); + + EXPECT_TRUE(filter->contains_any(1, 5)); + EXPECT_FALSE(filter->contains_any(5, 7)); Review Comment: warning: 7 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp EXPECT_FALSE(filter->contains_any(5, 7)); ^ ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } Review Comment: warning: 2048 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } ^ ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" Review Comment: warning: 'exprs/bitmapfilter_predicate.h' file not found [clang-diagnostic-error] ```cpp #include "exprs/bitmapfilter_predicate.h" ^ ``` ########## be/src/vec/common/hash_table/hash_map.h: ########## @@ -193,10 +197,229 @@ class HashMapTable : public HashTable<Key, Cell, Hash, Grower, Allocator> { bool has_null_key_data() const { return false; } }; +template <typename Key, typename Cell, typename Hash = DefaultHash<Key>, + typename Grower = HashTableGrower<>, typename Allocator = HashTableAllocator> +class JoinHashMapTable : public HashMapTable<Key, Cell, Hash, Grower, Allocator> { +public: + using Self = JoinHashMapTable; + using Base = HashMapTable<Key, Cell, Hash, Grower, Allocator>; + + using key_type = Key; + using value_type = typename Cell::value_type; + using mapped_type = typename Cell::Mapped; + + using LookupResult = typename Base::LookupResult; + + using HashMapTable<Key, Cell, Hash, Grower, Allocator>::HashMapTable; + + static uint32_t calc_bucket_size(size_t num_elem) { + size_t expect_bucket_size = static_cast<size_t>(num_elem) + (num_elem - 1) / 7; + return phmap::priv::NormalizeCapacity(expect_bucket_size) + 1; + } + + template <int JoinOpType> + void prepare_build(size_t num_elem, int batch_size) { + max_batch_size = batch_size; + bucket_size = calc_bucket_size(num_elem + 1); + first.resize(bucket_size, 0); + next.resize(num_elem); + + if constexpr (JoinOpType == doris::TJoinOp::FULL_OUTER_JOIN || + JoinOpType == doris::TJoinOp::RIGHT_OUTER_JOIN || + JoinOpType == doris::TJoinOp::RIGHT_ANTI_JOIN || + JoinOpType == doris::TJoinOp::RIGHT_SEMI_JOIN) { + visited.resize(num_elem, 0); + } + } + + uint32_t get_bucket_size() const { return bucket_size; } + + size_t size() const { return next.size(); } + + std::vector<uint8_t>& get_visited() { return visited; } + + void build(const Key* __restrict keys, const uint32_t* __restrict bucket_nums, + size_t num_elem) { + build_keys = keys; + for (size_t i = 1; i < num_elem; i++) { + uint32_t bucket_num = bucket_nums[i]; + next[i] = first[bucket_num]; + first[bucket_num] = i; + } + } + + template <int JoinOpType, bool with_other_conjuncts> + auto find_batch(const Key* __restrict keys, const uint32_t* __restrict bucket_nums, + int probe_idx, uint32_t build_idx, int probe_rows, + uint32_t* __restrict probe_idxs, uint32_t* __restrict build_idxs) { + if constexpr (JoinOpType == doris::TJoinOp::INNER_JOIN || + JoinOpType == doris::TJoinOp::FULL_OUTER_JOIN || + JoinOpType == doris::TJoinOp::LEFT_OUTER_JOIN || + JoinOpType == doris::TJoinOp::RIGHT_OUTER_JOIN) { + return _find_batch_inner_outer_join<JoinOpType, with_other_conjuncts>( + keys, bucket_nums, probe_idx, build_idx, probe_rows, probe_idxs, build_idxs); + } + if constexpr (JoinOpType == doris::TJoinOp::LEFT_ANTI_JOIN || + JoinOpType == doris::TJoinOp::LEFT_SEMI_JOIN) { + return _find_batch_left_semi_anti<JoinOpType>(keys, bucket_nums, probe_idx, probe_rows, + probe_idxs); + } + if constexpr (JoinOpType == doris::TJoinOp::RIGHT_ANTI_JOIN || + JoinOpType == doris::TJoinOp::RIGHT_SEMI_JOIN) { + return _find_batch_right_semi_anti<with_other_conjuncts>( + keys, bucket_nums, probe_idx, probe_rows, probe_idxs, build_idxs); + } + return std::tuple {0, 0u, 0}; + } + + template <int JoinOpType> + bool iterate_map(std::vector<uint32_t>& build_idxs) const { + const auto batch_size = max_batch_size; + const auto elem_num = visited.size(); + int count = 0; + build_idxs.resize(batch_size); + + while (count < batch_size && iter_idx < elem_num) { + const auto matched = visited[iter_idx]; + build_idxs[count] = iter_idx; + if constexpr (JoinOpType == doris::TJoinOp::RIGHT_ANTI_JOIN) { + count += !matched; + } else { + count += matched; + } + iter_idx++; + } + + build_idxs.resize(count); + return iter_idx >= elem_num; + } + +private: + template <bool with_other_conjuncts> + auto _find_batch_right_semi_anti(const Key* __restrict keys, + const uint32_t* __restrict bucket_nums, int probe_idx, + int probe_rows, uint32_t* __restrict probe_idxs, + uint32_t* __restrict build_idxs) { + auto matched_cnt = 0; + while (probe_idx < probe_rows) { + auto build_idx = first[bucket_nums[probe_idx]]; + + while (build_idx) { + if (keys[probe_idx] == build_keys[build_idx]) { + if constexpr (with_other_conjuncts) { + build_idxs[matched_cnt] = build_idx; + probe_idxs[matched_cnt] = probe_idx; + matched_cnt++; + } else { + visited[build_idx] = 1; + } + } + build_idx = next[build_idx]; + } + probe_idx++; + } + return std::tuple {probe_idx, 0u, matched_cnt}; Review Comment: warning: integer literal has suffix 'u', which is not uppercase [readability-uppercase-literal-suffix] ```suggestion return std::tuple {probe_idx, 0U, matched_cnt}; ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } Review Comment: warning: 2047 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } ^ ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); Review Comment: warning: 8 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp bitmap_value.add(8); ^ ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); Review Comment: warning: 2048 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp bitmap_value.add(2048); ^ ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); Review Comment: warning: 1024 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp bitmap_value.add(1024); ^ ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } + + void find_batch(BitmapFilterFuncBase* func) { + const std::vector<int32_t> to_find = create_vector(); + std::vector<uint8_t> results(to_find.size()); + func->find_batch(reinterpret_cast<const char*>(to_find.data()), nullptr, to_find.size(), + results.data()); + EXPECT_EQ(results[0], 1); + EXPECT_EQ(results[1], 1); + EXPECT_EQ(results[2], 0); + EXPECT_EQ(results[3], 1); + EXPECT_EQ(results[4], 1); + EXPECT_EQ(results[5], 0); + EXPECT_EQ(results[6], 0); + EXPECT_EQ(results[7], 1); + } +}; + +TEST_F(BitmapFilterPredicateTest, insert) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + EXPECT_TRUE(func->empty()); + + BitmapValue bitmap_value = create_bitmap_value(); + func->insert(&bitmap_value); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, insert_many) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + std::vector<const BitmapValue*> bitmaps; + + func->insert_many(bitmaps); + EXPECT_TRUE(func->empty()); + + auto bitmap = create_bitmap_value(); + bitmaps.emplace_back(&bitmap); + + func->insert_many(bitmaps); + EXPECT_FALSE(func->empty()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, assign) { Review Comment: warning: all parameters should be named in a function [readability-named-parameter] ```suggestion TEST_F(BitmapFilterPredicateTest /*unused*/, assign /*unused*/) { ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } Review Comment: warning: 1024 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } ^ ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } Review Comment: warning: 1025 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } ^ ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } + + void find_batch(BitmapFilterFuncBase* func) { + const std::vector<int32_t> to_find = create_vector(); + std::vector<uint8_t> results(to_find.size()); + func->find_batch(reinterpret_cast<const char*>(to_find.data()), nullptr, to_find.size(), + results.data()); + EXPECT_EQ(results[0], 1); + EXPECT_EQ(results[1], 1); + EXPECT_EQ(results[2], 0); + EXPECT_EQ(results[3], 1); + EXPECT_EQ(results[4], 1); + EXPECT_EQ(results[5], 0); + EXPECT_EQ(results[6], 0); + EXPECT_EQ(results[7], 1); + } +}; + +TEST_F(BitmapFilterPredicateTest, insert) { Review Comment: warning: all parameters should be named in a function [readability-named-parameter] ```suggestion TEST_F(BitmapFilterPredicateTest /*unused*/, insert /*unused*/) { ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } + + void find_batch(BitmapFilterFuncBase* func) { + const std::vector<int32_t> to_find = create_vector(); + std::vector<uint8_t> results(to_find.size()); + func->find_batch(reinterpret_cast<const char*>(to_find.data()), nullptr, to_find.size(), + results.data()); + EXPECT_EQ(results[0], 1); + EXPECT_EQ(results[1], 1); + EXPECT_EQ(results[2], 0); + EXPECT_EQ(results[3], 1); + EXPECT_EQ(results[4], 1); + EXPECT_EQ(results[5], 0); + EXPECT_EQ(results[6], 0); + EXPECT_EQ(results[7], 1); + } +}; + +TEST_F(BitmapFilterPredicateTest, insert) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + EXPECT_TRUE(func->empty()); + + BitmapValue bitmap_value = create_bitmap_value(); + func->insert(&bitmap_value); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, insert_many) { Review Comment: warning: all parameters should be named in a function [readability-named-parameter] ```suggestion TEST_F(BitmapFilterPredicateTest /*unused*/, insert_many /*unused*/) { ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } + + void find_batch(BitmapFilterFuncBase* func) { + const std::vector<int32_t> to_find = create_vector(); + std::vector<uint8_t> results(to_find.size()); + func->find_batch(reinterpret_cast<const char*>(to_find.data()), nullptr, to_find.size(), + results.data()); + EXPECT_EQ(results[0], 1); + EXPECT_EQ(results[1], 1); + EXPECT_EQ(results[2], 0); + EXPECT_EQ(results[3], 1); + EXPECT_EQ(results[4], 1); + EXPECT_EQ(results[5], 0); + EXPECT_EQ(results[6], 0); + EXPECT_EQ(results[7], 1); + } +}; + +TEST_F(BitmapFilterPredicateTest, insert) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + EXPECT_TRUE(func->empty()); + + BitmapValue bitmap_value = create_bitmap_value(); + func->insert(&bitmap_value); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, insert_many) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + std::vector<const BitmapValue*> bitmaps; + + func->insert_many(bitmaps); + EXPECT_TRUE(func->empty()); + + auto bitmap = create_bitmap_value(); + bitmaps.emplace_back(&bitmap); + + func->insert_many(bitmaps); + EXPECT_FALSE(func->empty()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, assign) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, contains_any) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + auto* filter = assert_cast<BitmapFilterFunc<PrimitiveType::TYPE_INT>*>(func.get()); + + EXPECT_TRUE(filter->contains_any(1, 5)); Review Comment: warning: 5 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp EXPECT_TRUE(filter->contains_any(1, 5)); ^ ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } + + void find_batch(BitmapFilterFuncBase* func) { + const std::vector<int32_t> to_find = create_vector(); + std::vector<uint8_t> results(to_find.size()); + func->find_batch(reinterpret_cast<const char*>(to_find.data()), nullptr, to_find.size(), + results.data()); + EXPECT_EQ(results[0], 1); + EXPECT_EQ(results[1], 1); + EXPECT_EQ(results[2], 0); + EXPECT_EQ(results[3], 1); + EXPECT_EQ(results[4], 1); + EXPECT_EQ(results[5], 0); + EXPECT_EQ(results[6], 0); + EXPECT_EQ(results[7], 1); + } +}; + +TEST_F(BitmapFilterPredicateTest, insert) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + EXPECT_TRUE(func->empty()); + + BitmapValue bitmap_value = create_bitmap_value(); + func->insert(&bitmap_value); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, insert_many) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + std::vector<const BitmapValue*> bitmaps; + + func->insert_many(bitmaps); + EXPECT_TRUE(func->empty()); + + auto bitmap = create_bitmap_value(); + bitmaps.emplace_back(&bitmap); + + func->insert_many(bitmaps); + EXPECT_FALSE(func->empty()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, assign) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, contains_any) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + auto* filter = assert_cast<BitmapFilterFunc<PrimitiveType::TYPE_INT>*>(func.get()); + + EXPECT_TRUE(filter->contains_any(1, 5)); + EXPECT_FALSE(filter->contains_any(5, 7)); + EXPECT_TRUE(filter->contains_any(5, 8)); + EXPECT_FALSE(filter->contains_any(1025, 2047)); + EXPECT_TRUE(filter->contains_any(1025, 2048)); Review Comment: warning: 1025 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp EXPECT_TRUE(filter->contains_any(1025, 2048)); ^ ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } + + void find_batch(BitmapFilterFuncBase* func) { + const std::vector<int32_t> to_find = create_vector(); + std::vector<uint8_t> results(to_find.size()); + func->find_batch(reinterpret_cast<const char*>(to_find.data()), nullptr, to_find.size(), + results.data()); + EXPECT_EQ(results[0], 1); + EXPECT_EQ(results[1], 1); + EXPECT_EQ(results[2], 0); + EXPECT_EQ(results[3], 1); + EXPECT_EQ(results[4], 1); + EXPECT_EQ(results[5], 0); + EXPECT_EQ(results[6], 0); + EXPECT_EQ(results[7], 1); + } +}; + +TEST_F(BitmapFilterPredicateTest, insert) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + EXPECT_TRUE(func->empty()); + + BitmapValue bitmap_value = create_bitmap_value(); + func->insert(&bitmap_value); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, insert_many) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + std::vector<const BitmapValue*> bitmaps; + + func->insert_many(bitmaps); + EXPECT_TRUE(func->empty()); + + auto bitmap = create_bitmap_value(); + bitmaps.emplace_back(&bitmap); + + func->insert_many(bitmaps); + EXPECT_FALSE(func->empty()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, assign) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, contains_any) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + auto* filter = assert_cast<BitmapFilterFunc<PrimitiveType::TYPE_INT>*>(func.get()); + + EXPECT_TRUE(filter->contains_any(1, 5)); + EXPECT_FALSE(filter->contains_any(5, 7)); + EXPECT_TRUE(filter->contains_any(5, 8)); + EXPECT_FALSE(filter->contains_any(1025, 2047)); Review Comment: warning: 1025 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp EXPECT_FALSE(filter->contains_any(1025, 2047)); ^ ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } + + void find_batch(BitmapFilterFuncBase* func) { + const std::vector<int32_t> to_find = create_vector(); + std::vector<uint8_t> results(to_find.size()); + func->find_batch(reinterpret_cast<const char*>(to_find.data()), nullptr, to_find.size(), + results.data()); + EXPECT_EQ(results[0], 1); + EXPECT_EQ(results[1], 1); + EXPECT_EQ(results[2], 0); + EXPECT_EQ(results[3], 1); + EXPECT_EQ(results[4], 1); + EXPECT_EQ(results[5], 0); + EXPECT_EQ(results[6], 0); + EXPECT_EQ(results[7], 1); + } +}; + +TEST_F(BitmapFilterPredicateTest, insert) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + EXPECT_TRUE(func->empty()); + + BitmapValue bitmap_value = create_bitmap_value(); + func->insert(&bitmap_value); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, insert_many) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + std::vector<const BitmapValue*> bitmaps; + + func->insert_many(bitmaps); + EXPECT_TRUE(func->empty()); + + auto bitmap = create_bitmap_value(); + bitmaps.emplace_back(&bitmap); + + func->insert_many(bitmaps); + EXPECT_FALSE(func->empty()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, assign) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, contains_any) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + auto* filter = assert_cast<BitmapFilterFunc<PrimitiveType::TYPE_INT>*>(func.get()); + + EXPECT_TRUE(filter->contains_any(1, 5)); + EXPECT_FALSE(filter->contains_any(5, 7)); + EXPECT_TRUE(filter->contains_any(5, 8)); Review Comment: warning: 5 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp EXPECT_TRUE(filter->contains_any(5, 8)); ^ ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } + + void find_batch(BitmapFilterFuncBase* func) { + const std::vector<int32_t> to_find = create_vector(); + std::vector<uint8_t> results(to_find.size()); + func->find_batch(reinterpret_cast<const char*>(to_find.data()), nullptr, to_find.size(), + results.data()); + EXPECT_EQ(results[0], 1); + EXPECT_EQ(results[1], 1); + EXPECT_EQ(results[2], 0); + EXPECT_EQ(results[3], 1); + EXPECT_EQ(results[4], 1); + EXPECT_EQ(results[5], 0); + EXPECT_EQ(results[6], 0); + EXPECT_EQ(results[7], 1); + } +}; + +TEST_F(BitmapFilterPredicateTest, insert) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + EXPECT_TRUE(func->empty()); + + BitmapValue bitmap_value = create_bitmap_value(); + func->insert(&bitmap_value); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, insert_many) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + std::vector<const BitmapValue*> bitmaps; + + func->insert_many(bitmaps); + EXPECT_TRUE(func->empty()); + + auto bitmap = create_bitmap_value(); + bitmaps.emplace_back(&bitmap); + + func->insert_many(bitmaps); + EXPECT_FALSE(func->empty()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, assign) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, contains_any) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + auto* filter = assert_cast<BitmapFilterFunc<PrimitiveType::TYPE_INT>*>(func.get()); + + EXPECT_TRUE(filter->contains_any(1, 5)); + EXPECT_FALSE(filter->contains_any(5, 7)); + EXPECT_TRUE(filter->contains_any(5, 8)); + EXPECT_FALSE(filter->contains_any(1025, 2047)); Review Comment: warning: 2047 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp EXPECT_FALSE(filter->contains_any(1025, 2047)); ^ ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } + + void find_batch(BitmapFilterFuncBase* func) { + const std::vector<int32_t> to_find = create_vector(); + std::vector<uint8_t> results(to_find.size()); + func->find_batch(reinterpret_cast<const char*>(to_find.data()), nullptr, to_find.size(), + results.data()); + EXPECT_EQ(results[0], 1); + EXPECT_EQ(results[1], 1); + EXPECT_EQ(results[2], 0); + EXPECT_EQ(results[3], 1); + EXPECT_EQ(results[4], 1); + EXPECT_EQ(results[5], 0); + EXPECT_EQ(results[6], 0); + EXPECT_EQ(results[7], 1); + } +}; + +TEST_F(BitmapFilterPredicateTest, insert) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + EXPECT_TRUE(func->empty()); + + BitmapValue bitmap_value = create_bitmap_value(); + func->insert(&bitmap_value); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, insert_many) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + std::vector<const BitmapValue*> bitmaps; + + func->insert_many(bitmaps); + EXPECT_TRUE(func->empty()); + + auto bitmap = create_bitmap_value(); + bitmaps.emplace_back(&bitmap); + + func->insert_many(bitmaps); + EXPECT_FALSE(func->empty()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, assign) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, contains_any) { Review Comment: warning: all parameters should be named in a function [readability-named-parameter] ```suggestion TEST_F(BitmapFilterPredicateTest /*unused*/, contains_any /*unused*/) { ``` ########## be/test/exprs/bitmapfilter_predicate_test.cpp: ########## @@ -0,0 +1,169 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 +// +// http://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/bitmapfilter_predicate.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include <memory> +#include <string> + +#include "common/object_pool.h" +#include "common/status.h" +#include "exprs/create_predicate_function.h" +#include "gtest/gtest_pred_impl.h" +#include "runtime/define_primitive_type.h" + +namespace doris { +class BitmapFilterPredicateTest : public testing::Test { +public: + BitmapFilterPredicateTest() = default; + virtual void SetUp() {} + virtual void TearDown() {} + + BitmapValue create_bitmap_value() { + BitmapValue bitmap_value; + bitmap_value.add(1); + bitmap_value.add(2); + bitmap_value.add(4); + bitmap_value.add(8); + bitmap_value.add(1024); + bitmap_value.add(2048); + + return bitmap_value; + } + + std::vector<int32_t> create_vector() { return {1, 2, 3, 4, 1024, 1025, 2047, 2048}; } + + void find_batch(BitmapFilterFuncBase* func) { + const std::vector<int32_t> to_find = create_vector(); + std::vector<uint8_t> results(to_find.size()); + func->find_batch(reinterpret_cast<const char*>(to_find.data()), nullptr, to_find.size(), + results.data()); + EXPECT_EQ(results[0], 1); + EXPECT_EQ(results[1], 1); + EXPECT_EQ(results[2], 0); + EXPECT_EQ(results[3], 1); + EXPECT_EQ(results[4], 1); + EXPECT_EQ(results[5], 0); + EXPECT_EQ(results[6], 0); + EXPECT_EQ(results[7], 1); + } +}; + +TEST_F(BitmapFilterPredicateTest, insert) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + EXPECT_TRUE(func->empty()); + + BitmapValue bitmap_value = create_bitmap_value(); + func->insert(&bitmap_value); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, insert_many) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + std::vector<const BitmapValue*> bitmaps; + + func->insert_many(bitmaps); + EXPECT_TRUE(func->empty()); + + auto bitmap = create_bitmap_value(); + bitmaps.emplace_back(&bitmap); + + func->insert_many(bitmaps); + EXPECT_FALSE(func->empty()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, assign) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + find_batch(func.get()); +} + +TEST_F(BitmapFilterPredicateTest, contains_any) { + std::unique_ptr<BitmapFilterFuncBase> func(create_bitmap_filter(PrimitiveType::TYPE_INT)); + + BitmapValue bitmap_value = create_bitmap_value(); + EXPECT_EQ(func->assign(&bitmap_value), Status::OK()); + + auto* filter = assert_cast<BitmapFilterFunc<PrimitiveType::TYPE_INT>*>(func.get()); + + EXPECT_TRUE(filter->contains_any(1, 5)); + EXPECT_FALSE(filter->contains_any(5, 7)); + EXPECT_TRUE(filter->contains_any(5, 8)); Review Comment: warning: 8 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp EXPECT_TRUE(filter->contains_any(5, 8)); ^ ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org