Coverage Report

Created: 2025-12-04 16:12

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