OmniSciDB  94e8789169
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OmniSciTypes.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <limits>
20 #include <type_traits>
21 
22 /* `../` is required for UDFCompiler */
23 #include "../Shared/InlineNullValues.h"
24 #include "../Shared/funcannotations.h"
25 
26 #define EXTENSION_INLINE extern "C" ALWAYS_INLINE DEVICE
27 #define EXTENSION_NOINLINE extern "C" NEVER_INLINE DEVICE
28 
29 EXTENSION_NOINLINE int8_t* allocate_varlen_buffer(int64_t element_count,
30  int64_t element_size);
31 
32 template <typename T>
33 struct Array {
34  T* ptr;
35  int64_t size;
36  int8_t is_null;
37 
38  DEVICE Array(const int64_t size, const bool is_null = false)
39  : size(size), is_null(is_null) {
40  if (!is_null) {
41  ptr = reinterpret_cast<T*>(
42  allocate_varlen_buffer(size, static_cast<int64_t>(sizeof(T))));
43  } else {
44  ptr = nullptr;
45  }
46  }
47 
48  DEVICE T operator()(const unsigned int index) const {
49  if (index < static_cast<unsigned int>(size)) {
50  return ptr[index];
51  } else {
52  return 0; // see array_at
53  }
54  }
55 
56  DEVICE T& operator[](const unsigned int index) { return ptr[index]; }
57 
58  DEVICE int64_t getSize() const { return size; }
59 
60  DEVICE bool isNull() const { return is_null; }
61 
62  DEVICE constexpr inline T null_value() const {
63  return std::is_signed<T>::value ? std::numeric_limits<T>::min()
64  : std::numeric_limits<T>::max();
65  }
66 };
67 
68 struct GeoLineString {
69  int8_t* ptr;
70  int64_t sz;
71  int32_t compression;
72  int32_t input_srid;
73  int32_t output_srid;
74 
75  DEVICE int64_t getSize() const { return sz; }
76 
77  DEVICE int32_t getCompression() const { return compression; }
78 
79  DEVICE int32_t getInputSrid() const { return input_srid; }
80 
81  DEVICE int32_t getOutputSrid() const { return output_srid; }
82 };
83 
84 struct GeoPoint {
85  int8_t* ptr;
86  int64_t sz;
87  int32_t compression;
88  int32_t input_srid;
89  int32_t output_srid;
90 
91  DEVICE int64_t getSize() const { return sz; }
92 
93  DEVICE int32_t getCompression() const { return compression; }
94 
95  DEVICE int32_t getInputSrid() const { return input_srid; }
96 
97  DEVICE int32_t getOutputSrid() const { return output_srid; }
98 };
99 
100 struct GeoPolygon {
101  int8_t* ptr_coords;
102  int64_t coords_size;
103  int32_t* ring_sizes;
104  int64_t num_rings;
105  int32_t compression;
106  int32_t input_srid;
107  int32_t output_srid;
108 
109  DEVICE int32_t* getRingSizes() { return ring_sizes; }
110  DEVICE int64_t getCoordsSize() const { return coords_size; }
111 
112  DEVICE int64_t getNumRings() const { return num_rings; }
113 
114  DEVICE int32_t getCompression() const { return compression; }
115 
116  DEVICE int32_t getInputSrid() const { return input_srid; }
117 
118  DEVICE int32_t getOutputSrid() const { return output_srid; }
119 };
120 
122  int8_t* ptr_coords;
123  int64_t coords_size;
124  int32_t* ring_sizes;
125  int64_t num_rings;
126  int32_t* poly_sizes;
127  int64_t num_polys;
128  int32_t compression;
129  int32_t input_srid;
130  int32_t output_srid;
131 
132  DEVICE int32_t* getRingSizes() { return ring_sizes; }
133  DEVICE int64_t getCoordsSize() const { return coords_size; }
134 
135  DEVICE int64_t getNumRings() const { return num_rings; }
136 
137  DEVICE int32_t* getPolygonSizes() { return poly_sizes; }
138 
139  DEVICE int64_t getNumPolygons() const { return num_polys; }
140 
141  DEVICE int32_t getCompression() const { return compression; }
142 
143  DEVICE int32_t getInputSrid() const { return input_srid; }
144 
145  DEVICE int32_t getOutputSrid() const { return output_srid; }
146 };
147 
148 template <typename T>
149 struct Column {
150  T* ptr; // row data
151  int64_t sz; // row count
152 
153  DEVICE T& operator[](const unsigned int index) const { return ptr[index]; }
154  DEVICE int64_t getSize() const { return sz; }
155  DEVICE void setSize(int64_t size) { this->sz = size; }
156 
157  DEVICE bool isNull(int64_t index) const { return is_null(ptr[index]); }
158  DEVICE void setNull(int64_t index) { set_null(ptr[index]); }
159 
160 #ifdef HAVE_TOSTRING
161 
162  std::string toString() const {
163  return ::typeName(this) + "(ptr=" + ::toString((void*)ptr) +
164  ", sz=" + std::to_string(sz) + ")";
165  }
166 #endif
167 };
int64_t coords_size
Definition: OmniSciTypes.h:102
int32_t compression
Definition: OmniSciTypes.h:105
DEVICE int32_t getCompression() const
Definition: OmniSciTypes.h:141
int8_t * ptr_coords
Definition: OmniSciTypes.h:101
std::string toString(const ExtArgumentType &sig_type)
DEVICE int32_t getInputSrid() const
Definition: OmniSciTypes.h:116
int32_t output_srid
Definition: OmniSciTypes.h:107
int32_t input_srid
Definition: OmniSciTypes.h:88
EXTENSION_NOINLINE int8_t * allocate_varlen_buffer(int64_t element_count, int64_t element_size)
DEVICE int32_t * getPolygonSizes()
Definition: OmniSciTypes.h:137
DEVICE int64_t getNumRings() const
Definition: OmniSciTypes.h:112
int64_t sz
Definition: OmniSciTypes.h:151
int64_t size
Definition: OmniSciTypes.h:35
int64_t coords_size
Definition: OmniSciTypes.h:123
DEVICE int64_t getNumPolygons() const
Definition: OmniSciTypes.h:139
int8_t * ptr
Definition: OmniSciTypes.h:69
std::string to_string(char const *&&v)
int32_t compression
Definition: OmniSciTypes.h:128
int32_t output_srid
Definition: OmniSciTypes.h:89
#define DEVICE
#define EXTENSION_NOINLINE
Definition: OmniSciTypes.h:27
DEVICE int32_t getInputSrid() const
Definition: OmniSciTypes.h:95
int32_t output_srid
Definition: OmniSciTypes.h:73
DEVICE int32_t getInputSrid() const
Definition: OmniSciTypes.h:79
DEVICE T & operator[](const unsigned int index) const
Definition: OmniSciTypes.h:153
int32_t * ring_sizes
Definition: OmniSciTypes.h:103
int32_t output_srid
Definition: OmniSciTypes.h:130
CONSTEXPR DEVICE bool is_null(const T &value)
DEVICE Array(const int64_t size, const bool is_null=false)
Definition: OmniSciTypes.h:38
DEVICE void setSize(int64_t size)
Definition: OmniSciTypes.h:155
DEVICE T operator()(const unsigned int index) const
Definition: OmniSciTypes.h:48
CONSTEXPR DEVICE void set_null(T &value)
int32_t input_srid
Definition: OmniSciTypes.h:129
DEVICE int64_t getSize() const
Definition: OmniSciTypes.h:58
DEVICE int32_t getCompression() const
Definition: OmniSciTypes.h:114
DEVICE int32_t getInputSrid() const
Definition: OmniSciTypes.h:143
int32_t compression
Definition: OmniSciTypes.h:87
int8_t is_null
Definition: OmniSciTypes.h:36
DEVICE int64_t getSize() const
Definition: OmniSciTypes.h:154
DEVICE int32_t getCompression() const
Definition: OmniSciTypes.h:77
DEVICE constexpr T null_value() const
Definition: OmniSciTypes.h:62
DEVICE int32_t getOutputSrid() const
Definition: OmniSciTypes.h:118
DEVICE bool isNull(int64_t index) const
Definition: OmniSciTypes.h:157
DEVICE void setNull(int64_t index)
Definition: OmniSciTypes.h:158
DEVICE int64_t getCoordsSize() const
Definition: OmniSciTypes.h:110
int8_t * ptr
Definition: OmniSciTypes.h:85
DEVICE int32_t getOutputSrid() const
Definition: OmniSciTypes.h:97
int32_t compression
Definition: OmniSciTypes.h:71
DEVICE int64_t getSize() const
Definition: OmniSciTypes.h:91
int64_t sz
Definition: OmniSciTypes.h:86
DEVICE int32_t getCompression() const
Definition: OmniSciTypes.h:93
int64_t num_rings
Definition: OmniSciTypes.h:104
T * ptr
Definition: OmniSciTypes.h:34
int32_t * ring_sizes
Definition: OmniSciTypes.h:124
DEVICE int64_t getSize() const
Definition: OmniSciTypes.h:75
DEVICE T & operator[](const unsigned int index)
Definition: OmniSciTypes.h:56
int8_t * ptr_coords
Definition: OmniSciTypes.h:122
int32_t * poly_sizes
Definition: OmniSciTypes.h:126
DEVICE int32_t * getRingSizes()
Definition: OmniSciTypes.h:109
DEVICE int64_t getNumRings() const
Definition: OmniSciTypes.h:135
DEVICE int32_t getOutputSrid() const
Definition: OmniSciTypes.h:145
DEVICE int64_t getCoordsSize() const
Definition: OmniSciTypes.h:133
DEVICE bool isNull() const
Definition: OmniSciTypes.h:60
int32_t input_srid
Definition: OmniSciTypes.h:106
DEVICE int32_t * getRingSizes()
Definition: OmniSciTypes.h:132
int32_t input_srid
Definition: OmniSciTypes.h:72
DEVICE int32_t getOutputSrid() const
Definition: OmniSciTypes.h:81