/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 | | |
33 | | namespace roaring { |
34 | | class Roaring; |
35 | | } // namespace roaring |
36 | | |
37 | | namespace doris { |
38 | | namespace segment_v2 { |
39 | | class InvertedIndexIterator; |
40 | | } // namespace segment_v2 |
41 | | namespace vectorized { |
42 | | class IColumn; |
43 | | } // namespace vectorized |
44 | | |
45 | | class NullPredicate : public ColumnPredicate { |
46 | | public: |
47 | | NullPredicate(uint32_t column_id, bool is_null, bool opposite = false); |
48 | | |
49 | | PredicateType type() const override; |
50 | | |
51 | | Status evaluate(const vectorized::IndexFieldNameAndTypePair& name_with_type, |
52 | | IndexIterator* iterator, uint32_t num_rows, |
53 | | roaring::Roaring* bitmap) const override; |
54 | | |
55 | | void evaluate_or(const vectorized::IColumn& column, const uint16_t* sel, uint16_t size, |
56 | | bool* flags) const override; |
57 | | |
58 | | void evaluate_and(const vectorized::IColumn& column, const uint16_t* sel, uint16_t size, |
59 | | bool* flags) const override; |
60 | | |
61 | 0 | bool evaluate_and(const std::pair<WrapperField*, WrapperField*>& statistic) const override { |
62 | 0 | if (_is_null) { |
63 | 0 | return statistic.first->is_null(); |
64 | 0 | } else { |
65 | 0 | return !statistic.second->is_null(); |
66 | 0 | } |
67 | 0 | } |
68 | | |
69 | 0 | bool evaluate_del(const std::pair<WrapperField*, WrapperField*>& statistic) const override { |
70 | | // evaluate_del only use for delete condition to filter page, need use delete condition origin value, |
71 | | // when opposite==true, origin value 'is null'->'is not null' and 'is not null'->'is null', |
72 | | // so when _is_null==true, need check 'is not null' and _is_null==false, need check 'is null' |
73 | 0 | if (_is_null) { |
74 | 0 | return !statistic.first->is_null() && !statistic.second->is_null(); |
75 | 0 | } else { |
76 | 0 | return statistic.first->is_null() && statistic.second->is_null(); |
77 | 0 | } |
78 | 0 | } |
79 | | |
80 | 0 | bool evaluate_and(const segment_v2::BloomFilter* bf) const override { |
81 | | // null predicate can not use ngram bf, just return true to accept |
82 | 0 | if (bf->is_ngram_bf()) return true; |
83 | 0 | if (_is_null) { |
84 | 0 | return bf->test_bytes(nullptr, 0); |
85 | 0 | } else { |
86 | 0 | throw Exception(Status::FatalError( |
87 | 0 | "Bloom filter is not supported by predicate type: is_null=")); |
88 | 0 | } |
89 | 0 | } |
90 | | |
91 | 0 | bool can_do_bloom_filter(bool ngram) const override { return _is_null && !ngram; } |
92 | | |
93 | | void evaluate_vec(const vectorized::IColumn& column, uint16_t size, bool* flags) const override; |
94 | | |
95 | | private: |
96 | | uint16_t _evaluate_inner(const vectorized::IColumn& column, uint16_t* sel, |
97 | | uint16_t size) const override; |
98 | | |
99 | 0 | std::string _debug_string() const override { |
100 | 0 | std::string info = "NullPredicate(" + std::string(_is_null ? "is_null" : "not_null") + ")"; |
101 | 0 | return info; |
102 | 0 | } |
103 | | |
104 | | bool _is_null; //true for null, false for not null |
105 | | }; |
106 | | |
107 | | } //namespace doris |