Coverage Report

Created: 2026-06-18 14:05

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