|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +#include "runtime/runtime_predicate.h" |
| 19 | + |
| 20 | +#include <gtest/gtest.h> |
| 21 | + |
| 22 | +#include "core/data_type/data_type_factory.hpp" |
| 23 | +#include "core/field.h" |
| 24 | +#include "exec/pipeline/thrift_builder.h" |
| 25 | +#include "runtime/descriptors.h" |
| 26 | + |
| 27 | +namespace doris { |
| 28 | +namespace { |
| 29 | + |
| 30 | +constexpr TPlanNodeId SOURCE_NODE_ID = 10; |
| 31 | +constexpr TPlanNodeId TARGET_NODE_ID = 20; |
| 32 | +constexpr SlotId SLOT_ID = 0; |
| 33 | + |
| 34 | +TTopnFilterDesc create_topn_filter_desc() { |
| 35 | + auto target_expr = TRuntimeFilterDescBuilder::get_default_expr(); |
| 36 | + |
| 37 | + TTopnFilterDesc desc; |
| 38 | + desc.__set_source_node_id(SOURCE_NODE_ID); |
| 39 | + desc.__set_is_asc(true); |
| 40 | + desc.__set_null_first(false); |
| 41 | + desc.__set_target_node_id_to_target_expr({{TARGET_NODE_ID, target_expr}}); |
| 42 | + return desc; |
| 43 | +} |
| 44 | + |
| 45 | +SlotDescriptor create_int_slot_descriptor() { |
| 46 | + SlotDescriptor slot_desc; |
| 47 | + slot_desc._id = SLOT_ID; |
| 48 | + slot_desc._col_name = "k1"; |
| 49 | + slot_desc._type = DataTypeFactory::instance().create_data_type(PrimitiveType::TYPE_INT, false); |
| 50 | + return slot_desc; |
| 51 | +} |
| 52 | + |
| 53 | +} // namespace |
| 54 | + |
| 55 | +TEST(RuntimePredicateTest, init_target_creates_column_predicate_for_valid_column_id) { |
| 56 | + RuntimePredicate predicate(create_topn_filter_desc()); |
| 57 | + predicate.set_detected_source(); |
| 58 | + |
| 59 | + auto slot_desc = create_int_slot_descriptor(); |
| 60 | + phmap::flat_hash_map<int, SlotDescriptor*> slot_id_to_slot_desc; |
| 61 | + slot_id_to_slot_desc[SLOT_ID] = &slot_desc; |
| 62 | + |
| 63 | + ASSERT_TRUE(predicate.init_target(TARGET_NODE_ID, slot_id_to_slot_desc, 0).ok()); |
| 64 | + |
| 65 | + EXPECT_TRUE(predicate.enable()); |
| 66 | + EXPECT_EQ("k1", predicate.get_col_name(TARGET_NODE_ID)); |
| 67 | + EXPECT_NE(nullptr, predicate.get_predicate(TARGET_NODE_ID)); |
| 68 | +} |
| 69 | + |
| 70 | +TEST(RuntimePredicateTest, init_target_without_column_predicate_still_enables_runtime_filter) { |
| 71 | + RuntimePredicate predicate(create_topn_filter_desc()); |
| 72 | + predicate.set_detected_source(); |
| 73 | + |
| 74 | + phmap::flat_hash_map<int, SlotDescriptor*> slot_id_to_slot_desc; |
| 75 | + ASSERT_TRUE(predicate.init_target(TARGET_NODE_ID, slot_id_to_slot_desc, -1).ok()); |
| 76 | + |
| 77 | + EXPECT_TRUE(predicate.enable()); |
| 78 | + EXPECT_EQ(nullptr, predicate.get_predicate(TARGET_NODE_ID)); |
| 79 | + |
| 80 | + auto top_value = Field::create_field<TYPE_INT>(10); |
| 81 | + ASSERT_TRUE(predicate.update(top_value).ok()); |
| 82 | + EXPECT_TRUE(predicate.has_value()); |
| 83 | + EXPECT_EQ(top_value, predicate.get_value()); |
| 84 | +} |
| 85 | + |
| 86 | +} // namespace doris |
0 commit comments