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