OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExtensionFunctionsArray.hpp
Go to the documentation of this file.
1 #include <cassert>
2 
3 #if defined(__clang__)
4 #pragma clang diagnostic push
5 #pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
6 #endif
7 
8 #ifndef __CUDACC__
9 
10 namespace {
11 
12 template <typename T>
14  Array<T> out_arr(in_arr.size() + 1);
15  for (size_t i = 0; i < in_arr.size(); i++) {
16  out_arr[i] = in_arr(i);
17  }
18  out_arr[in_arr.size()] = val;
19  return out_arr;
20 }
21 
22 // while appending boolean value to bool-type array we need to deal with its
23 // array storage carefully to correctly represent null sentinel for bool type array
25  const int8_t val) {
26  Array<bool> out_arr(in_arr.size() + 1);
27  // cast bool array storage to int8_t type to mask null elem correctly
28  auto casted_out_arr = (int8_t*)out_arr.data();
29  for (size_t i = 0; i < in_arr.size(); i++) {
30  casted_out_arr[i] = in_arr(i);
31  }
32  casted_out_arr[in_arr.size()] = val;
33  return out_arr;
34 }
35 
36 template <typename T>
38  auto sz = in_arr.size();
39  Array<T> out_arr(sz / 2, in_arr.isNull());
40  for (size_t i = 0; i < sz / 2; i++) {
41  out_arr[i] = in_arr(i);
42  }
43  return out_arr;
44 }
45 
46 template <typename T>
48  auto sz = in_arr.size();
49  Array<T> out_arr(sz - sz / 2, in_arr.isNull());
50  for (size_t i = sz / 2; i < sz; i++) {
51  out_arr[i - sz / 2] = in_arr(i);
52  }
53  return out_arr;
54 }
55 
56 } // namespace
57 
58 #endif
59 
60 #ifdef _WIN32
61 // MSVC doesn't allow extern "C" function using template type
62 // without explicit instantiation
63 template struct Array<bool>;
64 template struct Array<int8_t>;
65 template struct Array<int16_t>;
66 template struct Array<int32_t>;
67 template struct Array<int64_t>;
68 template struct Array<float>;
69 template struct Array<double>;
70 template struct Array<TextEncodingDict>;
71 #endif
72 
74  const int64_t val) {
75 #ifndef __CUDACC__
76  return array_append_impl(in_arr, val);
77 #else
78  assert(false);
79  return Array<int64_t>(0, true);
80 #endif
81 }
82 
84  const int32_t val) {
85 #ifndef __CUDACC__
86  return array_append_impl(in_arr, val);
87 #else
88  assert(false);
89  return Array<int32_t>(0, true);
90 #endif
91 }
92 
94  const int16_t val) {
95 #ifndef __CUDACC__
96  return array_append_impl(in_arr, val);
97 #else
98  assert(false);
99  return Array<int16_t>(0, true);
100 #endif
101 }
102 
104  const int8_t val) {
105 #ifndef __CUDACC__
106  return array_append_impl(in_arr, val);
107 #else
108  assert(false);
109  return Array<int8_t>(0, true);
110 #endif
111 }
112 
114  const double val) {
115 #ifndef __CUDACC__
116  return array_append_impl(in_arr, val);
117 #else
118  assert(false);
119  return Array<double>(0, true);
120 #endif
121 }
122 
124  const float val) {
125 #ifndef __CUDACC__
126  return array_append_impl(in_arr, val);
127 #else
128  assert(false);
129  return Array<float>(0, true);
130 #endif
131 }
132 
133 #ifndef __CUDACC__
135  RowFunctionManager& mgr,
136  const Array<TextEncodingDict>& in_arr,
137  const TextEncodingDict val) {
138  Array<TextEncodingDict> out_arr(in_arr.size() + 1);
139  for (size_t i = 0; i < in_arr.size(); i++) {
140  if (in_arr.isNull(i)) {
141  out_arr[i] = in_arr[i];
142  } else {
143  std::string str =
144  mgr.getString(GET_DICT_DB_ID(mgr, 0), GET_DICT_ID(mgr, 0), in_arr[i]);
146  }
147  }
148  if (val.isNull()) {
149  out_arr[in_arr.size()] = val;
150  } else {
151  std::string str = mgr.getString(GET_DICT_DB_ID(mgr, 1), GET_DICT_ID(mgr, 1), val);
152  out_arr[in_arr.size()] =
154  }
155  return out_arr;
156 }
157 #endif
158 
159 /*
160  Overloading UDFs works for types in the same SQL family. BOOLEAN
161  does not belong to NUMERIC family, hence we need to use different
162  name for boolean UDF.
163  */
164 EXTENSION_NOINLINE Array<bool> barray_append(const Array<bool>& in_arr, const bool val) {
165 #ifndef __CUDACC__
166  // we need to cast 'val' to int8_t type to represent null sentinel correctly
167  // i.e., NULL_BOOLEAN = -128
168  return barray_append_impl(in_arr, val);
169 #else
170  assert(false);
171  return Array<bool>(0, true);
172 #endif
173 }
174 
176 #ifndef __CUDACC__
177  return array_first_half_impl(in_arr);
178 #else
179  assert(false);
180  return Array<bool>(0, true);
181 #endif
182 }
183 
185 #ifndef __CUDACC__
186  return array_second_half_impl(in_arr);
187 #else
188  assert(false);
189  return Array<bool>(0, true);
190 #endif
191 }
192 
194 #ifndef __CUDACC__
195  return array_first_half_impl(in_arr);
196 #else
197  assert(false);
198  return Array<int8_t>(0, true);
199 #endif
200 }
201 
203 #ifndef __CUDACC__
204  return array_second_half_impl(in_arr);
205 #else
206  assert(false);
207  return Array<int8_t>(0, true);
208 #endif
209 }
210 
212 #ifndef __CUDACC__
213  return array_first_half_impl(in_arr);
214 #else
215  assert(false);
216  return Array<int16_t>(0, true);
217 #endif
218 }
219 
221 #ifndef __CUDACC__
222  return array_second_half_impl(in_arr);
223 #else
224  assert(false);
225  return Array<int16_t>(0, true);
226 #endif
227 }
228 
230 #ifndef __CUDACC__
231  return array_first_half_impl(in_arr);
232 #else
233  assert(false);
234  return Array<int32_t>(0, true);
235 #endif
236 }
237 
239 #ifndef __CUDACC__
240  return array_second_half_impl(in_arr);
241 #else
242  assert(false);
243  return Array<int32_t>(0, true);
244 #endif
245 }
246 
248 #ifndef __CUDACC__
249  return array_first_half_impl(in_arr);
250 #else
251  assert(false);
252  return Array<int64_t>(0, true);
253 #endif
254 }
255 
257 #ifndef __CUDACC__
258  return array_second_half_impl(in_arr);
259 #else
260  assert(false);
261  return Array<int64_t>(0, true);
262 #endif
263 }
264 
266 #ifndef __CUDACC__
267  return array_first_half_impl(in_arr);
268 #else
269  assert(false);
270  return Array<float>(0, true);
271 #endif
272 }
273 
275 #ifndef __CUDACC__
276  return array_second_half_impl(in_arr);
277 #else
278  assert(false);
279  return Array<float>(0, true);
280 #endif
281 }
282 
284 #ifndef __CUDACC__
285  return array_first_half_impl(in_arr);
286 #else
287  assert(false);
288  return Array<double>(0, true);
289 #endif
290 }
291 
293 #ifndef __CUDACC__
294  return array_second_half_impl(in_arr);
295 #else
296  assert(false);
297  return Array<double>(0, true);
298 #endif
299 }
300 
301 #ifdef _WIN32
302 template struct Array<TextEncodingDict>;
303 #endif
304 
305 #ifndef __CUDACC__
308  const Array<TextEncodingDict>& in_arr) {
310  for (size_t i = 0; i < out_arr.size(); i++) {
311  if (!out_arr.isNull(i)) {
312  std::string str =
313  mgr.getString(GET_DICT_DB_ID(mgr, 0), GET_DICT_ID(mgr, 0), out_arr[i]);
315  }
316  }
317  return out_arr;
318 }
319 
322  const Array<TextEncodingDict>& in_arr) {
324  for (size_t i = 0; i < out_arr.size(); i++) {
325  if (!out_arr.isNull(i)) {
326  std::string str =
327  mgr.getString(GET_DICT_DB_ID(mgr, 0), GET_DICT_ID(mgr, 0), out_arr[i]);
329  }
330  }
331  return out_arr;
332 }
333 #endif
334 
336  const Array<bool>& other_arr) {
337  return in_arr == other_arr;
338 }
339 
341  const Array<int8_t>& other_arr) {
342  return in_arr == other_arr;
343 }
344 
346  const Array<int16_t>& other_arr) {
347  return in_arr == other_arr;
348 }
349 
351  const Array<int32_t>& other_arr) {
352  return in_arr == other_arr;
353 }
354 
356  const Array<int64_t>& other_arr) {
357  return in_arr == other_arr;
358 }
359 
361  const Array<float>& other_arr) {
362  return in_arr == other_arr;
363 }
364 
366  const Array<double>& other_arr) {
367  return in_arr == other_arr;
368 }
369 
370 /*
371  // Requires Array<TextEncodingNone> indexing support:
372  EXTENSION_NOINLINE bool array_equal__text(const Array<TextEncodingNone>& in_arr, const
373  Array<TextEncodingNone>& other_arr) { return in_arr == other_arr;
374  }
375 */
376 
378  const Array<TextEncodingDict>& other_arr) {
379  return in_arr == other_arr;
380 }
381 
382 #if defined(__clang__)
383 #pragma clang diagnostic pop
384 #endif
EXTENSION_NOINLINE Array< float > array_second_half__f32(const Array< float > &in_arr)
EXTENSION_NOINLINE Array< TextEncodingDict > array_second_half__t32(RowFunctionManager &mgr, const Array< TextEncodingDict > &in_arr)
EXTENSION_NOINLINE Array< int16_t > array_append__1(const Array< int16_t > &in_arr, const int16_t val)
EXTENSION_NOINLINE bool array_equal__f64(const Array< double > &in_arr, const Array< double > &other_arr)
#define EXTENSION_NOINLINE
Definition: heavydbTypes.h:58
EXTENSION_NOINLINE Array< bool > array_second_half__b8(const Array< bool > &in_arr)
EXTENSION_NOINLINE Array< double > array_second_half__f64(const Array< double > &in_arr)
EXTENSION_NOINLINE Array< double > array_append__3(const Array< double > &in_arr, const double val)
EXTENSION_NOINLINE Array< TextEncodingDict > array_first_half__t32(RowFunctionManager &mgr, const Array< TextEncodingDict > &in_arr)
EXTENSION_NOINLINE Array< int8_t > array_append__2(const Array< int8_t > &in_arr, const int8_t val)
#define TRANSIENT_DICT_DB_ID
Definition: DbObjectKeys.h:25
EXTENSION_NOINLINE Array< double > array_first_half__f64(const Array< double > &in_arr)
EXTENSION_NOINLINE bool array_equal__textdict(const Array< TextEncodingDict > &in_arr, const Array< TextEncodingDict > &other_arr)
DEVICE ALWAYS_INLINE Array< T > array_second_half_impl(const Array< T > &in_arr)
#define TRANSIENT_DICT_ID
Definition: DbObjectKeys.h:24
EXTENSION_NOINLINE Array< bool > array_first_half__b8(const Array< bool > &in_arr)
DEVICE ALWAYS_INLINE Array< T > array_append_impl(const Array< T > &in_arr, T val)
#define DEVICE
EXTENSION_NOINLINE Array< int32_t > array_second_half__i32(const Array< int32_t > &in_arr)
#define GET_DICT_ID(mgr, arg_idx)
Definition: heavydbTypes.h:141
EXTENSION_NOINLINE Array< float > array_first_half__f32(const Array< float > &in_arr)
EXTENSION_NOINLINE Array< int64_t > array_first_half__i64(const Array< int64_t > &in_arr)
DEVICE ALWAYS_INLINE bool isNull() const
Definition: heavydbTypes.h:232
EXTENSION_NOINLINE Array< TextEncodingDict > tarray_append(RowFunctionManager &mgr, const Array< TextEncodingDict > &in_arr, const TextEncodingDict val)
DEVICE ALWAYS_INLINE T * data() const
Definition: heavydbTypes.h:516
EXTENSION_NOINLINE Array< int16_t > array_first_half__i16(const Array< int16_t > &in_arr)
EXTENSION_NOINLINE Array< int64_t > array_append(const Array< int64_t > &in_arr, const int64_t val)
EXTENSION_NOINLINE Array< int32_t > array_append__(const Array< int32_t > &in_arr, const int32_t val)
EXTENSION_NOINLINE bool array_equal__i64(const Array< int64_t > &in_arr, const Array< int64_t > &other_arr)
#define GET_DICT_DB_ID(mgr, arg_idx)
Definition: heavydbTypes.h:139
EXTENSION_NOINLINE bool array_equal__i8(const Array< int8_t > &in_arr, const Array< int8_t > &other_arr)
EXTENSION_NOINLINE Array< float > array_append__4(const Array< float > &in_arr, const float val)
int32_t getOrAddTransient(int32_t db_id, int32_t dict_id, std::string str)
Definition: heavydbTypes.h:314
EXTENSION_NOINLINE Array< int32_t > array_first_half__i32(const Array< int32_t > &in_arr)
EXTENSION_NOINLINE Array< int8_t > array_first_half__i8(const Array< int8_t > &in_arr)
EXTENSION_NOINLINE bool array_equal__f32(const Array< float > &in_arr, const Array< float > &other_arr)
EXTENSION_NOINLINE bool array_equal__i16(const Array< int16_t > &in_arr, const Array< int16_t > &other_arr)
EXTENSION_NOINLINE bool array_equal__i32(const Array< int32_t > &in_arr, const Array< int32_t > &other_arr)
DEVICE ALWAYS_INLINE size_t size() const
Definition: heavydbTypes.h:520
std::string getString(int32_t db_id, int32_t dict_id, int32_t string_id)
Definition: heavydbTypes.h:299
DEVICE ALWAYS_INLINE Array< bool > barray_append_impl(const Array< bool > &in_arr, const int8_t val)
EXTENSION_NOINLINE Array< int16_t > array_second_half__i16(const Array< int16_t > &in_arr)
DEVICE ALWAYS_INLINE Array< T > array_first_half_impl(const Array< T > &in_arr)
#define ALWAYS_INLINE
EXTENSION_NOINLINE Array< int8_t > array_second_half__i8(const Array< int8_t > &in_arr)
EXTENSION_NOINLINE Array< int64_t > array_second_half__i64(const Array< int64_t > &in_arr)
DEVICE bool isNull() const
Definition: heavydbTypes.h:556
EXTENSION_NOINLINE bool array_equal__bool(const Array< bool > &in_arr, const Array< bool > &other_arr)
EXTENSION_NOINLINE Array< bool > barray_append(const Array< bool > &in_arr, const bool val)