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*)aValueVector,
29 *(common::ValueVector*)resultValueVector);
30 }
31};
32
34 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename OP>
35 static inline void operation(A_TYPE& a, B_TYPE& b, C_TYPE& c, RESULT_TYPE& result,
36 void* /*aValueVector*/, void* /*resultValueVector*/, void* dataPtr) {
37 OP::operation(a, b, c, result, dataPtr);
38 }
39};
40
42 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
43 typename OP_WRAPPER>
45 common::ValueVector& c, common::ValueVector& result, uint64_t aPos, uint64_t bPos,
46 uint64_t cPos, uint64_t resPos, void* dataPtr) {
47 auto resValues = (RESULT_TYPE*)result.getData();
48 OP_WRAPPER::template operation<A_TYPE, B_TYPE, C_TYPE, RESULT_TYPE, FUNC>(
49 ((A_TYPE*)a.getData())[aPos], ((B_TYPE*)b.getData())[bPos],
50 ((C_TYPE*)c.getData())[cPos], resValues[resPos], (void*)&a, (void*)&result, dataPtr);
51 }
52
53 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
54 typename OP_WRAPPER>
56 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
57 auto aPos = a.state->getSelVector()[0];
58 auto bPos = b.state->getSelVector()[0];
59 auto cPos = c.state->getSelVector()[0];
60 auto resPos = result.state->getSelVector()[0];
61 result.setNull(resPos, a.isNull(aPos) || b.isNull(bPos) || c.isNull(cPos));
62 if (!result.isNull(resPos)) {
64 aPos, bPos, cPos, resPos, dataPtr);
65 }
66 }
67
68 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
69 typename OP_WRAPPER>
71 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
72 auto aPos = a.state->getSelVector()[0];
73 auto bPos = b.state->getSelVector()[0];
74 auto& cSelVector = c.state->getSelVector();
75 if (a.isNull(aPos) || b.isNull(bPos)) {
76 result.setAllNull();
77 } else if (c.hasNoNullsGuarantee()) {
78 if (cSelVector.isUnfiltered()) {
79 for (auto i = 0u; i < cSelVector.getSelSize(); ++i) {
81 result, aPos, bPos, i, i, dataPtr);
82 }
83 } else {
84 for (auto i = 0u; i < cSelVector.getSelSize(); ++i) {
85 auto pos = cSelVector[i];
87 result, aPos, bPos, pos, pos, dataPtr);
88 }
89 }
90 } else {
91 if (cSelVector.isUnfiltered()) {
92 for (auto i = 0u; i < cSelVector.getSelSize(); ++i) {
93 result.setNull(i, c.isNull(i));
94 if (!result.isNull(i)) {
96 c, result, aPos, bPos, i, i, dataPtr);
97 }
98 }
99 } else {
100 for (auto i = 0u; i < cSelVector.getSelSize(); ++i) {
101 auto pos = cSelVector[i];
102 result.setNull(pos, c.isNull(pos));
103 if (!result.isNull(pos)) {
105 c, result, aPos, bPos, pos, pos, dataPtr);
106 }
107 }
108 }
109 }
110 }
111
112 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
113 typename OP_WRAPPER>
115 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
116 KU_ASSERT(b.state == c.state);
117 auto aPos = a.state->getSelVector()[0];
118 auto& bSelVector = b.state->getSelVector();
119 if (a.isNull(aPos)) {
120 result.setAllNull();
121 } else if (b.hasNoNullsGuarantee() && c.hasNoNullsGuarantee()) {
122 if (bSelVector.isUnfiltered()) {
123 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
125 result, aPos, i, i, i, dataPtr);
126 }
127 } else {
128 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
129 auto pos = bSelVector[i];
131 result, aPos, pos, pos, pos, dataPtr);
132 }
133 }
134 } else {
135 if (bSelVector.isUnfiltered()) {
136 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
137 result.setNull(i, b.isNull(i) || c.isNull(i));
138 if (!result.isNull(i)) {
140 c, result, aPos, i, i, i, dataPtr);
141 }
142 }
143 } else {
144 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
145 auto pos = bSelVector[i];
146 result.setNull(pos, b.isNull(pos) || c.isNull(pos));
147 if (!result.isNull(pos)) {
149 c, result, aPos, pos, pos, pos, dataPtr);
150 }
151 }
152 }
153 }
154 }
155
156 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
157 typename OP_WRAPPER>
159 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
160 auto aPos = a.state->getSelVector()[0];
161 auto cPos = c.state->getSelVector()[0];
162 auto& bSelVector = b.state->getSelVector();
163 if (a.isNull(aPos) || c.isNull(cPos)) {
164 result.setAllNull();
165 } else if (b.hasNoNullsGuarantee()) {
166 if (bSelVector.isUnfiltered()) {
167 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
169 result, aPos, i, cPos, i, dataPtr);
170 }
171 } else {
172 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
173 auto pos = bSelVector[i];
175 result, aPos, pos, cPos, pos, dataPtr);
176 }
177 }
178 } else {
179 if (bSelVector.isUnfiltered()) {
180 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
181 result.setNull(i, b.isNull(i));
182 if (!result.isNull(i)) {
184 c, result, aPos, i, cPos, i, dataPtr);
185 }
186 }
187 } else {
188 for (auto i = 0u; i < bSelVector.getSelSize(); ++i) {
189 auto pos = bSelVector[i];
190 result.setNull(pos, b.isNull(pos));
191 if (!result.isNull(pos)) {
193 c, result, aPos, pos, cPos, pos, dataPtr);
194 }
195 }
196 }
197 }
198 }
199
200 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
201 typename OP_WRAPPER>
203 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
204 KU_ASSERT(a.state == b.state && b.state == c.state);
205 auto& aSelVector = a.state->getSelVector();
207 if (aSelVector.isUnfiltered()) {
208 for (uint64_t i = 0; i < aSelVector.getSelSize(); i++) {
210 result, i, i, i, i, dataPtr);
211 }
212 } else {
213 for (uint64_t i = 0; i < aSelVector.getSelSize(); i++) {
214 auto pos = aSelVector[i];
216 result, pos, pos, pos, pos, dataPtr);
217 }
218 }
219 } else {
220 if (aSelVector.isUnfiltered()) {
221 for (uint64_t i = 0; i < aSelVector.getSelSize(); i++) {
222 result.setNull(i, a.isNull(i) || b.isNull(i) || c.isNull(i));
223 if (!result.isNull(i)) {
225 c, result, i, i, i, i, dataPtr);
226 }
227 }
228 } else {
229 for (uint64_t i = 0; i < aSelVector.getSelSize(); i++) {
230 auto pos = aSelVector[i];
231 result.setNull(pos, a.isNull(pos) || b.isNull(pos) || c.isNull(pos));
232 if (!result.isNull(pos)) {
234 c, result, pos, pos, pos, pos, dataPtr);
235 }
236 }
237 }
238 }
239 }
240
241 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
242 typename OP_WRAPPER>
244 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
245 auto bPos = b.state->getSelVector()[0];
246 auto cPos = c.state->getSelVector()[0];
247 auto& aSelVector = a.state->getSelVector();
248 if (b.isNull(bPos) || c.isNull(cPos)) {
249 result.setAllNull();
250 } else if (a.hasNoNullsGuarantee()) {
251 if (aSelVector.isUnfiltered()) {
252 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
254 result, i, bPos, cPos, i, dataPtr);
255 }
256 } else {
257 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
258 auto pos = aSelVector[i];
260 result, pos, bPos, cPos, pos, dataPtr);
261 }
262 }
263 } else {
264 if (aSelVector.isUnfiltered()) {
265 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
266 result.setNull(i, a.isNull(i));
267 if (!result.isNull(i)) {
269 c, result, i, bPos, cPos, i, dataPtr);
270 }
271 }
272 } else {
273 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
274 auto pos = aSelVector[i];
275 result.setNull(pos, a.isNull(pos));
276 if (!result.isNull(pos)) {
278 c, result, pos, bPos, cPos, pos, dataPtr);
279 }
280 }
281 }
282 }
283 }
284
285 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
286 typename OP_WRAPPER>
288 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
289 KU_ASSERT(a.state == c.state);
290 auto& aSelVector = a.state->getSelVector();
291 auto bPos = b.state->getSelVector()[0];
292 if (b.isNull(bPos)) {
293 result.setAllNull();
294 } else if (a.hasNoNullsGuarantee() && c.hasNoNullsGuarantee()) {
295 if (aSelVector.isUnfiltered()) {
296 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
298 result, i, bPos, i, i, dataPtr);
299 }
300 } else {
301 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
302 auto pos = aSelVector[i];
304 result, pos, bPos, pos, pos, dataPtr);
305 }
306 }
307 } else {
308 if (aSelVector.isUnfiltered()) {
309 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
310 result.setNull(i, a.isNull(i) || c.isNull(i));
311 if (!result.isNull(i)) {
313 c, result, i, bPos, i, i, dataPtr);
314 }
315 }
316 } else {
317 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
318 auto pos = b.state->getSelVector()[i];
319 result.setNull(pos, a.isNull(pos) || c.isNull(pos));
320 if (!result.isNull(pos)) {
322 c, result, pos, bPos, pos, pos, dataPtr);
323 }
324 }
325 }
326 }
327 }
328
329 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
330 typename OP_WRAPPER>
332 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
333 KU_ASSERT(a.state == b.state);
334 auto& aSelVector = a.state->getSelVector();
335 auto cPos = c.state->getSelVector()[0];
336 if (c.isNull(cPos)) {
337 result.setAllNull();
338 } else if (a.hasNoNullsGuarantee() && b.hasNoNullsGuarantee()) {
339 if (aSelVector.isUnfiltered()) {
340 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
342 result, i, i, cPos, i, dataPtr);
343 }
344 } else {
345 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
346 auto pos = aSelVector[i];
348 result, pos, pos, cPos, pos, dataPtr);
349 }
350 }
351 } else {
352 if (aSelVector.isUnfiltered()) {
353 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
354 result.setNull(i, a.isNull(i) || b.isNull(i));
355 if (!result.isNull(i)) {
357 c, result, i, i, cPos, i, dataPtr);
358 }
359 }
360 } else {
361 for (auto i = 0u; i < aSelVector.getSelSize(); ++i) {
362 auto pos = aSelVector[i];
363 result.setNull(pos, a.isNull(pos) || b.isNull(pos));
364 if (!result.isNull(pos)) {
366 c, result, pos, pos, cPos, pos, dataPtr);
367 }
368 }
369 }
370 }
371 }
372
373 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC,
374 typename OP_WRAPPER>
376 common::ValueVector& c, common::ValueVector& result, void* dataPtr) {
377 result.resetAuxiliaryBuffer();
378 if (a.state->isFlat() && b.state->isFlat() && c.state->isFlat()) {
380 dataPtr);
381 } else if (a.state->isFlat() && b.state->isFlat() && !c.state->isFlat()) {
383 result, dataPtr);
384 } else if (a.state->isFlat() && !b.state->isFlat() && !c.state->isFlat()) {
386 result, dataPtr);
387 } else if (a.state->isFlat() && !b.state->isFlat() && c.state->isFlat()) {
389 result, dataPtr);
390 } else if (!a.state->isFlat() && !b.state->isFlat() && !c.state->isFlat()) {
392 dataPtr);
393 } else if (!a.state->isFlat() && !b.state->isFlat() && c.state->isFlat()) {
395 result, dataPtr);
396 } else if (!a.state->isFlat() && b.state->isFlat() && c.state->isFlat()) {
398 result, dataPtr);
399 } else if (!a.state->isFlat() && b.state->isFlat() && !c.state->isFlat()) {
401 result, dataPtr);
402 } else {
403 KU_ASSERT(false);
404 }
405 }
406
407 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
413
414 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
420
421 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
427
428 template<typename A_TYPE, typename B_TYPE, typename C_TYPE, typename RESULT_TYPE, typename FUNC>
434};
435
436} // namespace function
437} // namespace kuzu
#define KU_ASSERT(condition)
Definition assert.h:19
Definition value_vector.h:20
uint8_t * getData() const
Definition value_vector.h:82
uint8_t isNull(uint32_t pos) const
Definition value_vector.h:47
bool hasNoNullsGuarantee() const
Definition value_vector.h:41
void setAllNull()
Definition value_vector.h:38
void setNull(uint32_t pos, bool isNull)
std::shared_ptr< DataChunkState > state
Definition value_vector.h:105
Definition alter_type.h:5
Definition ternary_function_executor.h:41
static void executeAllUnFlat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:202
static void executeSwitch(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:375
static void executeString(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result)
Definition ternary_function_executor.h:415
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:44
static void executeFlatFlatUnflat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:70
static void executeListStruct(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result)
Definition ternary_function_executor.h:422
static void executeUnflatFlatFlat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:243
static void executeUDF(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:429
static void execute(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result)
Definition ternary_function_executor.h:408
static void executeFlatUnflatFlat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:158
static void executeAllFlat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:55
static void executeUnflatUnFlatFlat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:331
static void executeUnflatFlatUnflat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:287
static void executeFlatUnflatUnflat(common::ValueVector &a, common::ValueVector &b, common::ValueVector &c, common::ValueVector &result, void *dataPtr)
Definition ternary_function_executor.h:114
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:24
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: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:33
static void operation(A_TYPE &a, B_TYPE &b, C_TYPE &c, RESULT_TYPE &result, void *, void *, void *dataPtr)
Definition ternary_function_executor.h:35