13 template<
class OPERAND_TYPE,
class RESULT_TYPE>
14 static inline void operation(OPERAND_TYPE& input, RESULT_TYPE& result,
void* udfFunc) {
15 typedef RESULT_TYPE (*unary_udf_func)(OPERAND_TYPE);
16 auto unaryUDFFunc = (unary_udf_func)udfFunc;
17 result = unaryUDFFunc(input);
22 template<
class LEFT_TYPE,
class RIGHT_TYPE,
class RESULT_TYPE>
23 static inline void operation(LEFT_TYPE& left, RIGHT_TYPE& right, RESULT_TYPE& result,
25 typedef RESULT_TYPE (*binary_udf_func)(LEFT_TYPE, RIGHT_TYPE);
26 auto binaryUDFFunc = (binary_udf_func)udfFunc;
27 result = binaryUDFFunc(left, right);
32 template<
class A_TYPE,
class B_TYPE,
class C_TYPE,
class RESULT_TYPE>
33 static inline void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result,
35 typedef RESULT_TYPE (*ternary_udf_func)(A_TYPE, B_TYPE, C_TYPE);
36 auto ternaryUDFFunc = (ternary_udf_func)udfFunc;
37 result = ternaryUDFFunc(a, b, c);
47 []<
typename T1>(T1) {
return std::is_same<T, T1>::value; });
49 []<
typename T1>(T1) {
return std::is_same<T, T1>::value; });
50 return logicalTypeMatch || physicalTypeMatch;
57 "Incompatible udf parameter/return type and templated type."};
61 template<
typename RESULT_TYPE,
typename... Args>
63 const std::vector<common::LogicalTypeID>&) {
67 template<
typename RESULT_TYPE>
69 const std::vector<common::LogicalTypeID>&) {
71 return [udfFunc](
const std::vector<std::shared_ptr<common::ValueVector>>& params,
75 auto& resultSelVector = result.state->getSelVector();
76 for (
auto i = 0u; i < resultSelVector.getSelSize(); ++i) {
77 auto resultPos = resultSelVector[i];
83 template<
typename RESULT_TYPE,
typename... Args>
85 const std::vector<common::LogicalTypeID>& ) {
89 template<
typename RESULT_TYPE,
typename OPERAND_TYPE>
91 const std::vector<common::LogicalTypeID>& parameterTypes) {
92 if (parameterTypes.size() != 1) {
94 "Expected exactly one parameter type for unary udf. Got: " +
95 std::to_string(parameterTypes.size()) +
"."};
99 [udfFunc](
const std::vector<std::shared_ptr<common::ValueVector>>& params,
103 *params[0], result, (
void*)udfFunc);
108 template<
typename RESULT_TYPE,
typename... Args>
110 const std::vector<common::LogicalTypeID>& ) {
114 template<
typename RESULT_TYPE,
typename LEFT_TYPE,
typename RIGHT_TYPE>
116 RESULT_TYPE (*udfFunc)(LEFT_TYPE, RIGHT_TYPE),
117 const std::vector<common::LogicalTypeID>& parameterTypes) {
118 if (parameterTypes.size() != 2) {
120 "Expected exactly two parameter types for binary udf. Got: " +
121 std::to_string(parameterTypes.size()) +
"."};
126 [udfFunc](
const std::vector<std::shared_ptr<common::ValueVector>>& params,
135 template<
typename RESULT_TYPE,
typename... Args>
137 const std::vector<common::LogicalTypeID>& ) {
141 template<
typename RESULT_TYPE,
typename A_TYPE,
typename B_TYPE,
typename C_TYPE>
143 RESULT_TYPE (*udfFunc)(A_TYPE, B_TYPE, C_TYPE),
144 std::vector<common::LogicalTypeID> parameterTypes) {
145 if (parameterTypes.size() != 3) {
147 "Expected exactly three parameter types for ternary udf. Got: " +
148 std::to_string(parameterTypes.size()) +
"."};
154 [udfFunc](
const std::vector<std::shared_ptr<common::ValueVector>>& params,
163 template<
typename TR,
typename... Args>
165 std::vector<common::LogicalTypeID> parameterTypes) {
166 constexpr auto numArgs =
sizeof...(Args);
183 if (std::is_same<T, bool>()) {
185 }
else if (std::is_same<T, int8_t>()) {
187 }
else if (std::is_same<T, int16_t>()) {
189 }
else if (std::is_same<T, int32_t>()) {
191 }
else if (std::is_same<T, int64_t>()) {
193 }
else if (std::is_same<T, common::int128_t>()) {
195 }
else if (std::is_same<T, uint8_t>()) {
197 }
else if (std::is_same<T, uint16_t>()) {
199 }
else if (std::is_same<T, uint32_t>()) {
201 }
else if (std::is_same<T, uint64_t>()) {
203 }
else if (std::is_same<T, float>()) {
205 }
else if (std::is_same<T, double>()) {
207 }
else if (std::is_same<T, common::ku_string_t>()) {
214 template<
typename TA>
219 template<
typename TA,
typename TB,
typename... Args>
225 template<
typename... Args>
227 std::vector<common::LogicalTypeID> parameterTypes;
228 if constexpr (
sizeof...(Args) > 0) {
231 return parameterTypes;
234 template<
typename TR,
typename... Args>
243 definitions.push_back(std::make_unique<function::ScalarFunction>(std::move(name),
244 std::move(parameterTypes), returnType, std::move(scalarExecFunc)));
248 template<
typename TR,
typename... Args>
254 template<
typename TR,
typename... Args>
257 definitions.push_back(std::make_unique<function::ScalarFunction>(std::move(name),
265 definitions.push_back(std::make_unique<function::ScalarFunction>(std::move(name),
266 std::move(parameterTypes), returnType, std::move(execFunc)));
#define KU_ASSERT(condition)
Definition assert.h:19
#define KU_UNREACHABLE
Definition assert.h:28
Definition b5808759331fe82b539a753054fdc87f.h:9
KUZU_API PhysicalTypeID getPhysicalType() const
Definition types.h:227
static auto visit(const LogicalType &dataType, Fs... funcs)
Definition type_utils.h:126
Definition value_vector.h:20
LogicalTypeID
Definition types.h:126
std::vector< std::unique_ptr< Function > > function_set
Definition function.h:43
std::function< void( const std::vector< std::shared_ptr< common::ValueVector > > &, common::ValueVector &, void *)> scalar_func_exec_t
Definition scalar_function.h:18
Definition alter_type.h:5
static void executeUDF(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result, void *dataPtr)
Definition binary_function_executor.h:296
Definition udf_function.h:21
static void operation(LEFT_TYPE &left, RIGHT_TYPE &right, RESULT_TYPE &result, void *udfFunc)
Definition udf_function.h:23
static void executeUDF(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:429
Definition udf_function.h:31
static void operation(A_TYPE &a, B_TYPE &b, C_TYPE &c, RESULT_TYPE &result, void *udfFunc)
Definition udf_function.h:33
Definition udf_function.h:41
static function_set getFunction(std::string name, TR(*udfFunc)(Args...))
Definition udf_function.h:249
static function::scalar_func_exec_t createTernaryExecFunc(RESULT_TYPE(*udfFunc)(A_TYPE, B_TYPE, C_TYPE), std::vector< common::LogicalTypeID > parameterTypes)
Definition udf_function.h:142
static function::scalar_func_exec_t createEmptyParameterExecFunc(RESULT_TYPE(*)(Args...), const std::vector< common::LogicalTypeID > &)
Definition udf_function.h:62
static function::scalar_func_exec_t createUnaryExecFunc(RESULT_TYPE(*udfFunc)(OPERAND_TYPE), const std::vector< common::LogicalTypeID > ¶meterTypes)
Definition udf_function.h:90
static scalar_func_exec_t getScalarExecFunc(TR(*udfFunc)(Args...), std::vector< common::LogicalTypeID > parameterTypes)
Definition udf_function.h:164
static void getParameterTypesRecursive(std::vector< common::LogicalTypeID > &arguments)
Definition udf_function.h:220
static function::scalar_func_exec_t createTernaryExecFunc(RESULT_TYPE(*)(Args...), const std::vector< common::LogicalTypeID > &)
Definition udf_function.h:136
static function::scalar_func_exec_t createUnaryExecFunc(RESULT_TYPE(*)(Args...), const std::vector< common::LogicalTypeID > &)
Definition udf_function.h:84
static void validateType(const common::LogicalTypeID &type)
Definition udf_function.h:54
static function_set getFunction(std::string name, TR(*udfFunc)(Args...), std::vector< common::LogicalTypeID > parameterTypes, common::LogicalTypeID returnType)
Definition udf_function.h:235
static void getParameterTypesRecursive(std::vector< common::LogicalTypeID > &arguments)
Definition udf_function.h:215
static function_set getVectorizedFunction(std::string name, scalar_func_exec_t execFunc, std::vector< common::LogicalTypeID > parameterTypes, common::LogicalTypeID returnType)
Definition udf_function.h:262
static function::scalar_func_exec_t createBinaryExecFunc(RESULT_TYPE(*)(Args...), const std::vector< common::LogicalTypeID > &)
Definition udf_function.h:109
static function::scalar_func_exec_t createEmptyParameterExecFunc(RESULT_TYPE(*udfFunc)(), const std::vector< common::LogicalTypeID > &)
Definition udf_function.h:68
static bool templateValidateType(const common::LogicalTypeID &type)
Definition udf_function.h:43
static std::vector< common::LogicalTypeID > getParameterTypes()
Definition udf_function.h:226
static function::scalar_func_exec_t createBinaryExecFunc(RESULT_TYPE(*udfFunc)(LEFT_TYPE, RIGHT_TYPE), const std::vector< common::LogicalTypeID > ¶meterTypes)
Definition udf_function.h:115
static common::LogicalTypeID getParameterType()
Definition udf_function.h:182
static function_set getVectorizedFunction(std::string name, scalar_func_exec_t execFunc)
Definition udf_function.h:255
static void executeUDF(common::ValueVector &operand, common::ValueVector &result, void *dataPtr)
Definition unary_function_executor.h:170
Definition udf_function.h:12
static void operation(OPERAND_TYPE &input, RESULT_TYPE &result, void *udfFunc)
Definition udf_function.h:14