Coverage Report

Created: 2026-01-06 13:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/olap/null_predicate.cpp
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
#include "olap/null_predicate.h"
19
20
#include <string.h>
21
22
#include <roaring/roaring.hh>
23
24
#include "olap/rowset/segment_v2/inverted_index_cache.h"
25
#include "olap/rowset/segment_v2/inverted_index_reader.h"
26
#include "vec/columns/column.h"
27
#include "vec/columns/column_nullable.h"
28
#include "vec/runtime/vdatetime_value.h"
29
30
using namespace doris::vectorized;
31
32
namespace doris {
33
34
NullPredicate::NullPredicate(uint32_t column_id, std::string col_name, bool is_null,
35
                             PrimitiveType type, bool opposite)
36
43
        : ColumnPredicate(column_id, col_name, type), _is_null(opposite != is_null) {}
37
38
24
PredicateType NullPredicate::type() const {
39
24
    return _is_null ? PredicateType::IS_NULL : PredicateType::IS_NOT_NULL;
40
24
}
41
42
Status NullPredicate::evaluate(const vectorized::IndexFieldNameAndTypePair& name_with_type,
43
                               IndexIterator* iterator, uint32_t num_rows,
44
0
                               roaring::Roaring* bitmap) const {
45
0
    if (iterator->has_null()) {
46
0
        InvertedIndexQueryCacheHandle null_bitmap_cache_handle;
47
0
        RETURN_IF_ERROR(iterator->read_null_bitmap(&null_bitmap_cache_handle));
48
0
        std::shared_ptr<roaring::Roaring> null_bitmap = null_bitmap_cache_handle.get_bitmap();
49
50
0
        if (null_bitmap) {
51
0
            if (_is_null) {
52
0
                *bitmap &= *null_bitmap; // Keep only nulls in bitmap if _is_null is true
53
0
            } else {
54
0
                *bitmap -= *null_bitmap; // Remove nulls from bitmap if _is_null is false
55
0
            }
56
0
        } else if (_is_null) {
57
0
            *bitmap = roaring::Roaring(); // Reset bitmap to an empty bitmap
58
0
        }
59
0
    } else if (_is_null) {
60
0
        *bitmap = roaring::Roaring(); // Reset bitmap to an empty bitmap
61
0
    }
62
63
0
    return Status::OK();
64
0
}
65
66
uint16_t NullPredicate::_evaluate_inner(const vectorized::IColumn& column, uint16_t* sel,
67
12
                                        uint16_t size) const {
68
12
    uint16_t new_size = 0;
69
12
    if (auto* nullable = check_and_get_column<ColumnNullable>(column)) {
70
12
        if (!nullable->has_null()) {
71
12
            return _is_null ? 0 : size;
72
12
        }
73
0
        auto& pred_col = nullable->get_null_map_data();
74
0
        constexpr bool is_nullable = true;
75
0
#define EVALUATE_WITH_NULL_IMPL(IDX) pred_col[IDX] == _is_null
76
0
#define EVALUATE_WITHOUT_NULL_IMPL(IDX) true
77
0
        EVALUATE_BY_SELECTOR(EVALUATE_WITH_NULL_IMPL, EVALUATE_WITHOUT_NULL_IMPL)
78
0
#undef EVALUATE_WITH_NULL_IMPL
79
0
#undef EVALUATE_WITHOUT_NULL_IMPL
80
0
        return new_size;
81
12
    } else {
82
0
        if (_is_null) return 0;
83
0
    }
84
0
    return size;
85
12
}
86
87
void NullPredicate::evaluate_or(const IColumn& column, const uint16_t* sel, uint16_t size,
88
0
                                bool* flags) const {
89
0
    if (auto* nullable = check_and_get_column<ColumnNullable>(column)) {
90
0
        if (!nullable->has_null()) {
91
0
            if (!_is_null) {
92
0
                memset(flags, true, size);
93
0
            }
94
0
        } else {
95
0
            auto& null_map = nullable->get_null_map_data();
96
0
            for (uint16_t i = 0; i < size; ++i) {
97
0
                if (flags[i]) continue;
98
0
                uint16_t idx = sel[i];
99
0
                flags[i] |= (null_map[idx] == _is_null);
100
0
            }
101
0
        }
102
0
    } else {
103
0
        if (!_is_null) memset(flags, true, size);
104
0
    }
105
0
}
106
107
void NullPredicate::evaluate_and(const IColumn& column, const uint16_t* sel, uint16_t size,
108
0
                                 bool* flags) const {
109
0
    if (auto* nullable = check_and_get_column<ColumnNullable>(column)) {
110
0
        if (!nullable->has_null()) {
111
0
            if (_is_null) {
112
0
                memset(flags, false, size);
113
0
            }
114
0
        } else {
115
0
            auto& null_map = nullable->get_null_map_data();
116
0
            for (uint16_t i = 0; i < size; ++i) {
117
0
                if (flags[i]) continue;
118
0
                uint16_t idx = sel[i];
119
0
                flags[i] &= (null_map[idx] == _is_null);
120
0
            }
121
0
        }
122
0
    } else {
123
0
        if (_is_null) memset(flags, false, size);
124
0
    }
125
0
}
126
127
void NullPredicate::evaluate_vec(const vectorized::IColumn& column, uint16_t size,
128
0
                                 bool* flags) const {
129
0
    if (auto* nullable = check_and_get_column<ColumnNullable>(column)) {
130
0
        if (!nullable->has_null()) {
131
0
            memset(flags, !_is_null, size);
132
0
        }
133
0
        auto& null_map = nullable->get_null_map_data();
134
0
        for (uint16_t i = 0; i < size; ++i) {
135
0
            flags[i] = (null_map[i] == _is_null);
136
0
        }
137
0
    } else {
138
0
        if (_is_null) memset(flags, false, size);
139
0
    }
140
0
}
141
142
} //namespace doris