Kùzu C++ API
Loading...
Searching...
No Matches
ternary_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
9 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename OP>
10 static inline void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result,
11 void* /*aValueVector*/, void* /*resultValueVector*/, void* /*dataPtr*/) {
12 OP::operation(a, b, c, result);
13 }
14};
15
17 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename OP>
18 static inline void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result,
19 void* /*aValueVector*/, void* resultValueVector, void* /*dataPtr*/) {
20 OP::operation(a, b, c, result, *(common::ValueVector*)resultValueVector);
21 }
22};
23
25 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename OP>
26 static inline void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result,
27 void* /*aValueVector*/, void* resultValueVector, void* dataPtr) {
28 OP::operation(a, b, c, result, *(common::ValueVector*)resultValueVector, dataPtr);
29 }
30};
31
33 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename OP>
34 static inline void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result,
35 void* aValueVector, void* resultValueVector, void* /*dataPtr*/) {
36 OP::operation(a, b, c, result, *(common::ValueVector*)aValueVector,
37 *(common::ValueVector*)resultValueVector);
38 }
39};
40
42 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename OP>
43 static inline void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result,
44 void* /*aValueVector*/, void* /*resultValueVector*/, void* dataPtr) {
45 OP::operation(a, b, c, result, dataPtr);
46 }
47};
48
50 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
51 typename OP_WRAPPER>
53 common::ValueVector& c, common::ValueVector& result, uint64_t aPos, uint64_t bPos,
54 uint64_t cPos, uint64_t resPos, void* dataPtr) {
55 auto resValues = (RESULT_TYPE*)result.getData();
56 OP_WRAPPER::template operation<A_TYPE, B_TYPE, C_TYPE, RESULT_TYPE, FUNC>(
57 ((A_TYPE*)a.getData())[aPos], ((B_TYPE*)b.getData())[bPos],
58 ((C_TYPE*)c.getData())[cPos], resValues[resPos], (void*)&a, (void*)&result, dataPtr);
59 }
60
61 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
62 typename OP_WRAPPER>
64 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
65 auto aPos = a.state->getSelVector()[0];
66 auto bPos = b.state->getSelVector()[0];
67 auto cPos = c.state->getSelVector()[0];
68 auto resPos = result.state->getSelVector()[0];
69 result.setNull(resPos, a.isNull(aPos) || b.isNull(bPos) || c.isNull(cPos));
70 if (!result.isNull(resPos)) {
72 aPos, bPos, cPos, resPos, dataPtr);
73 }
74 }
75
76 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
77 typename OP_WRAPPER>
79 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
80 auto aPos = a.state->getSelVector()[0];
81 auto bPos = b.state->getSelVector()[0];
82 auto& cSelVector = c.state->getSelVector();
83 if (a.isNull(aPos) || b.isNull(bPos)) {
84 result.setAllNull();
85 } else if (c.hasNoNullsGuarantee()) {
86 if (cSelVector.isUnfiltered()) {
87 for (auto i = 0u; i < cSelVector.getSelSize(); ++i) {
89 result, aPos, bPos, i, i, dataPtr);
90 }
91 } else {
92 for (auto i = 0u; i < cSelVector.getSelSize(); ++i) {
93 auto pos = cSelVector[i];
95 result, aPos, bPos, pos, pos, dataPtr);
96 }
97 }
98 } else {
99 if (cSelVector.isUnfiltered()) {
100 for (auto i = 0u; i < cSelVector.getSelSize(); ++i) {
101 result.setNull(i, c.isNull(i));
102 if (!result.isNull(i)) {
104 c, result, aPos, bPos, i, i, dataPtr);
105 }
106 }
107 } else {
108 for (auto i = 0u; i < cSelVector.getSelSize(); ++i) {
109 auto pos = cSelVector[i];
110 result.setNull(pos, c.isNull(pos));
111 if (!result.isNull(pos)) {
113 c, result, aPos, bPos, pos, pos, dataPtr);
114 }
115 }
116 }
117 }
118 }
119
120 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
121 typename OP_WRAPPER>
123 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
124 KU_ASSERT(b.state == c.state);
125 auto aPos = a.state->getSelVector()[0];
126 auto& bSelVector = b.state->getSelVector();
127 if (a.isNull(aPos)) {
128 result.setAllNull();
129 } else if (b.hasNoNullsGuarantee() && c.hasNoNullsGuarantee()) {
130 if (bSelVector.isUnfiltered()) {
131 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
133 result, aPos, i, i, i, dataPtr);
134 }
135 } else {
136 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
137 auto pos = bSelVector[i];
139 result, aPos, pos, pos, pos, dataPtr);
140 }
141 }
142 } else {
143 if (bSelVector.isUnfiltered()) {
144 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
145 result.setNull(i, b.isNull(i) || c.isNull(i));
146 if (!result.isNull(i)) {
148 c, result, aPos, i, i, i, dataPtr);
149 }
150 }
151 } else {
152 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
153 auto pos = bSelVector[i];
154 result.setNull(pos, b.isNull(pos) || c.isNull(pos));
155 if (!result.isNull(pos)) {
157 c, result, aPos, pos, pos, pos, dataPtr);
158 }
159 }
160 }
161 }
162 }
163
164 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
165 typename OP_WRAPPER>
167 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
168 auto aPos = a.state->getSelVector()[0];
169 auto cPos = c.state->getSelVector()[0];
170 auto& bSelVector = b.state->getSelVector();
171 if (a.isNull(aPos) || c.isNull(cPos)) {
172 result.setAllNull();
173 } else if (b.hasNoNullsGuarantee()) {
174 if (bSelVector.isUnfiltered()) {
175 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
177 result, aPos, i, cPos, i, dataPtr);
178 }
179 } else {
180 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
181 auto pos = bSelVector[i];
183 result, aPos, pos, cPos, pos, dataPtr);
184 }
185 }
186 } else {
187 if (bSelVector.isUnfiltered()) {
188 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
189 result.setNull(i, b.isNull(i));
190 if (!result.isNull(i)) {
192 c, result, aPos, i, cPos, i, dataPtr);
193 }
194 }
195 } else {
196 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
197 auto pos = bSelVector[i];
198 result.setNull(pos, b.isNull(pos));
199 if (!result.isNull(pos)) {
201 c, result, aPos, pos, cPos, pos, dataPtr);
202 }
203 }
204 }
205 }
206 }
207
208 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
209 typename OP_WRAPPER>
211 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
212 KU_ASSERT(a.state == b.state && b.state == c.state);
213 auto& aSelVector = a.state->getSelVector();
215 if (aSelVector.isUnfiltered()) {
216 for (uint64_t i = 0; i < aSelVector.getSelSize(); i++) {
218 result, i, i, i, i, dataPtr);
219 }
220 } else {
221 for (uint64_t i = 0; i < aSelVector.getSelSize(); i++) {
222 auto pos = aSelVector[i];
224 result, pos, pos, pos, pos, dataPtr);
225 }
226 }
227 } else {
228 if (aSelVector.isUnfiltered()) {
229 for (uint64_t i = 0; i < aSelVector.getSelSize(); i++) {
230 result.setNull(i, a.isNull(i) || b.isNull(i) || c.isNull(i));
231 if (!result.isNull(i)) {
233 c, result, i, i, i, i, dataPtr);
234 }
235 }
236 } else {
237 for (uint64_t i = 0; i < aSelVector.getSelSize(); i++) {
238 auto pos = aSelVector[i];
239 result.setNull(pos, a.isNull(pos) || b.isNull(pos) || c.isNull(pos));
240 if (!result.isNull(pos)) {
242 c, result, pos, pos, pos, pos, dataPtr);
243 }
244 }
245 }
246 }
247 }
248
249 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
250 typename OP_WRAPPER>
252 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
253 auto bPos = b.state->getSelVector()[0];
254 auto cPos = c.state->getSelVector()[0];
255 auto& aSelVector = a.state->getSelVector();
256 if (b.isNull(bPos) || c.isNull(cPos)) {
257 result.setAllNull();
258 } else if (a.hasNoNullsGuarantee()) {
259 if (aSelVector.isUnfiltered()) {
260 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
262 result, i, bPos, cPos, i, dataPtr);
263 }
264 } else {
265 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
266 auto pos = aSelVector[i];
268 result, pos, bPos, cPos, pos, dataPtr);
269 }
270 }
271 } else {
272 if (aSelVector.isUnfiltered()) {
273 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
274 result.setNull(i, a.isNull(i));
275 if (!result.isNull(i)) {
277 c, result, i, bPos, cPos, i, dataPtr);
278 }
279 }
280 } else {
281 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
282 auto pos = aSelVector[i];
283 result.setNull(pos, a.isNull(pos));
284 if (!result.isNull(pos)) {
286 c, result, pos, bPos, cPos, pos, dataPtr);
287 }
288 }
289 }
290 }
291 }
292
293 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
294 typename OP_WRAPPER>
296 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
297 KU_ASSERT(a.state == c.state);
298 auto& aSelVector = a.state->getSelVector();
299 auto bPos = b.state->getSelVector()[0];
300 if (b.isNull(bPos)) {
301 result.setAllNull();
302 } else if (a.hasNoNullsGuarantee() && c.hasNoNullsGuarantee()) {
303 if (aSelVector.isUnfiltered()) {
304 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
306 result, i, bPos, i, i, dataPtr);
307 }
308 } else {
309 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
310 auto pos = aSelVector[i];
312 result, pos, bPos, pos, pos, dataPtr);
313 }
314 }
315 } else {
316 if (aSelVector.isUnfiltered()) {
317 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
318 result.setNull(i, a.isNull(i) || c.isNull(i));
319 if (!result.isNull(i)) {
321 c, result, i, bPos, i, i, dataPtr);
322 }
323 }
324 } else {
325 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
326 auto pos = b.state->getSelVector()[i];
327 result.setNull(pos, a.isNull(pos) || c.isNull(pos));
328 if (!result.isNull(pos)) {
330 c, result, pos, bPos, pos, pos, dataPtr);
331 }
332 }
333 }
334 }
335 }
336
337 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
338 typename OP_WRAPPER>
340 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
341 KU_ASSERT(a.state == b.state);
342 auto& aSelVector = a.state->getSelVector();
343 auto cPos = c.state->getSelVector()[0];
344 if (c.isNull(cPos)) {
345 result.setAllNull();
346 } else if (a.hasNoNullsGuarantee() && b.hasNoNullsGuarantee()) {
347 if (aSelVector.isUnfiltered()) {
348 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
350 result, i, i, cPos, i, dataPtr);
351 }
352 } else {
353 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
354 auto pos = aSelVector[i];
356 result, pos, pos, cPos, pos, dataPtr);
357 }
358 }
359 } else {
360 if (aSelVector.isUnfiltered()) {
361 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
362 result.setNull(i, a.isNull(i) || b.isNull(i));
363 if (!result.isNull(i)) {
365 c, result, i, i, cPos, i, dataPtr);
366 }
367 }
368 } else {
369 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
370 auto pos = aSelVector[i];
371 result.setNull(pos, a.isNull(pos) || b.isNull(pos));
372 if (!result.isNull(pos)) {
374 c, result, pos, pos, cPos, pos, dataPtr);
375 }
376 }
377 }
378 }
379 }
380
381 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
382 typename OP_WRAPPER>
384 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
385 result.resetAuxiliaryBuffer();
386 if (a.state->isFlat() && b.state->isFlat() && c.state->isFlat()) {
388 dataPtr);
389 } else if (a.state->isFlat() && b.state->isFlat() && !c.state->isFlat()) {
391 result, dataPtr);
392 } else if (a.state->isFlat() && !b.state->isFlat() && !c.state->isFlat()) {
394 result, dataPtr);
395 } else if (a.state->isFlat() && !b.state->isFlat() && c.state->isFlat()) {
397 result, dataPtr);
398 } else if (!a.state->isFlat() && !b.state->isFlat() && !c.state->isFlat()) {
400 dataPtr);
401 } else if (!a.state->isFlat() && !b.state->isFlat() && c.state->isFlat()) {
403 result, dataPtr);
404 } else if (!a.state->isFlat() && b.state->isFlat() && c.state->isFlat()) {
406 result, dataPtr);
407 } else if (!a.state->isFlat() && b.state->isFlat() && !c.state->isFlat()) {
409 result, dataPtr);
410 } else {
411 KU_ASSERT(false);
412 }
413 }
414
415 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
421
422 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
428
429 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
435
436 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
442
443 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
449};
450
451} // namespace function
452} // namespace kuzu
#define KU_ASSERT(condition)
Definition assert.h:19
Definition value_vector.h:21
uint8_t * getData() const
Definition value_vector.h:111
uint8_t isNull(uint32_t pos) const
Definition value_vector.h:76
bool hasNoNullsGuarantee() const
Definition value_vector.h:70
void setAllNull()
Definition value_vector.h:67
void setNull(uint32_t pos, bool isNull)
std::shared_ptr< DataChunkState > state
Definition value_vector.h:134
Definition array_utils.h:7
Definition ternary_function_executor.h:49
static void executeAllUnFlat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:210
static void executeSwitch(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:383
static void executeString(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result)
Definition ternary_function_executor.h:423
static void executeOnValue(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, uint64_t aPos, uint64_t bPos, uint64_t cPos, uint64_t resPos, void *dataPtr)
Definition ternary_function_executor.h:52
static void executeFlatFlatUnflat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:78
static void executeListStruct(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result)
Definition ternary_function_executor.h:437
static void executeUnflatFlatFlat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:251
static void executeUDF(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:444
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
static void executeFlatUnflatFlat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:166
static void executeAllFlat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:63
static void executeUnflatUnFlatFlat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:339
static void executeUnflatFlatUnflat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:295
static void executeFlatUnflatUnflat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:122
Definition ternary_function_executor.h:8
static void operation(A_TYPE &a, B_TYPE &b, C_TYPE &c, RESULT_TYPE &result, void *, void *, void *)
Definition ternary_function_executor.h:10
Definition ternary_function_executor.h:32
static void operation(A_TYPE &a, B_TYPE &b, C_TYPE &c, RESULT_TYPE &result, void *aValueVector, void *resultValueVector, void *)
Definition ternary_function_executor.h:34
Definition ternary_function_executor.h:24
static void operation(A_TYPE &a, B_TYPE &b, C_TYPE &c, RESULT_TYPE &result, void *, void *resultValueVector, void *dataPtr)
Definition ternary_function_executor.h:26
Definition ternary_function_executor.h:16
static void operation(A_TYPE &a, B_TYPE &b, C_TYPE &c, RESULT_TYPE &result, void *, void *resultValueVector, void *)
Definition ternary_function_executor.h:18
Definition ternary_function_executor.h:41
static void operation(A_TYPE &a, B_TYPE &b, C_TYPE &c, RESULT_TYPE &result, void *, void *, void *dataPtr)
Definition ternary_function_executor.h:43