Kùzu C++ API
Loading...
Searching...
No Matches
binary_function_executor.h
Go to the documentation of this file.
1#pragma once
2
3#include "value_vector.h"
4
5namespace kuzu {
6namespace function {
7
14 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename OP>
15 static inline void operation(LEFT_TYPE& left, RIGHT_TYPE& right, RESULT_TYPE& result,
16 common::ValueVector* /*leftValueVector*/, common::ValueVector* /*rightValueVector*/,
17 common::ValueVector* /*resultValueVector*/, uint64_t /*resultPos*/, void* /*dataPtr*/) {
18 OP::operation(left, right, result);
19 }
20};
21
23 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename OP>
24 static void operation(LEFT_TYPE& left, RIGHT_TYPE& right, RESULT_TYPE& result,
25 common::ValueVector* leftValueVector, common::ValueVector* rightValueVector,
26 common::ValueVector* resultValueVector, uint64_t /*resultPos*/, void* /*dataPtr*/) {
27 OP::operation(left, right, result, *leftValueVector, *rightValueVector, *resultValueVector);
28 }
29};
30
32 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename OP>
33 static void operation(LEFT_TYPE& left, RIGHT_TYPE& right, RESULT_TYPE& result,
34 common::ValueVector* leftValueVector, common::ValueVector* rightValueVector,
35 common::ValueVector* resultValueVector, uint64_t /*resultPos*/, void* dataPtr) {
36 OP::operation(left, right, result, *leftValueVector, *rightValueVector, *resultValueVector,
37 dataPtr);
38 }
39};
40
42 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename OP>
43 static inline void operation(LEFT_TYPE& left, RIGHT_TYPE& right, RESULT_TYPE& result,
44 common::ValueVector* leftValueVector, common::ValueVector* rightValueVector,
45 common::ValueVector* resultValueVector, uint64_t resultPos, void* /*dataPtr*/) {
46 OP::operation(left, right, result, *leftValueVector, *rightValueVector, *resultValueVector,
47 resultPos);
48 }
49};
50
52 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename OP>
53 static inline void operation(LEFT_TYPE& left, RIGHT_TYPE& right, RESULT_TYPE& result,
54 common::ValueVector* /*leftValueVector*/, common::ValueVector* /*rightValueVector*/,
55 common::ValueVector* resultValueVector, uint64_t /*resultPos*/, void* /*dataPtr*/) {
56 OP::operation(left, right, result, *resultValueVector);
57 }
58};
59
61 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename OP>
62 static inline void operation(LEFT_TYPE& left, RIGHT_TYPE& right, RESULT_TYPE& result,
63 common::ValueVector* leftValueVector, common::ValueVector* rightValueVector,
64 common::ValueVector* /*resultValueVector*/, uint64_t /*resultPos*/, void* /*dataPtr*/) {
65 OP::operation(left, right, result, leftValueVector, rightValueVector);
66 }
67};
68
70 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename OP>
71 static inline void operation(LEFT_TYPE& left, RIGHT_TYPE& right, RESULT_TYPE& result,
72 common::ValueVector* /*leftValueVector*/, common::ValueVector* /*rightValueVector*/,
73 common::ValueVector* /*resultValueVector*/, uint64_t /*resultPos*/, void* dataPtr) {
74 OP::operation(left, right, result, dataPtr);
75 }
76};
77
79 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC,
80 typename OP_WRAPPER>
81 static inline void executeOnValue(common::ValueVector& left, common::ValueVector& right,
82 common::ValueVector& resultValueVector, uint64_t lPos, uint64_t rPos, uint64_t resPos,
83 void* dataPtr) {
84 OP_WRAPPER::template operation<LEFT_TYPE, RIGHT_TYPE, RESULT_TYPE, FUNC>(
85 ((LEFT_TYPE*)left.getData())[lPos], ((RIGHT_TYPE*)right.getData())[rPos],
86 ((RESULT_TYPE*)resultValueVector.getData())[resPos], &left, &right, &resultValueVector,
87 resPos, dataPtr);
88 }
89
90 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC,
91 typename OP_WRAPPER>
93 common::ValueVector& result, void* dataPtr) {
94 auto lPos = left.state->getSelVector()[0];
95 auto rPos = right.state->getSelVector()[0];
96 auto resPos = result.state->getSelVector()[0];
97 result.setNull(resPos, left.isNull(lPos) || right.isNull(rPos));
98 if (!result.isNull(resPos)) {
100 result, lPos, rPos, resPos, dataPtr);
101 }
102 }
103
104 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC,
105 typename OP_WRAPPER>
107 common::ValueVector& result, void* dataPtr) {
108 auto lPos = left.state->getSelVector()[0];
109 auto& rightSelVector = right.state->getSelVector();
110 if (left.isNull(lPos)) {
111 result.setAllNull();
112 } else if (right.hasNoNullsGuarantee()) {
113 result.setAllNonNull();
114 rightSelVector.forEach([&](auto i) {
116 result, lPos, i, i, dataPtr);
117 });
118 } else {
119 rightSelVector.forEach([&](auto i) {
120 result.setNull(i, right.isNull(i)); // left is always not null
121 if (!result.isNull(i)) {
123 right, result, lPos, i, i, dataPtr);
124 }
125 });
126 }
127 }
128
129 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC,
130 typename OP_WRAPPER>
132 common::ValueVector& result, void* dataPtr) {
133 auto rPos = right.state->getSelVector()[0];
134 auto& leftSelVector = left.state->getSelVector();
135 if (right.isNull(rPos)) {
136 result.setAllNull();
137 } else if (left.hasNoNullsGuarantee()) {
138 result.setAllNonNull();
139 leftSelVector.forEach([&](auto i) {
141 result, i, rPos, i, dataPtr);
142 });
143 } else {
144 leftSelVector.forEach([&](auto i) {
145 result.setNull(i, left.isNull(i)); // right is always not null
146 if (!result.isNull(i)) {
148 right, result, i, rPos, i, dataPtr);
149 }
150 });
151 }
152 }
153
154 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC,
155 typename OP_WRAPPER>
157 common::ValueVector& result, void* dataPtr) {
158 KU_ASSERT(left.state == right.state);
159 auto& resultSelVector = result.state->getSelVector();
160 if (left.hasNoNullsGuarantee() && right.hasNoNullsGuarantee()) {
161 result.setAllNonNull();
162 resultSelVector.forEach([&](auto i) {
164 result, i, i, i, dataPtr);
165 });
166 } else {
167 resultSelVector.forEach([&](auto i) {
168 result.setNull(i, left.isNull(i) || right.isNull(i));
169 if (!result.isNull(i)) {
171 right, result, i, i, i, dataPtr);
172 }
173 });
174 }
175 }
176
177 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC,
178 typename OP_WRAPPER>
180 common::ValueVector& result, void* dataPtr) {
181 result.resetAuxiliaryBuffer();
182 if (left.state->isFlat() && right.state->isFlat()) {
184 result, dataPtr);
185 } else if (left.state->isFlat() && !right.state->isFlat()) {
187 result, dataPtr);
188 } else if (!left.state->isFlat() && right.state->isFlat()) {
190 result, dataPtr);
191 } else if (!left.state->isFlat() && !right.state->isFlat()) {
193 result, dataPtr);
194 } else {
195 KU_ASSERT(false);
196 }
197 }
198
199 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC>
201 common::ValueVector& result) {
203 result, nullptr /* dataPtr */);
204 }
205
206 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC>
208 common::ValueVector& result) {
210 right, result, nullptr /* dataPtr */);
211 }
212
213 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC>
219
220 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC>
226
227 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC>
233
234 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC>
240
241 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename RESULT_TYPE, typename FUNC>
243 common::ValueVector& result, void* dataPtr) {
245 right, result, dataPtr);
246 }
247
249 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename OP>
250 static inline void operation(LEFT_TYPE& left, RIGHT_TYPE& right, uint8_t& result,
251 common::ValueVector* /*leftValueVector*/, common::ValueVector* /*rightValueVector*/) {
252 OP::operation(left, right, result);
253 }
254 };
255
257 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename OP>
258 static inline void operation(LEFT_TYPE& left, RIGHT_TYPE& right, uint8_t& result,
259 common::ValueVector* leftValueVector, common::ValueVector* rightValueVector) {
260 OP::operation(left, right, result, leftValueVector, rightValueVector);
261 }
262 };
263
264 template<class LEFT_TYPE, class RIGHT_TYPE, class FUNC, typename SELECT_WRAPPER>
265 static void selectOnValue(common::ValueVector& left, common::ValueVector& right, uint64_t lPos,
266 uint64_t rPos, uint64_t resPos, uint64_t& numSelectedValues,
267 std::span<common::sel_t> selectedPositionsBuffer) {
268 uint8_t resultValue = 0;
269 SELECT_WRAPPER::template operation<LEFT_TYPE, RIGHT_TYPE, FUNC>(
270 ((LEFT_TYPE*)left.getData())[lPos], ((RIGHT_TYPE*)right.getData())[rPos], resultValue,
271 &left, &right);
272 selectedPositionsBuffer[numSelectedValues] = resPos;
273 numSelectedValues += (resultValue == true);
274 }
275
276 template<class LEFT_TYPE, class RIGHT_TYPE, class FUNC, typename SELECT_WRAPPER>
278 auto lPos = left.state->getSelVector()[0];
279 auto rPos = right.state->getSelVector()[0];
280 uint8_t resultValue = 0;
281 if (!left.isNull(lPos) && !right.isNull(rPos)) {
282 SELECT_WRAPPER::template operation<LEFT_TYPE, RIGHT_TYPE, FUNC>(
283 ((LEFT_TYPE*)left.getData())[lPos], ((RIGHT_TYPE*)right.getData())[rPos],
284 resultValue, &left, &right);
285 }
286 return resultValue == true;
287 }
288
289 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename FUNC, typename SELECT_WRAPPER>
291 common::SelectionVector& selVector) {
292 auto lPos = left.state->getSelVector()[0];
293 uint64_t numSelectedValues = 0;
294 auto selectedPositionsBuffer = selVector.getMutableBuffer();
295 auto& rightSelVector = right.state->getSelVector();
296 if (left.isNull(lPos)) {
297 return numSelectedValues;
298 } else if (right.hasNoNullsGuarantee()) {
299 rightSelVector.forEach([&](auto i) {
301 numSelectedValues, selectedPositionsBuffer);
302 });
303 } else {
304 rightSelVector.forEach([&](auto i) {
305 if (!right.isNull(i)) {
307 i, numSelectedValues, selectedPositionsBuffer);
308 }
309 });
310 }
311 selVector.setSelSize(numSelectedValues);
312 return numSelectedValues > 0;
313 }
314
315 template<typename LEFT_TYPE, typename RIGHT_TYPE, typename FUNC, typename SELECT_WRAPPER>
317 common::SelectionVector& selVector) {
318 auto rPos = right.state->getSelVector()[0];
319 uint64_t numSelectedValues = 0;
320 auto selectedPositionsBuffer = selVector.getMutableBuffer();
321 auto& leftSelVector = left.state->getSelVector();
322 if (right.isNull(rPos)) {
323 return numSelectedValues;
324 } else if (left.hasNoNullsGuarantee()) {
325 leftSelVector.forEach([&](auto i) {
327 numSelectedValues, selectedPositionsBuffer);
328 });
329 } else {
330 leftSelVector.forEach([&](auto i) {
331 if (!left.isNull(i)) {
333 i, numSelectedValues, selectedPositionsBuffer);
334 }
335 });
336 }
337 selVector.setSelSize(numSelectedValues);
338 return numSelectedValues > 0;
339 }
340
341 // Right, left, and result vectors share the same selectedPositions.
342 template<class LEFT_TYPE, class RIGHT_TYPE, class FUNC, typename SELECT_WRAPPER>
344 common::SelectionVector& selVector) {
345 uint64_t numSelectedValues = 0;
346 auto selectedPositionsBuffer = selVector.getMutableBuffer();
347 auto& leftSelVector = left.state->getSelVector();
348 if (left.hasNoNullsGuarantee() && right.hasNoNullsGuarantee()) {
349 leftSelVector.forEach([&](auto i) {
351 numSelectedValues, selectedPositionsBuffer);
352 });
353 } else {
354 leftSelVector.forEach([&](auto i) {
355 auto isNull = left.isNull(i) || right.isNull(i);
356 if (!isNull) {
358 numSelectedValues, selectedPositionsBuffer);
359 }
360 });
361 }
362 selVector.setSelSize(numSelectedValues);
363 return numSelectedValues > 0;
364 }
365
366 // BOOLEAN (AND, OR, XOR)
367 template<class LEFT_TYPE, class RIGHT_TYPE, class FUNC>
369 common::SelectionVector& selVector) {
370 if (left.state->isFlat() && right.state->isFlat()) {
372 } else if (left.state->isFlat() && !right.state->isFlat()) {
374 selVector);
375 } else if (!left.state->isFlat() && right.state->isFlat()) {
377 selVector);
378 } else {
380 selVector);
381 }
382 }
383
384 // COMPARISON (GT, GTE, LT, LTE, EQ, NEQ)
385 template<class LEFT_TYPE, class RIGHT_TYPE, class FUNC>
387 common::SelectionVector& selVector) {
388 if (left.state->isFlat() && right.state->isFlat()) {
390 right);
391 } else if (left.state->isFlat() && !right.state->isFlat()) {
393 left, right, selVector);
394 } else if (!left.state->isFlat() && right.state->isFlat()) {
396 left, right, selVector);
397 } else {
399 left, right, selVector);
400 }
401 }
402};
403
404} // namespace function
405} // namespace kuzu
#define KU_ASSERT(condition)
Definition assert.h:19
Definition sel_vector.h:12
std::span< sel_t > getMutableBuffer() const
Definition sel_vector.h:47
void setSelSize(sel_t size)
Definition sel_vector.h:69
Definition value_vector.h:20
uint8_t * getData() const
Definition value_vector.h:83
void setAllNonNull()
Definition value_vector.h:40
uint8_t isNull(uint32_t pos) const
Definition value_vector.h:48
bool hasNoNullsGuarantee() const
Definition value_vector.h:42
void setAllNull()
Definition value_vector.h:39
void setNull(uint32_t pos, bool isNull)
std::shared_ptr< DataChunkState > state
Definition value_vector.h:106
Definition array_utils.h:7
Definition binary_function_executor.h:60
static void operation(LEFT_TYPE &left, RIGHT_TYPE &right, RESULT_TYPE &result, common::ValueVector *leftValueVector, common::ValueVector *rightValueVector, common::ValueVector *, uint64_t, void *)
Definition binary_function_executor.h:62
static void operation(LEFT_TYPE &left, RIGHT_TYPE &right, uint8_t &result, common::ValueVector *leftValueVector, common::ValueVector *rightValueVector)
Definition binary_function_executor.h:258
Definition binary_function_executor.h:248
static void operation(LEFT_TYPE &left, RIGHT_TYPE &right, uint8_t &result, common::ValueVector *, common::ValueVector *)
Definition binary_function_executor.h:250
Definition binary_function_executor.h:78
static void executeListStruct(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result)
Definition binary_function_executor.h:214
static void executeUDF(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result, void *dataPtr)
Definition binary_function_executor.h:242
static void executeComparison(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result)
Definition binary_function_executor.h:235
static void executeOnValue(common::ValueVector &left, common::ValueVector &right, common::ValueVector &resultValueVector, uint64_t lPos, uint64_t rPos, uint64_t resPos, void *dataPtr)
Definition binary_function_executor.h:81
static void executeBothUnFlat(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result, void *dataPtr)
Definition binary_function_executor.h:156
static bool select(common::ValueVector &left, common::ValueVector &right, common::SelectionVector &selVector)
Definition binary_function_executor.h:368
static void executeFlatUnFlat(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result, void *dataPtr)
Definition binary_function_executor.h:106
static void selectOnValue(common::ValueVector &left, common::ValueVector &right, uint64_t lPos, uint64_t rPos, uint64_t resPos, uint64_t &numSelectedValues, std::span< common::sel_t > selectedPositionsBuffer)
Definition binary_function_executor.h:265
static void executeListExtract(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result)
Definition binary_function_executor.h:228
static bool selectComparison(common::ValueVector &left, common::ValueVector &right, common::SelectionVector &selVector)
Definition binary_function_executor.h:386
static void executeSwitch(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result, void *dataPtr)
Definition binary_function_executor.h:179
static uint64_t selectBothFlat(common::ValueVector &left, common::ValueVector &right)
Definition binary_function_executor.h:277
static void execute(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result)
Definition binary_function_executor.h:200
static void executeBothFlat(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result, void *dataPtr)
Definition binary_function_executor.h:92
static bool selectBothUnFlat(common::ValueVector &left, common::ValueVector &right, common::SelectionVector &selVector)
Definition binary_function_executor.h:343
static bool selectFlatUnFlat(common::ValueVector &left, common::ValueVector &right, common::SelectionVector &selVector)
Definition binary_function_executor.h:290
static void executeUnFlatFlat(common::ValueVector &left, common::ValueVector &right, common::ValueVector &result, void *dataPtr)
Definition binary_function_executor.h:131
static bool selectUnFlatFlat(common::ValueVector &left, common::ValueVector &right, common::SelectionVector &selVector)
Definition binary_function_executor.h:316
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
Definition binary_function_executor.h:13
static void operation(LEFT_TYPE &left, RIGHT_TYPE &right, RESULT_TYPE &result, common::ValueVector *, common::ValueVector *, common::ValueVector *, uint64_t, void *)
Definition binary_function_executor.h:15
Definition binary_function_executor.h:41
static void operation(LEFT_TYPE &left, RIGHT_TYPE &right, RESULT_TYPE &result, common::ValueVector *leftValueVector, common::ValueVector *rightValueVector, common::ValueVector *resultValueVector, uint64_t resultPos, void *)
Definition binary_function_executor.h:43
Definition binary_function_executor.h:22
static void operation(LEFT_TYPE &left, RIGHT_TYPE &right, RESULT_TYPE &result, common::ValueVector *leftValueVector, common::ValueVector *rightValueVector, common::ValueVector *resultValueVector, uint64_t, void *)
Definition binary_function_executor.h:24
Definition binary_function_executor.h:31
static void operation(LEFT_TYPE &left, RIGHT_TYPE &right, RESULT_TYPE &result, common::ValueVector *leftValueVector, common::ValueVector *rightValueVector, common::ValueVector *resultValueVector, uint64_t, void *dataPtr)
Definition binary_function_executor.h:33
Definition binary_function_executor.h:51
static void operation(LEFT_TYPE &left, RIGHT_TYPE &right, RESULT_TYPE &result, common::ValueVector *, common::ValueVector *, common::ValueVector *resultValueVector, uint64_t, void *)
Definition binary_function_executor.h:53
Definition binary_function_executor.h:69
static void operation(LEFT_TYPE &left, RIGHT_TYPE &right, RESULT_TYPE &result, common::ValueVector *, common::ValueVector *, common::ValueVector *, uint64_t, void *dataPtr)
Definition binary_function_executor.h:71