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) {
37 return ad.is_null ? 0 : ad.length >> elem_log_sz;
41 const uint64_t row_pos,
42 const uint32_t elem_log_sz,
43 const int32_t null_val) {
48 return ad.is_null ? null_val : ad.length >> elem_log_sz;
52 const uint64_t row_pos,
53 const int32_t null_val) {
58 return ad.is_null ? null_val : 1;
62 const uint64_t row_pos) {
71 const uint64_t row_pos) {
79 #define ARRAY_AT(type) \
80 extern "C" DEVICE RUNTIME_EXPORT type array_at_##type( \
81 int8_t* chunk_iter_, const uint64_t row_pos, const uint32_t elem_idx) { \
82 ChunkIter* chunk_iter = reinterpret_cast<ChunkIter*>(chunk_iter_); \
85 ChunkIter_get_nth(chunk_iter, row_pos, &ad, &is_end); \
86 return reinterpret_cast<type*>(ad.pointer)[elem_idx]; \
98 #define VARLEN_ARRAY_AT(type) \
99 extern "C" DEVICE RUNTIME_EXPORT type varlen_array_at_##type( \
100 int8_t* chunk_iter_, const uint64_t row_pos, const uint32_t elem_idx) { \
101 ChunkIter* chunk_iter = reinterpret_cast<ChunkIter*>(chunk_iter_); \
104 ChunkIter_get_nth_varlen(chunk_iter, row_pos, &ad, &is_end); \
105 return reinterpret_cast<type*>(ad.pointer)[elem_idx]; \
108 VARLEN_ARRAY_AT(int8_t)
109 VARLEN_ARRAY_AT(int16_t)
110 VARLEN_ARRAY_AT(int32_t)
111 VARLEN_ARRAY_AT(int64_t)
112 VARLEN_ARRAY_AT(
float)
113 VARLEN_ARRAY_AT(
double)
115 #undef VARLEN_ARRAY_AT
117 #define VARLEN_NOTNULL_ARRAY_AT(type) \
118 extern "C" DEVICE RUNTIME_EXPORT type varlen_notnull_array_at_##type( \
119 int8_t* chunk_iter_, const uint64_t row_pos, const uint32_t elem_idx) { \
120 ChunkIter* chunk_iter = reinterpret_cast<ChunkIter*>(chunk_iter_); \
123 ChunkIter_get_nth_varlen_notnull(chunk_iter, row_pos, &ad, &is_end); \
124 return reinterpret_cast<type*>(ad.pointer)[elem_idx]; \
127 VARLEN_NOTNULL_ARRAY_AT(int8_t)
128 VARLEN_NOTNULL_ARRAY_AT(int16_t)
129 VARLEN_NOTNULL_ARRAY_AT(int32_t)
130 VARLEN_NOTNULL_ARRAY_AT(int64_t)
131 VARLEN_NOTNULL_ARRAY_AT(
float)
132 VARLEN_NOTNULL_ARRAY_AT(
double)
134 #undef VARLEN_NOTNULL_ARRAY_AT
136 #define ARRAY_ANY(type, needle_type, oper_name, oper) \
137 extern "C" DEVICE RUNTIME_EXPORT bool array_any_##oper_name##_##type##_##needle_type( \
138 int8_t* chunk_iter_, \
139 const uint64_t row_pos, \
140 const needle_type needle, \
141 const type null_val) { \
142 ChunkIter* chunk_iter = reinterpret_cast<ChunkIter*>(chunk_iter_); \
145 ChunkIter_get_nth(chunk_iter, row_pos, &ad, &is_end); \
146 const size_t elem_count = ad.length / sizeof(type); \
147 for (size_t i = 0; i < elem_count; ++i) { \
148 const needle_type val = reinterpret_cast<type*>(ad.pointer)[i]; \
149 if (val != null_val && val oper needle) { \
156 #define ARRAY_ALL(type, needle_type, oper_name, oper) \
157 extern "C" DEVICE RUNTIME_EXPORT bool array_all_##oper_name##_##type##_##needle_type( \
158 int8_t* chunk_iter_, \
159 const uint64_t row_pos, \
160 const needle_type needle, \
161 const type null_val) { \
162 ChunkIter* chunk_iter = reinterpret_cast<ChunkIter*>(chunk_iter_); \
165 ChunkIter_get_nth(chunk_iter, row_pos, &ad, &is_end); \
166 const size_t elem_count = ad.length / sizeof(type); \
167 for (size_t i = 0; i < elem_count; ++i) { \
168 const needle_type val = reinterpret_cast<type*>(ad.pointer)[i]; \
169 if (!(val != null_val && val oper needle)) { \
176 #define ARRAY_ALL_ANY_ALL_TYPES(oper_name, oper, needle_type) \
177 ARRAY_ANY(int8_t, needle_type, oper_name, oper) \
178 ARRAY_ALL(int8_t, needle_type, oper_name, oper) \
179 ARRAY_ANY(int16_t, needle_type, oper_name, oper) \
180 ARRAY_ALL(int16_t, needle_type, oper_name, oper) \
181 ARRAY_ANY(int32_t, needle_type, oper_name, oper) \
182 ARRAY_ALL(int32_t, needle_type, oper_name, oper) \
183 ARRAY_ANY(int64_t, needle_type, oper_name, oper) \
184 ARRAY_ALL(int64_t, needle_type, oper_name, oper) \
185 ARRAY_ANY(float, needle_type, oper_name, oper) \
186 ARRAY_ALL(float, needle_type, oper_name, oper) \
187 ARRAY_ANY(double, needle_type, oper_name, oper) \
188 ARRAY_ALL(double, needle_type, oper_name, oper)
190 ARRAY_ALL_ANY_ALL_TYPES(eq, ==, int8_t)
191 ARRAY_ALL_ANY_ALL_TYPES(ne, !=, int8_t)
192 ARRAY_ALL_ANY_ALL_TYPES(lt, <, int8_t)
193 ARRAY_ALL_ANY_ALL_TYPES(le, <=, int8_t)
194 ARRAY_ALL_ANY_ALL_TYPES(gt, >, int8_t)
195 ARRAY_ALL_ANY_ALL_TYPES(ge, >=, int8_t)
197 ARRAY_ALL_ANY_ALL_TYPES(eq, ==, int16_t)
198 ARRAY_ALL_ANY_ALL_TYPES(ne, !=, int16_t)
199 ARRAY_ALL_ANY_ALL_TYPES(lt, <, int16_t)
200 ARRAY_ALL_ANY_ALL_TYPES(le, <=, int16_t)
201 ARRAY_ALL_ANY_ALL_TYPES(gt, >, int16_t)
202 ARRAY_ALL_ANY_ALL_TYPES(ge, >=, int16_t)
204 ARRAY_ALL_ANY_ALL_TYPES(eq, ==, int32_t)
205 ARRAY_ALL_ANY_ALL_TYPES(ne, !=, int32_t)
206 ARRAY_ALL_ANY_ALL_TYPES(lt, <, int32_t)
207 ARRAY_ALL_ANY_ALL_TYPES(le, <=, int32_t)
208 ARRAY_ALL_ANY_ALL_TYPES(gt, >, int32_t)
209 ARRAY_ALL_ANY_ALL_TYPES(ge, >=, int32_t)
211 ARRAY_ALL_ANY_ALL_TYPES(eq, ==, int64_t)
212 ARRAY_ALL_ANY_ALL_TYPES(ne, !=, int64_t)
213 ARRAY_ALL_ANY_ALL_TYPES(lt, <, int64_t)
214 ARRAY_ALL_ANY_ALL_TYPES(le, <=, int64_t)
215 ARRAY_ALL_ANY_ALL_TYPES(gt, >, int64_t)
216 ARRAY_ALL_ANY_ALL_TYPES(ge, >=, int64_t)
218 ARRAY_ALL_ANY_ALL_TYPES(eq, ==,
float)
219 ARRAY_ALL_ANY_ALL_TYPES(ne, !=,
float)
220 ARRAY_ALL_ANY_ALL_TYPES(lt, <,
float)
221 ARRAY_ALL_ANY_ALL_TYPES(le, <=,
float)
222 ARRAY_ALL_ANY_ALL_TYPES(gt, >,
float)
223 ARRAY_ALL_ANY_ALL_TYPES(ge, >=,
float)
225 ARRAY_ALL_ANY_ALL_TYPES(eq, ==,
double)
226 ARRAY_ALL_ANY_ALL_TYPES(ne, !=,
double)
227 ARRAY_ALL_ANY_ALL_TYPES(lt, <,
double)
228 ARRAY_ALL_ANY_ALL_TYPES(le, <=,
double)
229 ARRAY_ALL_ANY_ALL_TYPES(gt, >,
double)
230 ARRAY_ALL_ANY_ALL_TYPES(ge, >=,
double)
232 #undef ARRAY_ALL_ANY_ALL_TYPES
236 #define ARRAY_AT_CHECKED(type) \
237 extern "C" DEVICE RUNTIME_EXPORT type array_at_##type##_checked( \
238 int8_t* chunk_iter_, \
239 const uint64_t row_pos, \
240 const int64_t elem_idx, \
241 const type null_val) { \
242 if (elem_idx <= 0) { \
245 ChunkIter* chunk_iter = reinterpret_cast<ChunkIter*>(chunk_iter_); \
248 ChunkIter_get_nth(chunk_iter, row_pos, &ad, &is_end); \
249 if (ad.is_null || static_cast<size_t>(elem_idx) > ad.length / sizeof(type)) { \
252 return reinterpret_cast<type*>(ad.pointer)[elem_idx - 1]; \
255 ARRAY_AT_CHECKED(int8_t)
256 ARRAY_AT_CHECKED(int16_t)
257 ARRAY_AT_CHECKED(int32_t)
258 ARRAY_AT_CHECKED(int64_t)
259 ARRAY_AT_CHECKED(
float)
260 ARRAY_AT_CHECKED(
double)
262 #undef ARRAY_AT_CHECKED
265 int64_t element_size) {
267 int8_t* varlen_buffer =
268 reinterpret_cast<int8_t*
>(
checked_malloc((element_count + 1) * element_size));
269 return varlen_buffer;
276 fast_fixlen_array_size(int8_t* chunk_iter_,
const uint32_t elem_log_sz) {
283 const uint64_t row_pos) {
285 auto n =
static_cast<int>(row_pos);
291 const uint64_t row_pos) {
318 const double dval{val};
319 return *
reinterpret_cast<const int64_t*
>(may_alias_ptr(&dval));
323 return *
reinterpret_cast<const int64_t*
>(may_alias_ptr(&val));
326 #define COUNT_DISTINCT_ARRAY(type) \
327 extern "C" RUNTIME_EXPORT void agg_count_distinct_array_##type( \
328 int64_t* agg, int8_t* chunk_iter_, const uint64_t row_pos, const type null_val) { \
329 ChunkIter* chunk_iter = reinterpret_cast<ChunkIter*>(chunk_iter_); \
332 ChunkIter_get_nth(chunk_iter, row_pos, &ad, &is_end); \
333 const size_t elem_count{ad.length / sizeof(type)}; \
334 for (size_t i = 0; i < elem_count; ++i) { \
335 const auto val = reinterpret_cast<type*>(ad.pointer)[i]; \
336 if (val != null_val) { \
337 reinterpret_cast<CountDistinctSet*>(*agg)->insert(elem_bitcast_##type(val)); \
342 COUNT_DISTINCT_ARRAY(int8_t)
343 COUNT_DISTINCT_ARRAY(int16_t)
344 COUNT_DISTINCT_ARRAY(int32_t)
345 COUNT_DISTINCT_ARRAY(int64_t)
346 COUNT_DISTINCT_ARRAY(
float)
347 COUNT_DISTINCT_ARRAY(
double)
349 #undef COUNT_DISTINCT_ARRAY
351 #include <functional>
352 #include <string_view>
355 const int64_t string_dict_handle);
357 template <
typename T>
358 bool array_any(int8_t*
const chunk_iter_i8,
359 uint64_t
const row_pos,
360 std::string_view
const needle_str,
361 int64_t
const string_dict_handle,
363 std::function<
bool(std::string_view, std::string_view)>
const cmp) {
368 size_t const elem_count = ad.length /
sizeof(
T);
369 for (
size_t i = 0; i < elem_count; ++i) {
370 T const val =
reinterpret_cast<T*
>(ad.pointer)[i];
371 if (val != null_val) {
381 template <
typename T>
382 bool array_all(int8_t*
const chunk_iter_i8,
383 uint64_t
const row_pos,
384 std::string_view
const needle_str,
385 int64_t
const string_dict_handle,
387 std::function<
bool(std::string_view, std::string_view)>
const cmp) {
392 size_t const elem_count = ad.length /
sizeof(
T);
393 for (
size_t i = 0; i < elem_count; ++i) {
394 T const val =
reinterpret_cast<T*
>(ad.pointer)[i];
395 if (val == null_val) {
406 #define ARRAY_STR_ANY(type, oper_name, oper) \
407 extern "C" RUNTIME_EXPORT bool array_any_##oper_name##_str_##type( \
408 int8_t* const chunk_iter_i8, \
409 uint64_t const row_pos, \
410 char const* const needle_ptr, \
411 uint32_t const needle_len, \
412 int64_t const string_dict_handle, \
413 type const null_val) { \
414 return array_any(chunk_iter_i8, \
416 std::string_view{needle_ptr, needle_len}, \
417 string_dict_handle, \
419 std::oper<std::string_view>{}); \
422 #define ARRAY_STR_ALL(type, oper_name, oper) \
423 extern "C" RUNTIME_EXPORT bool array_all_##oper_name##_str_##type( \
424 int8_t* const chunk_iter_i8, \
425 uint64_t const row_pos, \
426 char const* const needle_ptr, \
427 uint32_t const needle_len, \
428 int64_t const string_dict_handle, \
429 type const null_val) { \
430 return array_all(chunk_iter_i8, \
432 std::string_view{needle_ptr, needle_len}, \
433 string_dict_handle, \
435 std::oper<std::string_view>{}); \
438 #define ARRAY_STR_ALL_ANY_ALL_TYPES(oper_name, oper) \
439 ARRAY_STR_ANY(int8_t, oper_name, oper) \
440 ARRAY_STR_ALL(int8_t, oper_name, oper) \
441 ARRAY_STR_ANY(int16_t, oper_name, oper) \
442 ARRAY_STR_ALL(int16_t, oper_name, oper) \
443 ARRAY_STR_ANY(int32_t, oper_name, oper) \
444 ARRAY_STR_ALL(int32_t, oper_name, oper) \
445 ARRAY_STR_ANY(int64_t, oper_name, oper) \
446 ARRAY_STR_ALL(int64_t, oper_name, oper)
448 ARRAY_STR_ALL_ANY_ALL_TYPES(eq, equal_to)
449 ARRAY_STR_ALL_ANY_ALL_TYPES(ne, not_equal_to)
450 ARRAY_STR_ALL_ANY_ALL_TYPES(lt, less)
451 ARRAY_STR_ALL_ANY_ALL_TYPES(le, less_equal)
452 ARRAY_STR_ALL_ANY_ALL_TYPES(gt, greater)
453 ARRAY_STR_ALL_ANY_ALL_TYPES(ge, greater_equal)
455 #undef ARRAY_ALL_ANY_ALL_TYPES
461 #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)