Kùzu C++ API
Loading...
Searching...
No Matches
scalar_function.h
Go to the documentation of this file.
1#pragma once
2
5#include "function.h"
9
10namespace kuzu {
11namespace function {
12
13// Evaluate function at compile time, e.g. struct_extraction.
15 std::function<void(FunctionBindData*, const std::vector<std::shared_ptr<common::ValueVector>>&,
16 std::shared_ptr<common::ValueVector>&)>;
17// Execute function.
18using scalar_func_exec_t = std::function<void(
19 const std::vector<std::shared_ptr<common::ValueVector>>&, common::ValueVector&, void*)>;
20// Execute boolean function and write result to selection vector. Fast path for filter.
21using scalar_func_select_t = std::function<bool(
22 const std::vector<std::shared_ptr<common::ValueVector>>&, common::SelectionVector&)>;
23
24struct ScalarFunction final : public BaseScalarFunction {
28
29 ScalarFunction(std::string name, std::vector<common::LogicalTypeID> parameterTypeIDs,
31 : ScalarFunction{std::move(name), std::move(parameterTypeIDs), returnTypeID,
32 std::move(execFunc), nullptr, nullptr, nullptr} {}
33
34 ScalarFunction(std::string name, std::vector<common::LogicalTypeID> parameterTypeIDs,
37 : ScalarFunction{std::move(name), std::move(parameterTypeIDs), returnTypeID,
38 std::move(execFunc), std::move(selectFunc), nullptr, nullptr} {}
39
40 ScalarFunction(std::string name, std::vector<common::LogicalTypeID> parameterTypeIDs,
43 : ScalarFunction{std::move(name), std::move(parameterTypeIDs), returnTypeID,
44 std::move(execFunc), std::move(selectFunc), nullptr, std::move(bindFunc)} {}
45
54
55 ScalarFunction(std::string name, std::vector<common::LogicalTypeID> parameterTypeIDs,
57 : ScalarFunction{std::move(name), std::move(parameterTypeIDs), returnTypeID,
58 nullptr /* execFunc */, nullptr /* selectFunc */, bindFunc} {}
59
60 ScalarFunction(std::string name, std::vector<common::LogicalTypeID> parameterTypeIDs,
62 : ScalarFunction{std::move(name), std::move(parameterTypeIDs), returnTypeID, execFunc,
63 nullptr /* selectFunc */, bindFunc} {}
64
65 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
66 static void TernaryExecFunction(const std::vector<std::shared_ptr<common::ValueVector>>& params,
67 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
68 KU_ASSERT(params.size() == 3);
70 *params[1], *params[2], result);
71 }
72
73 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
75 const std::vector<std::shared_ptr<common::ValueVector>>& params,
76 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
77 KU_ASSERT(params.size() == 3);
79 *params[0], *params[1], *params[2], result);
80 }
81
82 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC>
83 static void BinaryExecFunction(const std::vector<std::shared_ptr<common::ValueVector>>& params,
84 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
85 KU_ASSERT(params.size() == 2);
87 *params[1], result);
88 }
89
90 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC>
92 const std::vector<std::shared_ptr<common::ValueVector>>& params,
93 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
94 KU_ASSERT(params.size() == 2);
96 *params[1], result);
97 }
98
99 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename FUNC>
101 const std::vector<std::shared_ptr<common::ValueVector>>& params,
102 common::SelectionVector& selVector) {
103 KU_ASSERT(params.size() == 2);
105 selVector);
106 }
107
108 template<typename OPERAND_TYPE, typename RESULT_TYPE, typename FUNC,
109 typename EXECUTOR = UnaryFunctionExecutor>
110 static void UnaryExecFunction(const std::vector<std::shared_ptr<common::ValueVector>>& params,
111 common::ValueVector& result, void* dataPtr) {
112 KU_ASSERT(params.size() == 1);
113 EXECUTOR::template executeSwitch<OPERAND_TYPE, RESULT_TYPE, FUNC, UnaryFunctionWrapper>(
114 *params[0], result, dataPtr);
115 }
116
117 template<typename OPERAND_TYPE, typename RESULT_TYPE, typename FUNC>
119 const std::vector<std::shared_ptr<common::ValueVector>>& params,
120 common::ValueVector& result, void* dataPtr) {
121 KU_ASSERT(params.size() == 1);
123 dataPtr);
124 }
125
126 template<typename OPERAND_TYPE, typename RESULT_TYPE, typename FUNC>
128 const std::vector<std::shared_ptr<common::ValueVector>>& params,
129 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
130 KU_ASSERT(params.size() == 1);
131 UnaryFunctionExecutor::executeSwitch<OPERAND_TYPE, RESULT_TYPE, FUNC,
132 UnaryStringFunctionWrapper>(*params[0], result, nullptr /* dataPtr */);
133 }
134
135 template<typename OPERAND_TYPE, typename RESULT_TYPE, typename FUNC,
136 typename EXECUTOR = UnaryFunctionExecutor>
138 const std::vector<std::shared_ptr<common::ValueVector>>& params,
139 common::ValueVector& result, void* dataPtr) {
140 KU_ASSERT(params.size() == 1);
141 EXECUTOR::template executeSwitch<OPERAND_TYPE, RESULT_TYPE, FUNC,
142 UnaryCastStringFunctionWrapper>(*params[0], result, dataPtr);
143 }
144
145 template<typename OPERAND_TYPE, typename RESULT_TYPE, typename FUNC,
146 typename EXECUTOR = UnaryFunctionExecutor>
148 const std::vector<std::shared_ptr<common::ValueVector>>& params,
149 common::ValueVector& result, void* dataPtr) {
150 KU_ASSERT(params.size() == 1);
151 EXECUTOR::template executeSwitch<OPERAND_TYPE, RESULT_TYPE, FUNC, UnaryCastFunctionWrapper>(
152 *params[0], result, dataPtr);
153 }
154
155 template<typename OPERAND_TYPE, typename RESULT_TYPE, typename FUNC,
156 typename EXECUTOR = UnaryFunctionExecutor>
158 const std::vector<std::shared_ptr<common::ValueVector>>& params,
159 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
160 KU_ASSERT(params.size() == 1);
161 EXECUTOR::template executeSwitch<OPERAND_TYPE, RESULT_TYPE, FUNC,
162 UnaryRdfVariantCastFunctionWrapper>(*params[0], result, nullptr /* dataPtr */);
163 }
164
165 template<typename OPERAND_TYPE, typename RESULT_TYPE, typename FUNC>
167 const std::vector<std::shared_ptr<common::ValueVector>>& params,
168 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
169 KU_ASSERT(params.size() == 1);
170 UnaryFunctionExecutor::executeSwitch<OPERAND_TYPE, RESULT_TYPE, FUNC,
171 UnaryNestedTypeFunctionWrapper>(*params[0], result, nullptr /* dataPtr */);
172 }
173
174 template<typename RESULT_TYPE, typename FUNC>
175 static void NullaryExecFunction(const std::vector<std::shared_ptr<common::ValueVector>>& params,
176 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
177 KU_ASSERT(params.empty());
178 (void)params;
180 }
181
182 template<typename RESULT_TYPE, typename FUNC>
184 const std::vector<std::shared_ptr<common::ValueVector>>& params,
185 common::ValueVector& result, void* dataPtr) {
186 KU_ASSERT(params.empty());
187 (void)params;
189 }
190
191 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
193 const std::vector<std::shared_ptr<common::ValueVector>>& params,
194 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
195 KU_ASSERT(params.size() == 3);
197 *params[0], *params[1], *params[2], result);
198 }
199
200 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC>
202 const std::vector<std::shared_ptr<common::ValueVector>>& params,
203 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
204 KU_ASSERT(params.size() == 2);
206 *params[0], *params[1], result);
207 }
208
209 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC>
211 const std::vector<std::shared_ptr<common::ValueVector>>& params,
212 common::ValueVector& result, void* dataPtr) {
213 KU_ASSERT(params.size() == 2);
215 *params[0], *params[1], result, dataPtr);
216 }
217
218 std::unique_ptr<Function> copy() const override {
219 return std::make_unique<ScalarFunction>(*this);
220 }
221};
222
223} // namespace function
224} // namespace kuzu
#define KU_ASSERT(condition)
Definition assert.h:19
Definition sel_vector.h:12
Definition value_vector.h:20
LogicalTypeID
Definition types.h:126
std::function< void(FunctionBindData *, const std::vector< std::shared_ptr< common::ValueVector > > &, std::shared_ptr< common::ValueVector > &)> scalar_func_compile_exec_t
Definition scalar_function.h:14
std::function< bool( const std::vector< std::shared_ptr< common::ValueVector > > &, common::SelectionVector &)> scalar_func_select_t
Definition scalar_function.h:21
std::function< void( const std::vector< std::shared_ptr< common::ValueVector > > &, common::ValueVector &, void *)> scalar_func_exec_t
Definition scalar_function.h:18
std::function< std::unique_ptr< FunctionBindData >(ScalarBindFuncInput bindInput)> scalar_bind_func
Definition function.h:55
Definition alter_type.h:5
Definition function.h:89
common::LogicalTypeID returnTypeID
Definition function.h:90
scalar_bind_func bindFunc
Definition function.h:91
static void executeListStruct(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result)
Definition binary_function_executor.h:268
static bool select(common::ValueVector &left, common::ValueVector &right, common::SelectionVector &selVector)
Definition binary_function_executor.h:477
static void execute(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result)
Definition binary_function_executor.h:254
static void executeMapCreation(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result, void *dataPtr)
Definition binary_function_executor.h:275
static void executeString(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result)
Definition binary_function_executor.h:261
static void execute(common::ValueVector &result)
Definition const_function_executor.h:11
Definition function.h:14
std::string name
Definition function.h:59
std::vector< common::LogicalTypeID > parameterTypeIDs
Definition function.h:60
static void execute(common::ValueVector &result, void *dataPtr)
Definition pointer_function_executor.h:10
Definition scalar_function.h:24
static void TernaryExecListStructFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:192
static void NullaryAuxilaryExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *dataPtr)
Definition scalar_function.h:183
ScalarFunction(std::string name, std::vector< common::LogicalTypeID > parameterTypeIDs, common::LogicalTypeID returnTypeID, scalar_func_exec_t execFunc, scalar_func_select_t selectFunc)
Definition scalar_function.h:34
static void UnaryCastStringExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *dataPtr)
Definition scalar_function.h:137
ScalarFunction(std::string name, std::vector< common::LogicalTypeID > parameterTypeIDs, common::LogicalTypeID returnTypeID, scalar_func_exec_t execFunc, scalar_func_select_t selectFunc, scalar_bind_func bindFunc)
Definition scalar_function.h:40
static void UnaryStringExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:127
static void UnarySequenceExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *dataPtr)
Definition scalar_function.h:118
static void TernaryExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:66
static void BinaryExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:83
ScalarFunction(std::string name, std::vector< common::LogicalTypeID > parameterTypeIDs, common::LogicalTypeID returnTypeID, scalar_func_exec_t execFunc, scalar_func_select_t selectFunc, scalar_func_compile_exec_t compileFunc, scalar_bind_func bindFunc)
Definition scalar_function.h:46
static void UnaryExecNestedTypeFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:166
static void UnaryRdfVariantCastExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:157
static void TernaryStringExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:74
static void BinaryExecListStructFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:201
ScalarFunction(std::string name, std::vector< common::LogicalTypeID > parameterTypeIDs, common::LogicalTypeID returnTypeID, scalar_func_exec_t execFunc)
Definition scalar_function.h:29
scalar_func_exec_t execFunc
Definition scalar_function.h:25
ScalarFunction(std::string name, std::vector< common::LogicalTypeID > parameterTypeIDs, common::LogicalTypeID returnTypeID, scalar_bind_func bindFunc)
Definition scalar_function.h:55
scalar_func_compile_exec_t compileFunc
Definition scalar_function.h:27
static void BinaryStringExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:91
static bool BinarySelectFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::SelectionVector &selVector)
Definition scalar_function.h:100
static void BinaryExecMapCreationFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *dataPtr)
Definition scalar_function.h:210
ScalarFunction(std::string name, std::vector< common::LogicalTypeID > parameterTypeIDs, common::LogicalTypeID returnTypeID, scalar_func_exec_t execFunc, scalar_bind_func bindFunc)
Definition scalar_function.h:60
static void NullaryExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:175
static void UnaryExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *dataPtr)
Definition scalar_function.h:110
std::unique_ptr< Function > copy() const override
Definition scalar_function.h:218
static void UnaryCastExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *dataPtr)
Definition scalar_function.h:147
scalar_func_select_t selectFunc
Definition scalar_function.h:26
static void executeString(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result)
Definition ternary_function_executor.h:415
static void executeListStruct(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result)
Definition ternary_function_executor.h:422
static void execute(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result)
Definition ternary_function_executor.h:408
Definition unary_function_executor.h:46
Definition unary_function_executor.h:105
static void executeSwitch(common::ValueVector &operand, common::ValueVector &result, void *dataPtr)
Definition unary_function_executor.h:114
static void executeSequence(common::ValueVector &operand, common::ValueVector &result, void *dataPtr)
Definition unary_function_executor.h:177
Definition unary_function_executor.h:60
Definition unary_function_executor.h:82
Definition unary_function_executor.h:35