24 #include "../Shared/funcannotations.h"
25 #include "../Utils/ChunkIter.h"
28 #ifdef EXECUTE_INCLUDE
31 const uint64_t row_pos,
32 const uint32_t elem_log_sz) {
40 return ad.is_null ? 0 : ad.length >> elem_log_sz;
44 const uint64_t row_pos,
45 const uint32_t elem_log_sz,
46 const int32_t null_val) {
51 return ad.is_null ? null_val : ad.length >> elem_log_sz;
55 const uint64_t row_pos,
56 const int32_t null_val) {
61 return ad.is_null ? null_val : 1;
65 const uint64_t row_pos) {
74 const uint64_t row_pos) {
82 #define ARRAY_AT(type) \
83 extern "C" DEVICE RUNTIME_EXPORT type array_at_##type( \
84 int8_t* chunk_iter_, const uint64_t row_pos, const uint32_t elem_idx) { \
85 ChunkIter* chunk_iter = reinterpret_cast<ChunkIter*>(chunk_iter_); \
88 ChunkIter_get_nth(chunk_iter, row_pos, &ad, &is_end); \
89 return reinterpret_cast<type*>(ad.pointer)[elem_idx]; \
101 #define VARLEN_ARRAY_AT(type) \
102 extern "C" DEVICE RUNTIME_EXPORT type varlen_array_at_##type( \
103 int8_t* chunk_iter_, const uint64_t row_pos, const uint32_t elem_idx) { \
104 ChunkIter* chunk_iter = reinterpret_cast<ChunkIter*>(chunk_iter_); \
107 ChunkIter_get_nth_varlen(chunk_iter, row_pos, &ad, &is_end); \
108 return reinterpret_cast<type*>(ad.pointer)[elem_idx]; \
111 VARLEN_ARRAY_AT(int8_t)
112 VARLEN_ARRAY_AT(int16_t)
113 VARLEN_ARRAY_AT(int32_t)
114 VARLEN_ARRAY_AT(int64_t)
115 VARLEN_ARRAY_AT(
float)
116 VARLEN_ARRAY_AT(
double)
118 #undef VARLEN_ARRAY_AT
120 #define VARLEN_NOTNULL_ARRAY_AT(type) \
121 extern "C" DEVICE RUNTIME_EXPORT type varlen_notnull_array_at_##type( \
122 int8_t* chunk_iter_, const uint64_t row_pos, const uint32_t elem_idx) { \
123 ChunkIter* chunk_iter = reinterpret_cast<ChunkIter*>(chunk_iter_); \
126 ChunkIter_get_nth_varlen_notnull(chunk_iter, row_pos, &ad, &is_end); \
127 return reinterpret_cast<type*>(ad.pointer)[elem_idx]; \
130 VARLEN_NOTNULL_ARRAY_AT(int8_t)
131 VARLEN_NOTNULL_ARRAY_AT(int16_t)
132 VARLEN_NOTNULL_ARRAY_AT(int32_t)
133 VARLEN_NOTNULL_ARRAY_AT(int64_t)
134 VARLEN_NOTNULL_ARRAY_AT(
float)
135 VARLEN_NOTNULL_ARRAY_AT(
double)
137 #undef VARLEN_NOTNULL_ARRAY_AT
139 #define ARRAY_ANY(type, needle_type, oper_name, oper) \
140 extern "C" DEVICE RUNTIME_EXPORT bool array_any_##oper_name##_##type##_##needle_type( \
141 int8_t* chunk_iter_, \
142 const uint64_t row_pos, \
143 const needle_type needle, \
144 const type null_val) { \
145 ChunkIter* chunk_iter = reinterpret_cast<ChunkIter*>(chunk_iter_); \
148 ChunkIter_get_nth(chunk_iter, row_pos, &ad, &is_end); \
149 const size_t elem_count = ad.length / sizeof(type); \
150 for (size_t i = 0; i < elem_count; ++i) { \
151 const needle_type val = reinterpret_cast<type*>(ad.pointer)[i]; \
152 if (val != null_val && val oper needle) { \
159 #define ARRAY_ALL(type, needle_type, oper_name, oper) \
160 extern "C" DEVICE RUNTIME_EXPORT bool array_all_##oper_name##_##type##_##needle_type( \
161 int8_t* chunk_iter_, \
162 const uint64_t row_pos, \
163 const needle_type needle, \
164 const type null_val) { \
165 ChunkIter* chunk_iter = reinterpret_cast<ChunkIter*>(chunk_iter_); \
168 ChunkIter_get_nth(chunk_iter, row_pos, &ad, &is_end); \
169 const size_t elem_count = ad.length / sizeof(type); \
170 for (size_t i = 0; i < elem_count; ++i) { \
171 const needle_type val = reinterpret_cast<type*>(ad.pointer)[i]; \
172 if (!(val != null_val && val oper needle)) { \
179 #define ARRAY_ALL_ANY_ALL_TYPES(oper_name, oper, needle_type) \
180 ARRAY_ANY(int8_t, needle_type, oper_name, oper) \
181 ARRAY_ALL(int8_t, needle_type, oper_name, oper) \
182 ARRAY_ANY(int16_t, needle_type, oper_name, oper) \
183 ARRAY_ALL(int16_t, needle_type, oper_name, oper) \
184 ARRAY_ANY(int32_t, needle_type, oper_name, oper) \
185 ARRAY_ALL(int32_t, needle_type, oper_name, oper) \
186 ARRAY_ANY(int64_t, needle_type, oper_name, oper) \
187 ARRAY_ALL(int64_t, needle_type, oper_name, oper) \
188 ARRAY_ANY(float, needle_type, oper_name, oper) \
189 ARRAY_ALL(float, needle_type, oper_name, oper) \
190 ARRAY_ANY(double, needle_type, oper_name, oper) \
191 ARRAY_ALL(double, needle_type, oper_name, oper)
193 ARRAY_ALL_ANY_ALL_TYPES(eq, ==, int8_t)
194 ARRAY_ALL_ANY_ALL_TYPES(ne, !=, int8_t)
195 ARRAY_ALL_ANY_ALL_TYPES(lt, <, int8_t)
196 ARRAY_ALL_ANY_ALL_TYPES(le, <=, int8_t)
197 ARRAY_ALL_ANY_ALL_TYPES(gt, >, int8_t)
198 ARRAY_ALL_ANY_ALL_TYPES(ge, >=, int8_t)
200 ARRAY_ALL_ANY_ALL_TYPES(eq, ==, int16_t)
201 ARRAY_ALL_ANY_ALL_TYPES(ne, !=, int16_t)
202 ARRAY_ALL_ANY_ALL_TYPES(lt, <, int16_t)
203 ARRAY_ALL_ANY_ALL_TYPES(le, <=, int16_t)
204 ARRAY_ALL_ANY_ALL_TYPES(gt, >, int16_t)
205 ARRAY_ALL_ANY_ALL_TYPES(ge, >=, int16_t)
207 ARRAY_ALL_ANY_ALL_TYPES(eq, ==, int32_t)
208 ARRAY_ALL_ANY_ALL_TYPES(ne, !=, int32_t)
209 ARRAY_ALL_ANY_ALL_TYPES(lt, <, int32_t)
210 ARRAY_ALL_ANY_ALL_TYPES(le, <=, int32_t)
211 ARRAY_ALL_ANY_ALL_TYPES(gt, >, int32_t)
212 ARRAY_ALL_ANY_ALL_TYPES(ge, >=, int32_t)
214 ARRAY_ALL_ANY_ALL_TYPES(eq, ==, int64_t)
215 ARRAY_ALL_ANY_ALL_TYPES(ne, !=, int64_t)
216 ARRAY_ALL_ANY_ALL_TYPES(lt, <, int64_t)
217 ARRAY_ALL_ANY_ALL_TYPES(le, <=, int64_t)
218 ARRAY_ALL_ANY_ALL_TYPES(gt, >, int64_t)
219 ARRAY_ALL_ANY_ALL_TYPES(ge, >=, int64_t)
221 ARRAY_ALL_ANY_ALL_TYPES(eq, ==,
float)
222 ARRAY_ALL_ANY_ALL_TYPES(ne, !=,
float)
223 ARRAY_ALL_ANY_ALL_TYPES(lt, <,
float)
224 ARRAY_ALL_ANY_ALL_TYPES(le, <=,
float)
225 ARRAY_ALL_ANY_ALL_TYPES(gt, >,
float)
226 ARRAY_ALL_ANY_ALL_TYPES(ge, >=,
float)
228 ARRAY_ALL_ANY_ALL_TYPES(eq, ==,
double)
229 ARRAY_ALL_ANY_ALL_TYPES(ne, !=,
double)
230 ARRAY_ALL_ANY_ALL_TYPES(lt, <,
double)
231 ARRAY_ALL_ANY_ALL_TYPES(le, <=,
double)
232 ARRAY_ALL_ANY_ALL_TYPES(gt, >,
double)
233 ARRAY_ALL_ANY_ALL_TYPES(ge, >=,
double)
235 #undef ARRAY_ALL_ANY_ALL_TYPES
239 #define ARRAY_AT_CHECKED(type) \
240 extern "C" DEVICE RUNTIME_EXPORT type array_at_##type##_checked( \
241 int8_t* chunk_iter_, \
242 const uint64_t row_pos, \
243 const int64_t elem_idx, \
244 const type null_val) { \
245 if (elem_idx <= 0) { \
248 ChunkIter* chunk_iter = reinterpret_cast<ChunkIter*>(chunk_iter_); \
251 ChunkIter_get_nth(chunk_iter, row_pos, &ad, &is_end); \
252 if (ad.is_null || static_cast<size_t>(elem_idx) > ad.length / sizeof(type)) { \
255 return reinterpret_cast<type*>(ad.pointer)[elem_idx - 1]; \
258 ARRAY_AT_CHECKED(int8_t)
259 ARRAY_AT_CHECKED(int16_t)
260 ARRAY_AT_CHECKED(int32_t)
261 ARRAY_AT_CHECKED(int64_t)
262 ARRAY_AT_CHECKED(
float)
263 ARRAY_AT_CHECKED(
double)
265 #undef ARRAY_AT_CHECKED
268 int64_t element_size) {
270 int8_t* varlen_buffer =
271 reinterpret_cast<int8_t*
>(
checked_malloc((element_count + 1) * element_size));
272 return varlen_buffer;
279 fast_fixlen_array_size(int8_t* chunk_iter_,
const uint32_t elem_log_sz) {
286 const uint64_t row_pos) {
291 auto n =
static_cast<int>(row_pos);
297 determine_fixed_array_len(int8_t* chunk_iter, int64_t valid_len) {
298 return chunk_iter ? valid_len : 0;
302 const uint64_t row_pos) {
332 const double dval{val};
333 return *
reinterpret_cast<const int64_t*
>(may_alias_ptr(&dval));
337 return *
reinterpret_cast<const int64_t*
>(may_alias_ptr(&val));
340 #define COUNT_DISTINCT_ARRAY(type) \
341 extern "C" RUNTIME_EXPORT void agg_count_distinct_array_##type( \
342 int64_t* agg, int8_t* chunk_iter_, const uint64_t row_pos, const type null_val) { \
343 ChunkIter* chunk_iter = reinterpret_cast<ChunkIter*>(chunk_iter_); \
346 ChunkIter_get_nth(chunk_iter, row_pos, &ad, &is_end); \
347 const size_t elem_count{ad.length / sizeof(type)}; \
348 for (size_t i = 0; i < elem_count; ++i) { \
349 const auto val = reinterpret_cast<type*>(ad.pointer)[i]; \
350 if (val != null_val) { \
351 reinterpret_cast<CountDistinctSet*>(*agg)->insert(elem_bitcast_##type(val)); \
356 COUNT_DISTINCT_ARRAY(int8_t)
357 COUNT_DISTINCT_ARRAY(int16_t)
358 COUNT_DISTINCT_ARRAY(int32_t)
359 COUNT_DISTINCT_ARRAY(int64_t)
360 COUNT_DISTINCT_ARRAY(
float)
361 COUNT_DISTINCT_ARRAY(
double)
363 #undef COUNT_DISTINCT_ARRAY
365 #include <functional>
366 #include <string_view>
369 const int64_t string_dict_handle);
371 template <
typename T>
372 bool array_any(int8_t*
const chunk_iter_i8,
373 uint64_t
const row_pos,
374 std::string_view
const needle_str,
375 int64_t
const string_dict_handle,
377 std::function<
bool(std::string_view, std::string_view)>
const cmp) {
382 size_t const elem_count = ad.length /
sizeof(
T);
383 for (
size_t i = 0; i < elem_count; ++i) {
384 T const val =
reinterpret_cast<T*
>(ad.pointer)[i];
385 if (val != null_val) {
395 template <
typename T>
396 bool array_all(int8_t*
const chunk_iter_i8,
397 uint64_t
const row_pos,
398 std::string_view
const needle_str,
399 int64_t
const string_dict_handle,
401 std::function<
bool(std::string_view, std::string_view)>
const cmp) {
406 size_t const elem_count = ad.length /
sizeof(
T);
407 for (
size_t i = 0; i < elem_count; ++i) {
408 T const val =
reinterpret_cast<T*
>(ad.pointer)[i];
409 if (val == null_val) {
420 #define ARRAY_STR_ANY(type, oper_name, oper) \
421 extern "C" RUNTIME_EXPORT bool array_any_##oper_name##_str_##type( \
422 int8_t* const chunk_iter_i8, \
423 uint64_t const row_pos, \
424 char const* const needle_ptr, \
425 uint32_t const needle_len, \
426 int64_t const string_dict_handle, \
427 type const null_val) { \
428 return array_any(chunk_iter_i8, \
430 std::string_view{needle_ptr, needle_len}, \
431 string_dict_handle, \
433 std::oper<std::string_view>{}); \
436 #define ARRAY_STR_ALL(type, oper_name, oper) \
437 extern "C" RUNTIME_EXPORT bool array_all_##oper_name##_str_##type( \
438 int8_t* const chunk_iter_i8, \
439 uint64_t const row_pos, \
440 char const* const needle_ptr, \
441 uint32_t const needle_len, \
442 int64_t const string_dict_handle, \
443 type const null_val) { \
444 return array_all(chunk_iter_i8, \
446 std::string_view{needle_ptr, needle_len}, \
447 string_dict_handle, \
449 std::oper<std::string_view>{}); \
452 #define ARRAY_STR_ALL_ANY_ALL_TYPES(oper_name, oper) \
453 ARRAY_STR_ANY(int8_t, oper_name, oper) \
454 ARRAY_STR_ALL(int8_t, oper_name, oper) \
455 ARRAY_STR_ANY(int16_t, oper_name, oper) \
456 ARRAY_STR_ALL(int16_t, oper_name, oper) \
457 ARRAY_STR_ANY(int32_t, oper_name, oper) \
458 ARRAY_STR_ALL(int32_t, oper_name, oper) \
459 ARRAY_STR_ANY(int64_t, oper_name, oper) \
460 ARRAY_STR_ALL(int64_t, oper_name, oper)
462 ARRAY_STR_ALL_ANY_ALL_TYPES(eq, equal_to)
463 ARRAY_STR_ALL_ANY_ALL_TYPES(ne, not_equal_to)
464 ARRAY_STR_ALL_ANY_ALL_TYPES(lt, less)
465 ARRAY_STR_ALL_ANY_ALL_TYPES(le, less_equal)
466 ARRAY_STR_ALL_ANY_ALL_TYPES(gt, greater)
467 ARRAY_STR_ALL_ANY_ALL_TYPES(ge, greater_equal)
469 #undef ARRAY_ALL_ANY_ALL_TYPES
475 #endif // EXECUTE_INCLUDE
DEVICE void ChunkIter_get_nth_point_coords(ChunkIter *it, int n, ArrayDatum *result, bool *is_end)
DEVICE void ChunkIter_get_nth(ChunkIter *it, int n, bool uncompress, VarlenDatum *result, bool *is_end)
std::conditional_t< is_cuda_compiler(), DeviceArrayDatum, HostArrayDatum > ArrayDatum
EXTENSION_NOINLINE int8_t * allocate_varlen_buffer(int64_t element_count, int64_t element_size)
void * checked_malloc(const size_t size)
std::string_view stringView() const
RUNTIME_EXPORT StringView string_decompress(const int32_t string_id, const int64_t string_dict_handle)