/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 BitmapIndexIterator; |
41 | | class InvertedIndexIterator; |
42 | | } // namespace segment_v2 |
43 | | namespace vectorized { |
44 | | class IColumn; |
45 | | } // namespace vectorized |
46 | | |
47 | | class NullPredicate : public ColumnPredicate { |
48 | | public: |
49 | | NullPredicate(uint32_t column_id, bool is_null, bool opposite = false); |
50 | | |
51 | | PredicateType type() const override; |
52 | | |
53 | | Status evaluate(BitmapIndexIterator* iterator, uint32_t num_rows, |
54 | | roaring::Roaring* roaring) const override; |
55 | | |
56 | | Status evaluate(const vectorized::IndexFieldNameAndTypePair& name_with_type, |
57 | | IndexIterator* iterator, uint32_t num_rows, |
58 | | roaring::Roaring* bitmap) const override; |
59 | | |
60 | | void evaluate_or(const vectorized::IColumn& column, const uint16_t* sel, uint16_t size, |
61 | | bool* flags) const override; |
62 | | |
63 | | void evaluate_and(const vectorized::IColumn& column, const uint16_t* sel, uint16_t size, |
64 | | bool* flags) const override; |
65 | | |
66 | 0 | bool evaluate_and(const std::pair<WrapperField*, WrapperField*>& statistic) const override { |
67 | 0 | if (_is_null) { |
68 | 0 | return statistic.first->is_null(); |
69 | 0 | } else { |
70 | 0 | return !statistic.second->is_null(); |
71 | 0 | } |
72 | 0 | } |
73 | | |
74 | 5 | bool evaluate_and(vectorized::ParquetPredicate::ColumnStat* statistic) const override { |
75 | 5 | if (!(*statistic->get_stat_func)(statistic, column_id())) { |
76 | 2 | return true; |
77 | 2 | } |
78 | 3 | if (_is_null) { |
79 | 1 | return true; |
80 | 2 | } else { |
81 | 2 | return !statistic->is_all_null; |
82 | 2 | } |
83 | 3 | } |
84 | | |
85 | | bool evaluate_and(vectorized::ParquetPredicate::CachedPageIndexStat* statistic, |
86 | 0 | RowRanges* row_ranges) const override { |
87 | 0 | vectorized::ParquetPredicate::PageIndexStat* stat = nullptr; |
88 | 0 | if (!(statistic->get_stat_func)(&stat, column_id())) { |
89 | 0 | return true; |
90 | 0 | } |
91 | 0 | for (int page_id = 0; page_id < stat->num_of_pages; page_id++) { |
92 | 0 | if (_is_null || !stat->is_all_null[page_id]) { |
93 | 0 | row_ranges->add(stat->ranges[page_id]); |
94 | 0 | } |
95 | 0 | }; |
96 | 0 | return row_ranges->count() > 0; |
97 | 0 | } |
98 | | |
99 | 0 | bool evaluate_del(const std::pair<WrapperField*, WrapperField*>& statistic) const override { |
100 | | // evaluate_del only use for delete condition to filter page, need use delete condition origin value, |
101 | | // when opposite==true, origin value 'is null'->'is not null' and 'is not null'->'is null', |
102 | | // so when _is_null==true, need check 'is not null' and _is_null==false, need check 'is null' |
103 | 0 | if (_is_null) { |
104 | 0 | return !statistic.first->is_null() && !statistic.second->is_null(); |
105 | 0 | } else { |
106 | 0 | return statistic.first->is_null() && statistic.second->is_null(); |
107 | 0 | } |
108 | 0 | } |
109 | | |
110 | 0 | bool evaluate_and(const segment_v2::BloomFilter* bf) const override { |
111 | | // null predicate can not use ngram bf, just return true to accept |
112 | 0 | if (bf->is_ngram_bf()) return true; |
113 | 0 | if (_is_null) { |
114 | 0 | return bf->test_bytes(nullptr, 0); |
115 | 0 | } else { |
116 | 0 | throw Exception(Status::FatalError( |
117 | 0 | "Bloom filter is not supported by predicate type: is_null=")); |
118 | 0 | } |
119 | 0 | } |
120 | | |
121 | 0 | bool can_do_bloom_filter(bool ngram) const override { return _is_null && !ngram; } |
122 | | |
123 | | void evaluate_vec(const vectorized::IColumn& column, uint16_t size, bool* flags) const override; |
124 | | |
125 | | private: |
126 | | uint16_t _evaluate_inner(const vectorized::IColumn& column, uint16_t* sel, |
127 | | uint16_t size) const override; |
128 | | |
129 | 0 | std::string _debug_string() const override { |
130 | 0 | std::string info = "NullPredicate(" + std::string(_is_null ? "is_null" : "not_null") + ")"; |
131 | 0 | return info; |
132 | 0 | } |
133 | | |
134 | | bool _is_null; //true for null, false for not null |
135 | | }; |
136 | | |
137 | | } //namespace doris |