Coverage Report

Created: 2024-11-18 12:21

/root/doris/be/src/olap/null_predicate.h
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
#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
33
namespace roaring {
34
class Roaring;
35
} // namespace roaring
36
37
namespace doris {
38
namespace segment_v2 {
39
class BitmapIndexIterator;
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(BitmapIndexIterator* iterator, uint32_t num_rows,
53
                    roaring::Roaring* roaring) const override;
54
55
    Status evaluate(const vectorized::IndexFieldNameAndTypePair& name_with_type,
56
                    InvertedIndexIterator* iterator, uint32_t num_rows,
57
                    roaring::Roaring* bitmap) const override;
58
59
    void evaluate_or(const vectorized::IColumn& column, const uint16_t* sel, uint16_t size,
60
                     bool* flags) const override;
61
62
    void evaluate_and(const vectorized::IColumn& column, const uint16_t* sel, uint16_t size,
63
                      bool* flags) const override;
64
65
0
    bool evaluate_and(const std::pair<WrapperField*, WrapperField*>& statistic) const override {
66
0
        if (_is_null) {
67
0
            return statistic.first->is_null();
68
0
        } else {
69
0
            return !statistic.second->is_null();
70
0
        }
71
0
    }
72
73
0
    bool evaluate_del(const std::pair<WrapperField*, WrapperField*>& statistic) const override {
74
        // evaluate_del only use for delete condition to filter page, need use delete condition origin value,
75
        // when opposite==true, origin value 'is null'->'is not null' and 'is not null'->'is null',
76
        // so when _is_null==true, need check 'is not null' and _is_null==false, need check 'is null'
77
0
        if (_is_null) {
78
0
            return !statistic.first->is_null() && !statistic.second->is_null();
79
0
        } else {
80
0
            return statistic.first->is_null() && statistic.second->is_null();
81
0
        }
82
0
    }
83
84
0
    bool evaluate_and(const segment_v2::BloomFilter* bf) const override {
85
        // null predicate can not use ngram bf, just return true to accept
86
0
        if (bf->is_ngram_bf()) return true;
87
0
        if (_is_null) {
88
0
            return bf->test_bytes(nullptr, 0);
89
0
        } else {
90
0
            LOG(FATAL) << "Bloom filter is not supported by predicate type: is_null=" << _is_null;
91
0
            return true;
92
0
        }
93
0
    }
94
95
0
    bool can_do_bloom_filter(bool ngram) const override { return _is_null && !ngram; }
96
97
0
    bool can_do_apply_safely(PrimitiveType input_type, bool is_null) const override {
98
        // Always safe to apply is null predicate
99
0
        return true;
100
0
    }
101
102
    void evaluate_vec(const vectorized::IColumn& column, uint16_t size, bool* flags) const override;
103
104
private:
105
    uint16_t _evaluate_inner(const vectorized::IColumn& column, uint16_t* sel,
106
                             uint16_t size) const override;
107
108
0
    std::string _debug_string() const override {
109
0
        std::string info = "NullPredicate(" + std::string(_is_null ? "is_null" : "not_null") + ")";
110
0
        return info;
111
0
    }
112
113
    bool _is_null; //true for null, false for not null
114
};
115
116
} //namespace doris