Coverage Report

Created: 2026-03-14 20:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/function_rpc.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 <fmt/format.h>
21
#include <gen_cpp/Types_types.h>
22
#include <stddef.h>
23
24
#include <memory>
25
#include <string>
26
#include <vector>
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/block/columns_with_type_and_name.h"
33
#include "core/data_type/data_type.h"
34
#include "core/types.h"
35
#include "exprs/function/function.h"
36
#include "exprs/function_context.h"
37
38
namespace doris {
39
class PFunctionCallRequest;
40
class PFunctionService_Stub;
41
class PValues;
42
} // namespace doris
43
44
namespace doris {
45
46
class RPCFnImpl {
47
public:
48
    RPCFnImpl(const TFunction& fn);
49
0
    ~RPCFnImpl() = default;
50
    Status vec_call(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
51
                    uint32_t result, size_t input_rows_count);
52
0
    bool available() { return _client != nullptr; }
53
54
private:
55
    Status _convert_block_to_proto(Block& block, const ColumnNumbers& arguments,
56
                                   size_t input_rows_count, PFunctionCallRequest* request);
57
    Status _convert_to_block(Block& block, const PValues& result, size_t pos);
58
59
    std::shared_ptr<PFunctionService_Stub> _client;
60
    std::string _function_name;
61
    std::string _server_addr;
62
    std::string _signature;
63
    TFunction _fn;
64
};
65
66
class RPCPreparedFunction : public IPreparedFunction {
67
public:
68
0
    ~RPCPreparedFunction() override = default;
69
70
    /// Get the main function name.
71
0
    String get_name() const override { return "RPCPreparedFunction: "; }
72
73
    Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
74
0
                   uint32_t result, size_t input_rows_count) const override {
75
0
        auto* fn = reinterpret_cast<RPCFnImpl*>(
76
0
                context->get_function_state(FunctionContext::FRAGMENT_LOCAL));
77
0
        return fn->vec_call(context, block, arguments, result, input_rows_count);
78
0
    }
79
};
80
81
class FunctionRPC : public IFunctionBase {
82
public:
83
    FunctionRPC(const TFunction& fn, const DataTypes& argument_types,
84
                const DataTypePtr& return_type);
85
86
    static FunctionBasePtr create(const TFunction& fn, const ColumnsWithTypeAndName& argument_types,
87
0
                                  const DataTypePtr& return_type) {
88
0
        DataTypes data_types(argument_types.size());
89
0
        for (size_t i = 0; i < argument_types.size(); ++i) {
90
0
            data_types[i] = argument_types[i].type;
91
0
        }
92
0
        return std::make_shared<FunctionRPC>(fn, data_types, return_type);
93
0
    }
94
95
    /// Get the main function name.
96
0
    String get_name() const override {
97
0
        return fmt::format("{}: [{}/{}]", _tfn.name.function_name, _tfn.hdfs_location,
98
0
                           _tfn.scalar_fn.symbol);
99
0
    }
100
101
0
    const DataTypes& get_argument_types() const override { return _argument_types; }
102
0
    const DataTypePtr& get_return_type() const override { return _return_type; }
103
104
    PreparedFunctionPtr prepare(FunctionContext* context, const Block& sample_block,
105
0
                                const ColumnNumbers& arguments, uint32_t result) const override {
106
0
        return std::make_shared<RPCPreparedFunction>();
107
0
    }
108
109
    Status open(FunctionContext* context, FunctionContext::FunctionStateScope scope) override;
110
111
0
    bool is_use_default_implementation_for_constants() const override { return true; }
112
113
private:
114
    DataTypes _argument_types;
115
    DataTypePtr _return_type;
116
    TFunction _tfn;
117
};
118
119
} // namespace doris