OmniSciDB  471d68cefb
 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.getSize() + 1);
15  for (int64_t i = 0; i < in_arr.getSize(); i++) {
16  out_arr[i] = in_arr(i);
17  }
18  out_arr[in_arr.getSize()] = 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.getSize() + 1);
27  // cast bool array storage to int8_t type to mask null elem correctly
28  auto casted_out_arr = (int8_t*)out_arr.ptr;
29  for (int64_t i = 0; i < in_arr.getSize(); i++) {
30  casted_out_arr[i] = in_arr(i);
31  }
32  casted_out_arr[in_arr.getSize()] = val;
33  return out_arr;
34 }
35 
36 } // namespace
37 
38 #endif
39 
40 #ifdef _WIN32
41 // MSVC doesn't allow extern "C" function using template type
42 // without explicit instantiation
43 template struct Array<bool>;
44 template struct Array<int8_t>;
45 template struct Array<int16_t>;
46 template struct Array<int32_t>;
47 template struct Array<int64_t>;
48 template struct Array<float>;
49 template struct Array<double>;
50 #endif
51 
53  const int64_t val) {
54 #ifndef __CUDACC__
55  return array_append_impl(in_arr, val);
56 #else
57  assert(false);
58  return Array<int64_t>(0, true);
59 #endif
60 }
61 
63  const int32_t val) {
64 #ifndef __CUDACC__
65  return array_append_impl(in_arr, val);
66 #else
67  assert(false);
68  return Array<int32_t>(0, true);
69 #endif
70 }
71 
73  const int16_t val) {
74 #ifndef __CUDACC__
75  return array_append_impl(in_arr, val);
76 #else
77  assert(false);
78  return Array<int16_t>(0, true);
79 #endif
80 }
81 
83  const int8_t val) {
84 #ifndef __CUDACC__
85  return array_append_impl(in_arr, val);
86 #else
87  assert(false);
88  return Array<int8_t>(0, true);
89 #endif
90 }
91 
93  const double val) {
94 #ifndef __CUDACC__
95  return array_append_impl(in_arr, val);
96 #else
97  assert(false);
98  return Array<double>(0, true);
99 #endif
100 }
101 
103  const float val) {
104 #ifndef __CUDACC__
105  return array_append_impl(in_arr, val);
106 #else
107  assert(false);
108  return Array<float>(0, true);
109 #endif
110 }
111 
112 /*
113  Overloading UDFs works for types in the same SQL family. BOOLEAN
114  does not belong to NUMERIC family, hence we need to use different
115  name for boolean UDF.
116  */
118 #ifndef __CUDACC__
119  // we need to cast 'val' to int8_t type to represent null sentinel correctly
120  // i.e., NULL_BOOLEAN = -128
121  return barray_append_impl(in_arr, val);
122 #else
123  assert(false);
124  return Array<bool>(0, true);
125 #endif
126 }
127 
128 #if defined(__clang__)
129 #pragma clang diagnostic pop
130 #endif
EXTENSION_NOINLINE Array< bool > barray_append(const Array< bool > in_arr, const bool val)
EXTENSION_NOINLINE Array< int16_t > array_append__1(const Array< int16_t > in_arr, const int16_t val)
#define DEVICE
#define EXTENSION_NOINLINE
Definition: OmniSciTypes.h:28
EXTENSION_NOINLINE Array< float > array_append__4(const Array< float > in_arr, const float val)
EXTENSION_NOINLINE Array< int32_t > array_append__(const Array< int32_t > in_arr, const int32_t val)
DEVICE int64_t getSize() const
Definition: OmniSciTypes.h:91
DEVICE ALWAYS_INLINE Array< bool > barray_append_impl(const Array< bool > in_arr, const int8_t val)
EXTENSION_NOINLINE Array< double > array_append__3(const Array< double > in_arr, const double val)
EXTENSION_NOINLINE Array< int64_t > array_append(const Array< int64_t > in_arr, const int64_t val)
EXTENSION_NOINLINE Array< int8_t > array_append__2(const Array< int8_t > in_arr, const int8_t val)
T * ptr
Definition: OmniSciTypes.h:67
DEVICE ALWAYS_INLINE Array< T > array_append_impl(const Array< T > in_arr, T val)
#define ALWAYS_INLINE