/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 vectorized::IndexFieldNameAndTypePair& name_with_type, |
57 | | InvertedIndexIterator* iterator, uint32_t num_rows, |
58 | 0 | roaring::Roaring* bitmap) const { |
59 | 0 | if (iterator->has_null()) { |
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 | |
|
64 | 0 | if (null_bitmap) { |
65 | 0 | if (_is_null) { |
66 | 0 | *bitmap &= *null_bitmap; // Keep only nulls in bitmap if _is_null is true |
67 | 0 | } else { |
68 | 0 | *bitmap -= *null_bitmap; // Remove nulls from bitmap if _is_null is false |
69 | 0 | } |
70 | 0 | } else if (_is_null) { |
71 | 0 | *bitmap = roaring::Roaring(); // Reset bitmap to an empty bitmap |
72 | 0 | } |
73 | 0 | } else if (_is_null) { |
74 | 0 | *bitmap = roaring::Roaring(); // Reset bitmap to an empty bitmap |
75 | 0 | } |
76 | | |
77 | 0 | return Status::OK(); |
78 | 0 | } |
79 | | |
80 | | uint16_t NullPredicate::_evaluate_inner(const vectorized::IColumn& column, uint16_t* sel, |
81 | 0 | uint16_t size) const { |
82 | 0 | uint16_t new_size = 0; |
83 | 0 | if (auto* nullable = check_and_get_column<ColumnNullable>(column)) { |
84 | 0 | if (!nullable->has_null()) { |
85 | 0 | return _is_null ? 0 : size; |
86 | 0 | } |
87 | 0 | auto& pred_col = nullable->get_null_map_data(); |
88 | 0 | constexpr bool is_nullable = true; |
89 | 0 | #define EVALUATE_WITH_NULL_IMPL(IDX) pred_col[IDX] == _is_null |
90 | 0 | #define EVALUATE_WITHOUT_NULL_IMPL(IDX) true |
91 | 0 | EVALUATE_BY_SELECTOR(EVALUATE_WITH_NULL_IMPL, EVALUATE_WITHOUT_NULL_IMPL) |
92 | 0 | #undef EVALUATE_WITH_NULL_IMPL |
93 | 0 | #undef EVALUATE_WITHOUT_NULL_IMPL |
94 | 0 | return new_size; |
95 | 0 | } else { |
96 | 0 | if (_is_null) return 0; |
97 | 0 | } |
98 | 0 | return size; |
99 | 0 | } |
100 | | |
101 | | void NullPredicate::evaluate_or(const IColumn& column, const uint16_t* sel, uint16_t size, |
102 | 0 | bool* flags) const { |
103 | 0 | if (auto* nullable = check_and_get_column<ColumnNullable>(column)) { |
104 | 0 | if (!nullable->has_null()) { |
105 | 0 | if (!_is_null) { |
106 | 0 | memset(flags, true, size); |
107 | 0 | } |
108 | 0 | } else { |
109 | 0 | auto& null_map = nullable->get_null_map_data(); |
110 | 0 | for (uint16_t i = 0; i < size; ++i) { |
111 | 0 | if (flags[i]) continue; |
112 | 0 | uint16_t idx = sel[i]; |
113 | 0 | flags[i] |= (null_map[idx] == _is_null); |
114 | 0 | } |
115 | 0 | } |
116 | 0 | } else { |
117 | 0 | if (!_is_null) memset(flags, true, size); |
118 | 0 | } |
119 | 0 | } |
120 | | |
121 | | void NullPredicate::evaluate_and(const IColumn& column, const uint16_t* sel, uint16_t size, |
122 | 0 | bool* flags) const { |
123 | 0 | if (auto* nullable = check_and_get_column<ColumnNullable>(column)) { |
124 | 0 | if (!nullable->has_null()) { |
125 | 0 | if (_is_null) { |
126 | 0 | memset(flags, false, size); |
127 | 0 | } |
128 | 0 | } else { |
129 | 0 | auto& null_map = nullable->get_null_map_data(); |
130 | 0 | for (uint16_t i = 0; i < size; ++i) { |
131 | 0 | if (flags[i]) continue; |
132 | 0 | uint16_t idx = sel[i]; |
133 | 0 | flags[i] &= (null_map[idx] == _is_null); |
134 | 0 | } |
135 | 0 | } |
136 | 0 | } else { |
137 | 0 | if (_is_null) memset(flags, false, size); |
138 | 0 | } |
139 | 0 | } |
140 | | |
141 | | void NullPredicate::evaluate_vec(const vectorized::IColumn& column, uint16_t size, |
142 | 0 | bool* flags) const { |
143 | 0 | if (auto* nullable = check_and_get_column<ColumnNullable>(column)) { |
144 | 0 | if (!nullable->has_null()) { |
145 | 0 | memset(flags, !_is_null, size); |
146 | 0 | } |
147 | 0 | auto& null_map = nullable->get_null_map_data(); |
148 | 0 | for (uint16_t i = 0; i < size; ++i) { |
149 | 0 | flags[i] = (null_map[i] == _is_null); |
150 | 0 | } |
151 | 0 | } else { |
152 | 0 | if (_is_null) memset(flags, false, size); |
153 | 0 | } |
154 | 0 | } |
155 | | |
156 | | } //namespace doris |