Coverage Report

Created: 2026-03-15 22:14

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/function/function.h"
38
39
namespace doris {
40
class FunctionContext;
41
} // namespace doris
42
43
namespace doris {
44
45
/// Implements the function is_null which returns true if a value
46
/// is null, false otherwise.
47
class FunctionIsNull : public IFunction {
48
public:
49
    static constexpr auto name = "is_null_pred";
50
51
4
    static FunctionPtr create() { return std::make_shared<FunctionIsNull>(); }
52
53
1
    std::string get_name() const override { return name; }
54
55
2
    size_t get_number_of_arguments() const override { return 1; }
56
2
    bool use_default_implementation_for_nulls() const override { return false; }
57
58
2
    DataTypePtr get_return_type_impl(const DataTypes&) const override {
59
2
        return std::make_shared<DataTypeUInt8>();
60
2
    }
61
62
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
63
0
                        uint32_t result, size_t input_rows_count) const override {
64
0
        const ColumnWithTypeAndName& elem = block.get_by_position(arguments[0]);
65
0
        if (auto* nullable = check_and_get_column<ColumnNullable>(*elem.column)) {
66
            /// Merely return the embedded null map.
67
0
            block.get_by_position(result).column = nullable->get_null_map_column_ptr();
68
0
        } else {
69
            /// Since no element is nullable, return a zero-constant column representing
70
            /// a zero-filled null map.
71
0
            block.get_by_position(result).column = DataTypeUInt8().create_column_const(
72
0
                    elem.column->size(), Field::create_field<TYPE_BOOLEAN>(0));
73
0
        }
74
0
        return Status::OK();
75
0
    }
76
77
    Status evaluate_inverted_index(
78
            const ColumnsWithTypeAndName& arguments,
79
            const std::vector<IndexFieldNameAndTypePair>& data_type_with_names,
80
            std::vector<segment_v2::IndexIterator*> iterators, uint32_t num_rows,
81
            const InvertedIndexAnalyzerCtx* /*analyzer_ctx*/,
82
5
            segment_v2::InvertedIndexResultBitmap& bitmap_result) const override {
83
5
        if (iterators.empty() || iterators[0] == nullptr) {
84
2
            return Status::OK();
85
2
        }
86
3
        auto* index_iter = iterators[0];
87
3
        if (!index_iter->has_null()) {
88
0
            return Status::OK();
89
0
        }
90
3
        segment_v2::InvertedIndexQueryCacheHandle null_bitmap_cache_handle;
91
3
        RETURN_IF_ERROR(index_iter->read_null_bitmap(&null_bitmap_cache_handle));
92
3
        std::shared_ptr<roaring::Roaring> null_bitmap = null_bitmap_cache_handle.get_bitmap();
93
3
        if (!null_bitmap) {
94
0
            return Status::OK();
95
0
        }
96
3
        auto data_bitmap = std::make_shared<roaring::Roaring>(*null_bitmap);
97
3
        auto empty_null_bitmap = std::make_shared<roaring::Roaring>();
98
3
        bitmap_result = segment_v2::InvertedIndexResultBitmap(std::move(data_bitmap),
99
3
                                                              std::move(empty_null_bitmap));
100
3
        return Status::OK();
101
3
    }
102
};
103
104
} // namespace doris