Coverage Report

Created: 2026-08-20 18:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/is_null.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
// This file is copied from
18
// https://github.com/ClickHouse/ClickHouse/blob/master/src/Functions/IsNull.cpp
19
// and modified by Doris
20
21
#include <stddef.h>
22
23
#include <algorithm>
24
#include <boost/iterator/iterator_facade.hpp>
25
#include <memory>
26
#include <string>
27
28
#include "common/status.h"
29
#include "core/block/block.h"
30
#include "core/block/column_numbers.h"
31
#include "core/block/column_with_type_and_name.h"
32
#include "core/column/column.h"
33
#include "core/column/column_nullable.h"
34
#include "core/data_type/data_type_number.h"
35
#include "core/field.h"
36
#include "exprs/aggregate/aggregate_function.h"
37
#include "exprs/expr_zonemap_filter.h"
38
#include "exprs/function/function.h"
39
#include "exprs/vslot_ref.h"
40
#include "storage/index/index_iterator.h"
41
42
namespace doris {
43
class FunctionContext;
44
} // namespace doris
45
46
namespace doris {
47
48
/// Implements the function is_null which returns true if a value
49
/// is null, false otherwise.
50
class FunctionIsNull : public IFunction {
51
public:
52
    static constexpr auto name = "is_null_pred";
53
54
13
    static FunctionPtr create() { return std::make_shared<FunctionIsNull>(); }
55
56
7
    std::string get_name() const override { return name; }
57
58
11
    size_t get_number_of_arguments() const override { return 1; }
59
14
    bool use_default_implementation_for_nulls() const override { return false; }
60
61
11
    DataTypePtr get_return_type_impl(const DataTypes&) const override {
62
11
        return std::make_shared<DataTypeUInt8>();
63
11
    }
64
65
    ZoneMapFilterResult evaluate_zonemap_filter(const ZoneMapEvalContext& ctx,
66
11
                                                const VExprSPtrs& arguments) const override {
67
11
        return expr_zonemap::eval_null_zonemap(ctx, arguments, true);
68
11
    }
69
70
46
    bool can_evaluate_zonemap_filter(const VExprSPtrs& arguments) const override {
71
46
        return std::dynamic_pointer_cast<VSlotRef>(arguments[0]) != nullptr;
72
46
    }
73
74
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
75
3
                        uint32_t result, size_t input_rows_count) const override {
76
3
        const ColumnWithTypeAndName& elem = block.get_by_position(arguments[0]);
77
3
        if (auto* nullable = check_and_get_column<ColumnNullable>(*elem.column)) {
78
            /// Merely return the embedded null map.
79
3
            block.get_by_position(result).column = nullable->get_null_map_column_ptr();
80
3
        } else {
81
            /// Since no element is nullable, return a zero-constant column representing
82
            /// a zero-filled null map.
83
0
            block.get_by_position(result).column = DataTypeUInt8().create_column_const(
84
0
                    elem.column->size(), Field::create_field<TYPE_BOOLEAN>(0));
85
0
        }
86
3
        return Status::OK();
87
3
    }
88
89
    Status evaluate_inverted_index(
90
            const ColumnsWithTypeAndName& arguments,
91
            const std::vector<IndexFieldNameAndTypePair>& data_type_with_names,
92
            std::vector<segment_v2::IndexIterator*> iterators, uint32_t num_rows,
93
            const InvertedIndexAnalyzerCtx* /*analyzer_ctx*/,
94
5
            segment_v2::InvertedIndexResultBitmap& bitmap_result) const override {
95
5
        if (iterators.empty() || iterators[0] == nullptr) {
96
2
            return Status::OK();
97
2
        }
98
3
        auto* index_iter = iterators[0];
99
3
        if (!index_iter->has_null()) {
100
0
            return Status::OK();
101
0
        }
102
3
        segment_v2::InvertedIndexQueryCacheHandle null_bitmap_cache_handle;
103
3
        RETURN_IF_ERROR(index_iter->read_null_bitmap(&null_bitmap_cache_handle));
104
3
        std::shared_ptr<roaring::Roaring> null_bitmap = null_bitmap_cache_handle.get_bitmap();
105
3
        if (!null_bitmap) {
106
0
            return Status::OK();
107
0
        }
108
3
        auto data_bitmap = std::make_shared<roaring::Roaring>(*null_bitmap);
109
3
        auto empty_null_bitmap = std::make_shared<roaring::Roaring>();
110
3
        bitmap_result = segment_v2::InvertedIndexResultBitmap(std::move(data_bitmap),
111
3
                                                              std::move(empty_null_bitmap));
112
3
        return Status::OK();
113
3
    }
114
};
115
116
} // namespace doris