github-actions[bot] commented on code in PR #62589:
URL: https://github.com/apache/doris/pull/62589#discussion_r3302353005


##########
be/test/exec/runtime_filter/runtime_filter_partition_pruner_test.cpp:
##########
@@ -0,0 +1,450 @@
+// 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 "exec/runtime_filter/runtime_filter_partition_pruner.h"
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <type_traits>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+#include "core/data_type/data_type_factory.hpp"
+#include "core/string_ref.h"
+#include "core/types.h"
+#include "exec/runtime_filter/utils.h"
+#include "exprs/create_predicate_function.h"
+#include "exprs/runtime_filter_expr.h"
+#include "exprs/vdirect_in_predicate.h"
+#include "exprs/vexpr.h"
+#include "exprs/vexpr_context.h"
+#include "exprs/vliteral.h"
+#include "exprs/vslot_ref.h"
+#include "runtime/descriptors.h"
+
+namespace doris {
+
+class IdentityWrapperExpr final : public VExpr {
+public:
+    explicit IdentityWrapperExpr(DataTypePtr type) : VExpr(std::move(type), 
false) {}
+
+    const std::string& expr_name() const override { return _expr_name; }
+
+    Status execute_column_impl(VExprContext* context, const Block* block, 
const Selector* selector,
+                               size_t count, ColumnPtr& result_column) const 
override {
+        return get_child(0)->execute_column(context, block, selector, count, 
result_column);
+    }
+
+private:
+    std::string _expr_name = "identity_wrapper";
+};
+
+class RuntimeFilterPartitionPrunerTest : public testing::Test {
+protected:
+    static constexpr SlotId SLOT_ID = 1;
+
+    template <PrimitiveType PT>
+    using CppType = typename PrimitiveTypeTraits<PT>::CppType;
+
+    template <PrimitiveType PT>
+    TExprNode literal_node(const CppType<PT>& value, int precision = 0, int 
scale = 0) {
+        TExprNode node;
+        EXPECT_TRUE(create_texpr_literal_node<PT>(&value, &node, precision, 
scale).ok());
+        return node;
+    }
+
+    TExprNode null_node(PrimitiveType ptype, int precision = 0, int scale = 0) 
{
+        TExprNode node;
+        node.__set_node_type(TExprNodeType::NULL_LITERAL);
+        node.__set_type(create_type_desc(ptype, precision, scale));
+        return node;
+    }
+
+    template <PrimitiveType PT>
+    TPartitionBoundary list_boundary(int64_t partition_id, const 
std::vector<TExprNode>& values) {
+        TPartitionBoundary boundary;
+        boundary.__set_partition_id(partition_id);
+        boundary.__set_slot_id(SLOT_ID);
+        boundary.__set_list_values(values);
+        return boundary;
+    }
+
+    template <PrimitiveType PT>
+    TPartitionBoundary range_boundary(int64_t partition_id, const CppType<PT>& 
start,
+                                      const CppType<PT>& end, int precision = 
0, int scale = 0) {
+        TPartitionBoundary boundary;
+        boundary.__set_partition_id(partition_id);
+        boundary.__set_slot_id(SLOT_ID);
+        boundary.__set_range_start(literal_node<PT>(start, precision, scale));
+        boundary.__set_range_end(literal_node<PT>(end, precision, scale));
+        return boundary;
+    }
+
+    template <PrimitiveType PT>
+    TPartitionBoundary lower_unbounded_range_boundary(int64_t partition_id, 
const CppType<PT>& end,
+                                                      int precision = 0, int 
scale = 0) {
+        TPartitionBoundary boundary;
+        boundary.__set_partition_id(partition_id);
+        boundary.__set_slot_id(SLOT_ID);
+        boundary.__set_range_end(literal_node<PT>(end, precision, scale));
+        return boundary;
+    }
+
+    template <PrimitiveType PT>
+    TPartitionBoundary upper_unbounded_range_boundary(int64_t partition_id,
+                                                      const CppType<PT>& 
start, int precision = 0,
+                                                      int scale = 0) {
+        TPartitionBoundary boundary;
+        boundary.__set_partition_id(partition_id);
+        boundary.__set_slot_id(SLOT_ID);
+        boundary.__set_range_start(literal_node<PT>(start, precision, scale));
+        return boundary;
+    }
+
+    SlotDescriptor slot_desc(PrimitiveType ptype, bool nullable, int precision 
= 0, int scale = 0) {
+        SlotDescriptor slot;
+        slot._id = SLOT_ID;
+        slot._type = DataTypeFactory::instance().create_data_type(
+                create_type_desc(ptype, precision, scale), nullable);
+        slot._col_name = "part_col";
+        return slot;
+    }
+
+    std::unique_ptr<ParsedPartitionBoundaries> parse_boundaries(
+            PrimitiveType ptype, const std::vector<TPartitionBoundary>& 
boundaries,
+            bool nullable = false, int precision = 0, int scale = 0) {
+        auto slot = slot_desc(ptype, nullable, precision, scale);
+        phmap::flat_hash_map<int, SlotDescriptor*> slots;
+        slots[SLOT_ID] = &slot;
+        auto parsed = std::make_unique<ParsedPartitionBoundaries>();
+        EXPECT_TRUE(parsed->parse(boundaries, slots).ok());
+        return parsed;
+    }
+
+    template <PrimitiveType PT>
+    std::shared_ptr<HybridSetBase> in_filter(const CppType<PT>& value, bool 
contain_null = false) {
+        std::shared_ptr<HybridSetBase> set(create_set(PT, contain_null));
+        if constexpr (std::is_same_v<CppType<PT>, String>) {
+            StringRef ref(value.data(), value.size());
+            set->insert(&ref);
+        } else {
+            set->insert(&value);
+        }
+        if (contain_null) {
+            set->insert(static_cast<const void*>(nullptr));
+        }
+        return set;
+    }
+
+    template <PrimitiveType PT>
+    VExprSPtr in_predicate(const CppType<PT>& value, bool contain_null = 
false) {
+        TExprNode node;
+        node.__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
+        node.__set_node_type(contain_null ? TExprNodeType::NULL_AWARE_IN_PRED
+                                          : TExprNodeType::IN_PRED);
+        node.in_predicate.__set_is_not_in(false);
+        node.__set_opcode(TExprOpcode::FILTER_IN);
+        node.__set_is_nullable(false);
+        return VDirectInPredicate::create_shared(node, in_filter<PT>(value, 
contain_null));
+    }
+
+    template <PrimitiveType PT>
+    VExprSPtr minmax_predicate_le(const CppType<PT>& value, const DataTypePtr& 
type) {
+        VExprSPtr pred;
+        TExprNode node;
+        EXPECT_TRUE(create_vbin_predicate(type, TExprOpcode::LE, pred, &node, 
false).ok());
+        VExprSPtr lhs;
+        VExprSPtr rhs;
+        EXPECT_TRUE(create_literal(type, &value, lhs).ok());
+        EXPECT_TRUE(create_literal(type, &value, rhs).ok());
+        pred->add_child(lhs);
+        pred->add_child(rhs);
+        return pred;
+    }
+
+    VExprSPtr slot_ref_expr(const DataTypePtr& type) {
+        TSlotRef slot_ref_thrift;
+        slot_ref_thrift.__set_slot_id(SLOT_ID);
+        slot_ref_thrift.__set_tuple_id(0);
+        TExprNode node;
+        node.__set_type(create_type_desc(type->get_primitive_type(), 
type->get_precision(),
+                                         type->get_scale()));
+        node.__set_node_type(TExprNodeType::SLOT_REF);
+        node.__set_num_children(0);
+        node.__set_slot_ref(slot_ref_thrift);
+        auto slot_ref = VSlotRef::create_shared(node);
+        slot_ref->set_slot_id(SLOT_ID);
+        slot_ref->set_column_id(0);
+        return slot_ref;
+    }
+
+    VExprSPtr identity_wrapper_expr(const DataTypePtr& type) {
+        auto expr = std::make_shared<IdentityWrapperExpr>(type);
+        expr->add_child(slot_ref_expr(type));
+        return expr;
+    }
+
+    TRuntimeFilterDesc rf_desc_with_monotonicity(int filter_id, int 
scan_node_id,
+                                                 const std::vector<int64_t>& 
partition_ids) {
+        TRuntimeFilterDesc desc;
+        desc.__set_filter_id(filter_id);
+        std::vector<TPartitionTargetExprMonotonicity> entries;
+        entries.reserve(partition_ids.size());
+        for (int64_t partition_id : partition_ids) {
+            TPartitionTargetExprMonotonicity entry;
+            entry.__set_partition_id(partition_id);
+            
entry.__set_monotonicity(TTargetExprMonotonicity::MONOTONIC_INCREASING);
+            entries.emplace_back(std::move(entry));
+        }
+        desc.__set_planId_to_partition_target_monotonicity({{scan_node_id, 
std::move(entries)}});
+        return desc;
+    }
+
+    template <PrimitiveType PT>
+    void assert_parse_and_prune_type(const CppType<PT>& keep_value, const 
CppType<PT>& prune_value,
+                                     int precision = 0, int scale = 0) {
+        auto boundaries = std::vector<TPartitionBoundary> {
+                list_boundary<PT>(1, {literal_node<PT>(keep_value, precision, 
scale)}),
+                list_boundary<PT>(2, {literal_node<PT>(prune_value, precision, 
scale)})};
+        auto parsed = parse_boundaries(PT, boundaries, false, precision, 
scale);
+        ASSERT_FALSE(parsed->empty());
+        ASSERT_EQ(parsed->total_partitions(), 2);
+        const auto& parsed_boundaries = 
parsed->slot_to_boundaries().at(SLOT_ID);
+
+        RuntimeFilterPartitionPruner in_pruner;
+        phmap::flat_hash_set<int64_t> in_pruned;
+        in_pruner._try_prune_by_single_rf(parsed_boundaries, 
in_predicate<PT>(keep_value),

Review Comment:
   This test calls `_try_prune_by_single_rf()` directly, but that method is 
declared `private` in `RuntimeFilterPartitionPruner` 
(`be/src/exec/runtime_filter/runtime_filter_partition_pruner.h`). The same 
private helper is also called later in this file, so `run-be-ut` should fail at 
compile time before these cases can execute. Please either exercise the public 
`prune_by_runtime_filters()` API here (as the later public-path test does), or 
explicitly expose/friend a test-only helper.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to