Coverage Report

Created: 2026-03-15 22:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/array/function_array_binary.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
18
#pragma once
19
20
#include "core/column/column_array.h"
21
#include "core/data_type/data_type_array.h"
22
#include "core/data_type/data_type_number.h"
23
#include "exprs/function/array/function_array_utils.h"
24
#include "exprs/function/function.h"
25
#include "exprs/function/function_helpers.h"
26
27
namespace doris {
28
29
// Functions with arguments is two arrays of the same element type.
30
template <typename Impl, typename Name>
31
class FunctionArrayBinary : public IFunction {
32
public:
33
    static constexpr auto name = Name::name;
34
2
    static FunctionPtr create() { return std::make_shared<FunctionArrayBinary>(); }
35
1
    String get_name() const override { return name; }
36
1
    bool is_variadic() const override { return false; }
37
0
    size_t get_number_of_arguments() const override { return 2; }
38
39
0
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
40
0
        DCHECK(arguments[0]->get_primitive_type() == TYPE_ARRAY) << arguments[0]->get_name();
41
0
        DCHECK(arguments[1]->get_primitive_type() == TYPE_ARRAY) << arguments[1]->get_name();
42
0
        auto left_nested_type = remove_nullable(
43
0
                assert_cast<const DataTypeArray&>(*(arguments[0])).get_nested_type());
44
0
        auto right_nested_type = remove_nullable(
45
0
                assert_cast<const DataTypeArray&>(*(arguments[1])).get_nested_type());
46
0
        DCHECK(left_nested_type->equals_ignore_precision(*right_nested_type))
47
0
                << "data type " << arguments[0]->get_name() << " not equal with "
48
0
                << arguments[1]->get_name();
49
0
        return Impl::get_return_type(arguments);
50
0
    }
51
52
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
53
0
                        uint32_t result, size_t input_rows_count) const override {
54
0
        const auto& [left_column, left_const] =
55
0
                unpack_if_const(block.get_by_position(arguments[0]).column);
56
0
        const auto& [right_column, right_const] =
57
0
                unpack_if_const(block.get_by_position(arguments[1]).column);
58
59
        // extract array column
60
0
        ColumnArrayExecutionData left_data;
61
0
        ColumnArrayExecutionData right_data;
62
0
        ColumnPtr res_ptr = nullptr;
63
0
        if (extract_column_array_info(*left_column, left_data) &&
64
0
            extract_column_array_info(*right_column, right_data) &&
65
0
            Impl::execute(res_ptr, left_data, right_data, left_const, right_const) ==
66
0
                    Status::OK()) {
67
0
            block.replace_by_position(result, std::move(res_ptr));
68
0
            return Status::OK();
69
0
        }
70
0
        return Status::RuntimeError(
71
0
                fmt::format("execute failed, unsupported types for function {}({}, {})", get_name(),
72
0
                            block.get_by_position(arguments[0]).type->get_name(),
73
0
                            block.get_by_position(arguments[1]).type->get_name()));
74
0
    }
75
};
76
77
} // namespace doris