|
29 | 29 |
|
30 | 30 | #include "common/consts.h" |
31 | 31 | #include "core/assert_cast.h" |
| 32 | +#include "core/block/block.h" |
| 33 | +#include "core/column/column_vector.h" |
32 | 34 | #include "core/data_type/data_type_number.h" |
33 | 35 | #include "core/data_type/data_type_string.h" |
34 | 36 | #include "exec/operator/file_scan_operator.h" |
| 37 | +#include "exec/scan/file_scanner.h" |
| 38 | +#include "exec/scan/split_source_connector.h" |
35 | 39 | #include "exprs/runtime_filter_expr.h" |
36 | 40 | #include "exprs/vdirect_in_predicate.h" |
37 | 41 | #include "exprs/vslot_ref.h" |
@@ -63,6 +67,33 @@ VExprSPtr slot_ref(int slot_id, int column_id, DataTypePtr type, const std::stri |
63 | 67 | return VSlotRef::create_shared(slot_id, column_id, -1, std::move(type), name); |
64 | 68 | } |
65 | 69 |
|
| 70 | +TExprNode bool_in_pred_node(); |
| 71 | + |
| 72 | +class UnsafePartitionPredicate final : public VExpr { |
| 73 | +public: |
| 74 | + UnsafePartitionPredicate() : VExpr(std::make_shared<DataTypeUInt8>(), false) {} |
| 75 | + |
| 76 | + Status execute_column_impl(VExprContext*, const Block*, const Selector*, size_t count, |
| 77 | + ColumnPtr& result_column) const override { |
| 78 | + auto result = ColumnUInt8::create(); |
| 79 | + result->get_data().resize_fill(count, 1); |
| 80 | + result_column = std::move(result); |
| 81 | + return Status::OK(); |
| 82 | + } |
| 83 | + |
| 84 | + const std::string& expr_name() const override { return _expr_name; } |
| 85 | + bool is_safe_to_execute_on_selected_rows() const override { return false; } |
| 86 | + |
| 87 | +private: |
| 88 | + const std::string _expr_name = "UnsafePartitionPredicate"; |
| 89 | +}; |
| 90 | + |
| 91 | +VExprContextSPtr runtime_filter_context(VExprSPtr impl, int filter_id) { |
| 92 | + const auto node = bool_in_pred_node(); |
| 93 | + return VExprContext::create_shared( |
| 94 | + RuntimeFilterExpr::create_shared(node, std::move(impl), 0.4, false, filter_id)); |
| 95 | +} |
| 96 | + |
66 | 97 | TExprNode bool_in_pred_node() { |
67 | 98 | TTypeDesc bool_type; |
68 | 99 | TTypeNode bool_node; |
@@ -512,4 +543,24 @@ TEST(FileScannerV2Test, RewriteSlotRefsToGlobalIndexMatrix) { |
512 | 543 | } |
513 | 544 | } |
514 | 545 |
|
| 546 | +TEST(FileScannerTest, PartitionPruningStopsAtUnsafePredicate) { |
| 547 | + const auto bool_type = std::make_shared<DataTypeUInt8>(); |
| 548 | + auto unsafe_predicate = std::make_shared<UnsafePartitionPredicate>(); |
| 549 | + unsafe_predicate->add_child(slot_ref(1, 0, bool_type, "part")); |
| 550 | + VExprContextSPtrs conjuncts { |
| 551 | + runtime_filter_context(slot_ref(1, 0, bool_type, "part"), 1), |
| 552 | + runtime_filter_context(std::move(unsafe_predicate), 2), |
| 553 | + runtime_filter_context(slot_ref(1, 0, bool_type, "part"), 3), |
| 554 | + }; |
| 555 | + |
| 556 | + RuntimeState state {TQueryOptions(), TQueryGlobals()}; |
| 557 | + RuntimeProfile profile("file_scanner"); |
| 558 | + FileScanner scanner(&state, &profile, nullptr, nullptr, nullptr); |
| 559 | + scanner.TEST_init_runtime_filter_partition_prune_ctxs(conjuncts, {{1, 0}}); |
| 560 | + |
| 561 | + const auto& partition_conjuncts = scanner.TEST_runtime_filter_partition_prune_ctxs(); |
| 562 | + ASSERT_EQ(partition_conjuncts.size(), 1); |
| 563 | + EXPECT_EQ(partition_conjuncts[0], conjuncts[0]); |
| 564 | +} |
| 565 | + |
515 | 566 | } // namespace doris |
0 commit comments