/root/doris/be/src/olap/null_predicate.h
Line | Count | Source |
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 | | #pragma once |
19 | | |
20 | | #include <glog/logging.h> |
21 | | #include <stdint.h> |
22 | | |
23 | | #include <ostream> |
24 | | #include <string> |
25 | | #include <utility> |
26 | | |
27 | | #include "common/status.h" |
28 | | #include "olap/column_predicate.h" |
29 | | #include "olap/rowset/segment_v2/bloom_filter.h" |
30 | | #include "olap/schema.h" |
31 | | #include "olap/wrapper_field.h" |
32 | | #include "vec/exec/format/parquet/parquet_predicate.h" |
33 | | |
34 | | namespace roaring { |
35 | | class Roaring; |
36 | | } // namespace roaring |
37 | | |
38 | | namespace doris { |
39 | | namespace segment_v2 { |
40 | | class InvertedIndexIterator; |
41 | | } // namespace segment_v2 |
42 | | namespace vectorized { |
43 | | class IColumn; |
44 | | } // namespace vectorized |
45 | | |
46 | | class NullPredicate final : public ColumnPredicate { |
47 | | public: |
48 | | ENABLE_FACTORY_CREATOR(NullPredicate); |
49 | | NullPredicate(uint32_t column_id, std::string col_name, bool is_null, PrimitiveType type, |
50 | | bool opposite = false); |
51 | | NullPredicate(const NullPredicate& other) = delete; |
52 | | NullPredicate(const NullPredicate& other, uint32_t column_id) |
53 | 0 | : ColumnPredicate(other, column_id), _is_null(other._is_null) {} |
54 | 43 | ~NullPredicate() override = default; |
55 | 0 | std::shared_ptr<ColumnPredicate> clone(uint32_t column_id) const override { |
56 | 0 | return NullPredicate::create_shared(*this, column_id); |
57 | 0 | } |
58 | 0 | std::string debug_string() const override { |
59 | 0 | fmt::memory_buffer debug_string_buffer; |
60 | 0 | fmt::format_to(debug_string_buffer, "NullPredicate({}, is_null={})", |
61 | 0 | ColumnPredicate::debug_string(), _is_null); |
62 | 0 | return fmt::to_string(debug_string_buffer); |
63 | 0 | } |
64 | 0 | bool could_be_erased() const override { return true; } |
65 | | |
66 | | PredicateType type() const override; |
67 | | |
68 | | Status evaluate(const vectorized::IndexFieldNameAndTypePair& name_with_type, |
69 | | IndexIterator* iterator, uint32_t num_rows, |
70 | | roaring::Roaring* bitmap) const override; |
71 | | |
72 | | void evaluate_or(const vectorized::IColumn& column, const uint16_t* sel, uint16_t size, |
73 | | bool* flags) const override; |
74 | | |
75 | | void evaluate_and(const vectorized::IColumn& column, const uint16_t* sel, uint16_t size, |
76 | | bool* flags) const override; |
77 | | |
78 | 0 | bool evaluate_and(const ZoneMapInfo& zone_map_info) const override { |
79 | 0 | if (_is_null) { |
80 | 0 | return zone_map_info.has_null; |
81 | 0 | } else { |
82 | 0 | return !zone_map_info.is_all_null; |
83 | 0 | } |
84 | 0 | } |
85 | | |
86 | 5 | bool evaluate_and(vectorized::ParquetPredicate::ColumnStat* statistic) const override { |
87 | 5 | if (!(*statistic->get_stat_func)(statistic, column_id())) { |
88 | 2 | return true; |
89 | 2 | } |
90 | 3 | if (_is_null) { |
91 | 1 | return true; |
92 | 2 | } else { |
93 | 2 | return !statistic->is_all_null; |
94 | 2 | } |
95 | 3 | } |
96 | | |
97 | | bool evaluate_and(vectorized::ParquetPredicate::CachedPageIndexStat* statistic, |
98 | 0 | RowRanges* row_ranges) const override { |
99 | 0 | vectorized::ParquetPredicate::PageIndexStat* stat = nullptr; |
100 | 0 | if (!(statistic->get_stat_func)(&stat, column_id())) { |
101 | 0 | row_ranges->add(statistic->row_group_range); |
102 | 0 | return true; |
103 | 0 | } |
104 | 0 | for (int page_id = 0; page_id < stat->num_of_pages; page_id++) { |
105 | 0 | if (_is_null || !stat->is_all_null[page_id]) { |
106 | 0 | row_ranges->add(stat->ranges[page_id]); |
107 | 0 | } |
108 | 0 | }; |
109 | 0 | return row_ranges->count() > 0; |
110 | 0 | } |
111 | | |
112 | 0 | bool evaluate_del(const ZoneMapInfo& zone_map_info) const override { |
113 | | // evaluate_del only use for delete condition to filter page, need use delete condition origin value, |
114 | | // when opposite==true, origin value 'is null'->'is not null' and 'is not null'->'is null', |
115 | | // so when _is_null==true, need check 'is not null' and _is_null==false, need check 'is null' |
116 | 0 | if (_is_null) { |
117 | 0 | return !zone_map_info.has_null; |
118 | 0 | } else { |
119 | 0 | return zone_map_info.is_all_null; |
120 | 0 | } |
121 | 0 | } |
122 | | |
123 | 0 | bool evaluate_and(const segment_v2::BloomFilter* bf) const override { |
124 | | // null predicate can not use ngram bf, just return true to accept |
125 | 0 | if (bf->is_ngram_bf()) return true; |
126 | 0 | if (_is_null) { |
127 | 0 | return bf->test_bytes(nullptr, 0); |
128 | 0 | } else { |
129 | 0 | throw Exception(Status::FatalError( |
130 | 0 | "Bloom filter is not supported by predicate type: is_null=")); |
131 | 0 | } |
132 | 0 | } |
133 | | |
134 | 0 | bool can_do_bloom_filter(bool ngram) const override { return _is_null && !ngram; } |
135 | | |
136 | | void evaluate_vec(const vectorized::IColumn& column, uint16_t size, bool* flags) const override; |
137 | | |
138 | | private: |
139 | | uint16_t _evaluate_inner(const vectorized::IColumn& column, uint16_t* sel, |
140 | | uint16_t size) const override; |
141 | | |
142 | | bool _is_null; //true for null, false for not null |
143 | | }; |
144 | | |
145 | | } //namespace doris |