Coverage Report

Created: 2026-03-12 17:07

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
1.96k
    static FunctionPtr create() { return std::make_shared<FunctionIsNull>(); }
52
53
59
    std::string get_name() const override { return name; }
54
55
1.95k
    size_t get_number_of_arguments() const override { return 1; }
56
13.8k
    bool use_default_implementation_for_nulls() const override { return false; }
57
58
1.95k
    DataTypePtr get_return_type_impl(const DataTypes&) const override {
59
1.95k
        return std::make_shared<DataTypeUInt8>();
60
1.95k
    }
61
62
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
63
11.8k
                        uint32_t result, size_t input_rows_count) const override {
64
11.8k
        const ColumnWithTypeAndName& elem = block.get_by_position(arguments[0]);
65
11.8k
        if (auto* nullable = check_and_get_column<ColumnNullable>(*elem.column)) {
66
            /// Merely return the embedded null map.
67
10.3k
            block.get_by_position(result).column = nullable->get_null_map_column_ptr();
68
10.3k
        } else {
69
            /// Since no element is nullable, return a zero-constant column representing
70
            /// a zero-filled null map.
71
1.50k
            block.get_by_position(result).column = DataTypeUInt8().create_column_const(
72
1.50k
                    elem.column->size(), Field::create_field<TYPE_BOOLEAN>(0));
73
1.50k
        }
74
11.8k
        return Status::OK();
75
11.8k
    }
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
34
            segment_v2::InvertedIndexResultBitmap& bitmap_result) const override {
83
34
        if (iterators.empty() || iterators[0] == nullptr) {
84
2
            return Status::OK();
85
2
        }
86
32
        auto* index_iter = iterators[0];
87
32
        if (!index_iter->has_null()) {
88
0
            return Status::OK();
89
0
        }
90
32
        segment_v2::InvertedIndexQueryCacheHandle null_bitmap_cache_handle;
91
32
        RETURN_IF_ERROR(index_iter->read_null_bitmap(&null_bitmap_cache_handle));
92
32
        std::shared_ptr<roaring::Roaring> null_bitmap = null_bitmap_cache_handle.get_bitmap();
93
32
        if (!null_bitmap) {
94
0
            return Status::OK();
95
0
        }
96
32
        auto data_bitmap = std::make_shared<roaring::Roaring>(*null_bitmap);
97
32
        auto empty_null_bitmap = std::make_shared<roaring::Roaring>();
98
32
        bitmap_result = segment_v2::InvertedIndexResultBitmap(std::move(data_bitmap),
99
32
                                                              std::move(empty_null_bitmap));
100
32
        return Status::OK();
101
32
    }
102
};
103
104
} // namespace doris