be/src/exprs/vlambda_function_call_expr.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 "common/status.h" |
21 | | #include "exprs/lambda_function/lambda_function.h" |
22 | | #include "exprs/lambda_function/lambda_function_factory.h" |
23 | | #include "exprs/vexpr.h" |
24 | | #include "exprs/vlambda_function_expr.h" |
25 | | #include "fmt/format.h" |
26 | | #include "fmt/ranges.h" |
27 | | |
28 | | namespace doris { |
29 | | |
30 | | class VLambdaFunctionCallExpr : public VExpr { |
31 | | ENABLE_FACTORY_CREATOR(VLambdaFunctionCallExpr); |
32 | | |
33 | | public: |
34 | 0 | VLambdaFunctionCallExpr(const TExprNode& node) : VExpr(node) {} |
35 | 0 | ~VLambdaFunctionCallExpr() override = default; |
36 | | |
37 | 0 | const std::string& expr_name() const override { return _expr_name; } |
38 | | |
39 | 0 | Status prepare(RuntimeState* state, const RowDescriptor& desc, VExprContext* context) override { |
40 | 0 | RETURN_IF_ERROR_OR_PREPARED(VExpr::prepare(state, desc, context)); |
41 | |
|
42 | 0 | std::vector<std::string_view> child_expr_name; |
43 | 0 | for (auto child : _children) { |
44 | 0 | child_expr_name.emplace_back(child->expr_name()); |
45 | 0 | } |
46 | 0 | _expr_name = fmt::format("{}({})", _fn.name.function_name, child_expr_name); |
47 | |
|
48 | 0 | _lambda_function = LambdaFunctionFactory::instance().get_function(_fn.name.function_name); |
49 | 0 | if (_lambda_function == nullptr) { |
50 | 0 | return Status::InternalError("Lambda Function {} is not implemented.", |
51 | 0 | _fn.name.function_name); |
52 | 0 | } |
53 | 0 | RETURN_IF_ERROR(_lambda_function->prepare(state)); |
54 | 0 | _prepare_finished = true; |
55 | 0 | return Status::OK(); |
56 | 0 | } |
57 | | |
58 | | Status open(RuntimeState* state, VExprContext* context, |
59 | 0 | FunctionContext::FunctionStateScope scope) override { |
60 | 0 | DCHECK(_prepare_finished); |
61 | 0 | RETURN_IF_ERROR(VExpr::open(state, context, scope)); |
62 | 0 | _open_finished = true; |
63 | 0 | return Status::OK(); |
64 | 0 | } |
65 | | |
66 | | Status execute_column(VExprContext* context, const Block* block, Selector* selector, |
67 | 0 | size_t count, ColumnPtr& result_column) const override { |
68 | 0 | DCHECK(_open_finished || block == nullptr); |
69 | 0 | return _lambda_function->execute(context, block, selector, count, result_column, _data_type, |
70 | 0 | _children); |
71 | 0 | } |
72 | | |
73 | 0 | std::string debug_string() const override { |
74 | 0 | std::stringstream out; |
75 | 0 | out << "VLambdaFunctionCallExpr["; |
76 | 0 | out << _expr_name; |
77 | 0 | out << "]{"; |
78 | 0 | bool first = true; |
79 | 0 | for (auto& input_expr : children()) { |
80 | 0 | if (first) { |
81 | 0 | first = false; |
82 | 0 | } else { |
83 | 0 | out << ","; |
84 | 0 | } |
85 | 0 | out << "\n" << input_expr->debug_string(); |
86 | 0 | } |
87 | 0 | out << "}"; |
88 | 0 | return out.str(); |
89 | 0 | } |
90 | | |
91 | 0 | uint64_t get_digest(uint64_t seed) const override { return 0; } |
92 | | |
93 | | private: |
94 | | std::string _expr_name; |
95 | | LambdaFunctionPtr _lambda_function; |
96 | | }; |
97 | | } // namespace doris |