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
28
29 ScalarFunction() = default;
30 ScalarFunction(std::string name, std::vector<common::LogicalTypeID> parameterTypeIDs,
32 : ScalarFunction{std::move(name), std::move(parameterTypeIDs), returnTypeID,
33 std::move(execFunc), nullptr, nullptr, nullptr} {}
34
35 ScalarFunction(std::string name, std::vector<common::LogicalTypeID> parameterTypeIDs,
38 : ScalarFunction{std::move(name), std::move(parameterTypeIDs), returnTypeID,
39 std::move(execFunc), std::move(selectFunc), nullptr, nullptr} {}
40
41 ScalarFunction(std::string name, std::vector<common::LogicalTypeID> parameterTypeIDs,
44 : ScalarFunction{std::move(name), std::move(parameterTypeIDs), returnTypeID,
45 std::move(execFunc), std::move(selectFunc), nullptr, std::move(bindFunc)} {}
46
55
56 ScalarFunction(std::string name, std::vector<common::LogicalTypeID> parameterTypeIDs,
58 : ScalarFunction{std::move(name), std::move(parameterTypeIDs), returnTypeID,
59 nullptr /* execFunc */, nullptr /* selectFunc */, bindFunc} {}
60
61 ScalarFunction(std::string name, std::vector<common::LogicalTypeID> parameterTypeIDs,
63 : ScalarFunction{std::move(name), std::move(parameterTypeIDs), returnTypeID, execFunc,
64 nullptr /* selectFunc */, bindFunc} {}
65
66 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
67 static void TernaryExecFunction(const std::vector<std::shared_ptr<common::ValueVector>>& params,
68 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
69 KU_ASSERT(params.size() == 3);
71 *params[1], *params[2], result);
72 }
73
74 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
76 const std::vector<std::shared_ptr<common::ValueVector>>& params,
77 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
78 KU_ASSERT(params.size() == 3);
80 *params[0], *params[1], *params[2], result);
81 }
82
83 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
85 const std::vector<std::shared_ptr<common::ValueVector>>& params,
86 common::ValueVector& result, void* dataPtr) {
88 *params[1], *params[2], result, dataPtr);
89 }
90
91 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC>
92 static void BinaryExecFunction(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 RESULT_TYPE, typename FUNC>
101 const std::vector<std::shared_ptr<common::ValueVector>>& params,
102 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
103 KU_ASSERT(params.size() == 2);
105 *params[1], result);
106 }
107
108 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename FUNC>
110 const std::vector<std::shared_ptr<common::ValueVector>>& params,
111 common::SelectionVector& selVector) {
112 KU_ASSERT(params.size() == 2);
114 selVector);
115 }
116
117 template<typename OPERAND_TYPE, typename RESULT_TYPE, typename FUNC,
118 typename EXECUTOR = UnaryFunctionExecutor>
119 static void UnaryExecFunction(const std::vector<std::shared_ptr<common::ValueVector>>& params,
120 common::ValueVector& result, void* dataPtr) {
121 KU_ASSERT(params.size() == 1);
122 EXECUTOR::template executeSwitch<OPERAND_TYPE, RESULT_TYPE, FUNC, UnaryFunctionWrapper>(
123 *params[0], result, 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) {
130 KU_ASSERT(params.size() == 1);
132 dataPtr);
133 }
134
135 template<typename OPERAND_TYPE, typename RESULT_TYPE, typename FUNC>
137 const std::vector<std::shared_ptr<common::ValueVector>>& params,
138 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
139 KU_ASSERT(params.size() == 1);
140 UnaryFunctionExecutor::executeSwitch<OPERAND_TYPE, RESULT_TYPE, FUNC,
141 UnaryStringFunctionWrapper>(*params[0], result, nullptr /* dataPtr */);
142 }
143
144 template<typename OPERAND_TYPE, typename RESULT_TYPE, typename FUNC,
145 typename EXECUTOR = UnaryFunctionExecutor>
147 const std::vector<std::shared_ptr<common::ValueVector>>& params,
148 common::ValueVector& result, void* dataPtr) {
149 KU_ASSERT(params.size() == 1);
150 EXECUTOR::template executeSwitch<OPERAND_TYPE, RESULT_TYPE, FUNC,
151 UnaryCastStringFunctionWrapper>(*params[0], result, dataPtr);
152 }
153
154 template<typename OPERAND_TYPE, typename RESULT_TYPE, typename FUNC,
155 typename EXECUTOR = UnaryFunctionExecutor>
157 const std::vector<std::shared_ptr<common::ValueVector>>& params,
158 common::ValueVector& result, void* dataPtr) {
159 KU_ASSERT(params.size() == 1);
160 EXECUTOR::template executeSwitch<OPERAND_TYPE, RESULT_TYPE, FUNC, UnaryCastFunctionWrapper>(
161 *params[0], result, dataPtr);
162 }
163
164 template<typename OPERAND_TYPE, typename RESULT_TYPE, typename FUNC>
166 const std::vector<std::shared_ptr<common::ValueVector>>& params,
167 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
168 KU_ASSERT(params.size() == 1);
169 UnaryFunctionExecutor::executeSwitch<OPERAND_TYPE, RESULT_TYPE, FUNC,
170 UnaryNestedTypeFunctionWrapper>(*params[0], result, nullptr /* dataPtr */);
171 }
172
173 template<typename OPERAND_TYPE, typename RESULT_TYPE, typename FUNC>
175 const std::vector<std::shared_ptr<common::ValueVector>>& params,
176 common::ValueVector& result, void* dataPtr) {
177 KU_ASSERT(params.size() == 1);
178 UnaryFunctionExecutor::executeSwitch<OPERAND_TYPE, RESULT_TYPE, FUNC,
179 UnaryStructFunctionWrapper>(*params[0], result, dataPtr);
180 }
181
182 template<typename RESULT_TYPE, typename FUNC>
183 static void NullaryExecFunction(const std::vector<std::shared_ptr<common::ValueVector>>& params,
184 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
185 KU_ASSERT(params.empty());
186 (void)params;
188 }
189
190 template<typename RESULT_TYPE, typename FUNC>
192 const std::vector<std::shared_ptr<common::ValueVector>>& params,
193 common::ValueVector& result, void* dataPtr) {
194 KU_ASSERT(params.empty());
195 (void)params;
197 }
198
199 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
201 const std::vector<std::shared_ptr<common::ValueVector>>& params,
202 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
203 KU_ASSERT(params.size() == 3);
205 *params[0], *params[1], *params[2], result);
206 }
207
208 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC>
210 const std::vector<std::shared_ptr<common::ValueVector>>& params,
211 common::ValueVector& result, void* /*dataPtr*/ = nullptr) {
212 KU_ASSERT(params.size() == 2);
214 *params[0], *params[1], result);
215 }
216
217 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC>
219 const std::vector<std::shared_ptr<common::ValueVector>>& params,
220 common::ValueVector& result, void* dataPtr) {
221 KU_ASSERT(params.size() == 2);
223 *params[0], *params[1], result, dataPtr);
224 }
225
226 virtual std::unique_ptr<ScalarFunction> copy() const {
227 return std::make_unique<ScalarFunction>(*this);
228 }
229};
230
231} // namespace function
232} // namespace kuzu
#define KU_ASSERT(condition)
Definition assert.h:19
Definition sel_vector.h:12
Definition value_vector.h:20
LogicalTypeID
Definition types.h:167
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 array_utils.h:7
static void executeListStruct(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result)
Definition binary_function_executor.h:214
static bool select(common::ValueVector &left, common::ValueVector &right, common::SelectionVector &selVector)
Definition binary_function_executor.h:368
static void execute(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result)
Definition binary_function_executor.h:200
static void executeMapCreation(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result, void *dataPtr)
Definition binary_function_executor.h:221
static void executeString(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result)
Definition binary_function_executor.h:207
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:200
static void NullaryAuxilaryExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *dataPtr)
Definition scalar_function.h:191
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:35
static void UnaryCastStringExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *dataPtr)
Definition scalar_function.h:146
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:41
static void UnaryStringExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:136
static void UnarySequenceExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *dataPtr)
Definition scalar_function.h:127
static void TernaryExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:67
static void BinaryExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:92
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:47
static void UnaryExecNestedTypeFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:165
static void TernaryStringExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:75
static void BinaryExecListStructFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:209
ScalarFunction(std::string name, std::vector< common::LogicalTypeID > parameterTypeIDs, common::LogicalTypeID returnTypeID, scalar_func_exec_t execFunc)
Definition scalar_function.h:30
static void UnaryExecStructFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *dataPtr)
Definition scalar_function.h:174
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:56
static void TernaryRegexExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *dataPtr)
Definition scalar_function.h:84
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:100
virtual std::unique_ptr< ScalarFunction > copy() const
Definition scalar_function.h:226
static bool BinarySelectFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::SelectionVector &selVector)
Definition scalar_function.h:109
static void BinaryExecMapCreationFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *dataPtr)
Definition scalar_function.h:218
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:61
static void NullaryExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *=nullptr)
Definition scalar_function.h:183
static void UnaryExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *dataPtr)
Definition scalar_function.h:119
static void UnaryCastExecFunction(const std::vector< std::shared_ptr< common::ValueVector > > &params, common::ValueVector &result, void *dataPtr)
Definition scalar_function.h:156
scalar_func_select_t selectFunc
Definition scalar_function.h:26
common::LogicalTypeID returnTypeID
Definition function.h:89
scalar_bind_func bindFunc
Definition function.h:90
static void executeString(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result)
Definition ternary_function_executor.h:423
static void executeListStruct(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result)
Definition ternary_function_executor.h:437
static void executeRegex(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:430
static void execute(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result)
Definition ternary_function_executor.h:416
Definition unary_function_executor.h:55
Definition unary_function_executor.h:102
static void executeSwitch(common::ValueVector &operand, common::ValueVector &result, void *dataPtr)
Definition unary_function_executor.h:111
static void executeSequence(common::ValueVector &operand, common::ValueVector &result, void *dataPtr)
Definition unary_function_executor.h:174
Definition unary_function_executor.h:69
Definition unary_function_executor.h:35
Definition unary_function_executor.h:46