/root/doris/be/src/olap/null_predicate.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | #include "olap/null_predicate.h" |
19 | | |
20 | | #include <string.h> |
21 | | |
22 | | #include <roaring/roaring.hh> |
23 | | |
24 | | #include "olap/rowset/segment_v2/bitmap_index_reader.h" |
25 | | #include "olap/rowset/segment_v2/inverted_index_cache.h" |
26 | | #include "olap/rowset/segment_v2/inverted_index_reader.h" |
27 | | #include "vec/columns/column.h" |
28 | | #include "vec/columns/column_nullable.h" |
29 | | #include "vec/runtime/vdatetime_value.h" |
30 | | |
31 | | using namespace doris::vectorized; |
32 | | |
33 | | namespace doris { |
34 | | |
35 | | NullPredicate::NullPredicate(uint32_t column_id, bool is_null, bool opposite) |
36 | 0 | : ColumnPredicate(column_id), _is_null(opposite != is_null) {} |
37 | | |
38 | 0 | PredicateType NullPredicate::type() const { |
39 | 0 | return _is_null ? PredicateType::IS_NULL : PredicateType::IS_NOT_NULL; |
40 | 0 | } |
41 | | |
42 | | Status NullPredicate::evaluate(BitmapIndexIterator* iterator, uint32_t num_rows, |
43 | 0 | roaring::Roaring* roaring) const { |
44 | 0 | if (iterator != nullptr) { |
45 | 0 | roaring::Roaring null_bitmap; |
46 | 0 | RETURN_IF_ERROR(iterator->read_null_bitmap(&null_bitmap)); |
47 | 0 | if (_is_null) { |
48 | 0 | *roaring &= null_bitmap; |
49 | 0 | } else { |
50 | 0 | *roaring -= null_bitmap; |
51 | 0 | } |
52 | 0 | } |
53 | 0 | return Status::OK(); |
54 | 0 | } |
55 | | |
56 | | Status NullPredicate::evaluate(const Schema& schema, InvertedIndexIterator* iterator, |
57 | 0 | uint32_t num_rows, roaring::Roaring* bitmap) const { |
58 | | // mask out null_bitmap, since NULL cmp VALUE will produce NULL |
59 | | // and be treated as false in WHERE |
60 | 0 | InvertedIndexQueryCacheHandle null_bitmap_cache_handle; |
61 | 0 | RETURN_IF_ERROR(iterator->read_null_bitmap(&null_bitmap_cache_handle)); |
62 | 0 | std::shared_ptr<roaring::Roaring> null_bitmap = null_bitmap_cache_handle.get_bitmap(); |
63 | 0 | if (null_bitmap) { |
64 | 0 | if (_is_null) { |
65 | 0 | *bitmap &= *null_bitmap; |
66 | 0 | } else { |
67 | 0 | *bitmap -= *null_bitmap; |
68 | 0 | } |
69 | 0 | } else { |
70 | | // all rows not null |
71 | 0 | if (_is_null) { |
72 | 0 | *bitmap -= *bitmap; |
73 | 0 | } |
74 | 0 | } |
75 | |
|
76 | 0 | return Status::OK(); |
77 | 0 | } |
78 | | |
79 | | uint16_t NullPredicate::evaluate(const vectorized::IColumn& column, uint16_t* sel, |
80 | 0 | uint16_t size) const { |
81 | 0 | uint16_t new_size = 0; |
82 | 0 | if (auto* nullable = check_and_get_column<ColumnNullable>(column)) { |
83 | 0 | if (!nullable->has_null()) { |
84 | 0 | return _is_null ? 0 : size; |
85 | 0 | } |
86 | 0 | auto& pred_col = nullable->get_null_map_data(); |
87 | 0 | constexpr bool is_nullable = true; |
88 | 0 | #define EVALUATE_WITH_NULL_IMPL(IDX) pred_col[IDX] == _is_null |
89 | 0 | #define EVALUATE_WITHOUT_NULL_IMPL(IDX) true |
90 | 0 | EVALUATE_BY_SELECTOR(EVALUATE_WITH_NULL_IMPL, EVALUATE_WITHOUT_NULL_IMPL) |
91 | 0 | #undef EVALUATE_WITH_NULL_IMPL |
92 | 0 | #undef EVALUATE_WITHOUT_NULL_IMPL |
93 | 0 | return new_size; |
94 | 0 | } else { |
95 | 0 | if (_is_null) return 0; |
96 | 0 | } |
97 | 0 | return size; |
98 | 0 | } |
99 | | |
100 | | void NullPredicate::evaluate_or(const IColumn& column, const uint16_t* sel, uint16_t size, |
101 | 0 | bool* flags) const { |
102 | 0 | if (auto* nullable = check_and_get_column<ColumnNullable>(column)) { |
103 | 0 | if (!nullable->has_null()) { |
104 | 0 | if (!_is_null) { |
105 | 0 | memset(flags, true, size); |
106 | 0 | } |
107 | 0 | } else { |
108 | 0 | auto& null_map = nullable->get_null_map_data(); |
109 | 0 | for (uint16_t i = 0; i < size; ++i) { |
110 | 0 | if (flags[i]) continue; |
111 | 0 | uint16_t idx = sel[i]; |
112 | 0 | flags[i] |= (null_map[idx] == _is_null); |
113 | 0 | } |
114 | 0 | } |
115 | 0 | } else { |
116 | 0 | if (!_is_null) memset(flags, true, size); |
117 | 0 | } |
118 | 0 | } |
119 | | |
120 | | void NullPredicate::evaluate_and(const IColumn& column, const uint16_t* sel, uint16_t size, |
121 | 0 | bool* flags) const { |
122 | 0 | if (auto* nullable = check_and_get_column<ColumnNullable>(column)) { |
123 | 0 | if (!nullable->has_null()) { |
124 | 0 | if (_is_null) { |
125 | 0 | memset(flags, false, size); |
126 | 0 | } |
127 | 0 | } else { |
128 | 0 | auto& null_map = nullable->get_null_map_data(); |
129 | 0 | for (uint16_t i = 0; i < size; ++i) { |
130 | 0 | if (flags[i]) continue; |
131 | 0 | uint16_t idx = sel[i]; |
132 | 0 | flags[i] &= (null_map[idx] == _is_null); |
133 | 0 | } |
134 | 0 | } |
135 | 0 | } else { |
136 | 0 | if (_is_null) memset(flags, false, size); |
137 | 0 | } |
138 | 0 | } |
139 | | |
140 | | void NullPredicate::evaluate_vec(const vectorized::IColumn& column, uint16_t size, |
141 | 0 | bool* flags) const { |
142 | 0 | if (auto* nullable = check_and_get_column<ColumnNullable>(column)) { |
143 | 0 | if (!nullable->has_null()) { |
144 | 0 | memset(flags, !_is_null, size); |
145 | 0 | } |
146 | 0 | auto& null_map = nullable->get_null_map_data(); |
147 | 0 | for (uint16_t i = 0; i < size; ++i) { |
148 | 0 | flags[i] = (null_map[i] == _is_null); |
149 | 0 | } |
150 | 0 | } else { |
151 | 0 | if (_is_null) memset(flags, false, size); |
152 | 0 | } |
153 | 0 | } |
154 | | |
155 | | } //namespace doris |