Coverage Report

Created: 2026-01-06 13:44

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