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