OmniSciDB  340b00dbf6
 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 #include "../Shared/funcannotations.h"
23 
24 #define EXTENSION_INLINE extern "C" ALWAYS_INLINE DEVICE
25 #define EXTENSION_NOINLINE extern "C" NEVER_INLINE DEVICE
26 
27 EXTENSION_NOINLINE int8_t* allocate_varlen_buffer(int64_t element_count,
28  int64_t element_size);
29 
30 template <typename T>
31 struct Array {
32  T* ptr;
33  int64_t size;
34  int8_t is_null;
35 
36  DEVICE Array(const int64_t size, const bool is_null = false)
37  : size(size), is_null(is_null) {
38  if (!is_null) {
39  ptr = reinterpret_cast<T*>(
40  allocate_varlen_buffer(size, static_cast<int64_t>(sizeof(T))));
41  } else {
42  ptr = nullptr;
43  }
44  }
45 
46  DEVICE T operator()(const unsigned int index) const {
47  if (index < static_cast<unsigned int>(size)) {
48  return ptr[index];
49  } else {
50  return 0; // see array_at
51  }
52  }
53 
54  DEVICE T& operator[](const unsigned int index) { return ptr[index]; }
55 
56  DEVICE int64_t getSize() const { return size; }
57 
58  DEVICE bool isNull() const { return is_null; }
59 
60  DEVICE constexpr inline T null_value() const {
61  return std::is_signed<T>::value ? std::numeric_limits<T>::min()
62  : std::numeric_limits<T>::max();
63  }
64 };
65 
66 struct GeoLineString {
67  int8_t* ptr;
68  int64_t sz;
69  int32_t compression;
70  int32_t input_srid;
71  int32_t output_srid;
72 
73  DEVICE int64_t getSize() const { return sz; }
74 
75  DEVICE int32_t getCompression() const { return compression; }
76 
77  DEVICE int32_t getInputSrid() const { return input_srid; }
78 
79  DEVICE int32_t getOutputSrid() const { return output_srid; }
80 };
81 
82 struct GeoPoint {
83  int8_t* ptr;
84  int64_t sz;
85  int32_t compression;
86  int32_t input_srid;
87  int32_t output_srid;
88 
89  DEVICE int64_t getSize() const { return sz; }
90 
91  DEVICE int32_t getCompression() const { return compression; }
92 
93  DEVICE int32_t getInputSrid() const { return input_srid; }
94 
95  DEVICE int32_t getOutputSrid() const { return output_srid; }
96 };
97 
98 struct GeoPolygon {
99  int8_t* ptr_coords;
100  int64_t coords_size;
101  int32_t* ring_sizes;
102  int64_t num_rings;
103  int32_t compression;
104  int32_t input_srid;
105  int32_t output_srid;
106 
107  DEVICE int32_t* getRingSizes() { return ring_sizes; }
108  DEVICE int64_t getCoordsSize() const { return coords_size; }
109 
110  DEVICE int64_t getNumRings() const { return num_rings; }
111 
112  DEVICE int32_t getCompression() const { return compression; }
113 
114  DEVICE int32_t getInputSrid() const { return input_srid; }
115 
116  DEVICE int32_t getOutputSrid() const { return output_srid; }
117 };
118 
120  int8_t* ptr_coords;
121  int64_t coords_size;
122  int32_t* ring_sizes;
123  int64_t num_rings;
124  int32_t* poly_sizes;
125  int64_t num_polys;
126  int32_t compression;
127  int32_t input_srid;
128  int32_t output_srid;
129 
130  DEVICE int32_t* getRingSizes() { return ring_sizes; }
131  DEVICE int64_t getCoordsSize() const { return coords_size; }
132 
133  DEVICE int64_t getNumRings() const { return num_rings; }
134 
135  DEVICE int32_t* getPolygonSizes() { return poly_sizes; }
136 
137  DEVICE int64_t getNumPolygons() const { return num_polys; }
138 
139  DEVICE int32_t getCompression() const { return compression; }
140 
141  DEVICE int32_t getInputSrid() const { return input_srid; }
142 
143  DEVICE int32_t getOutputSrid() const { return output_srid; }
144 };
145 
146 template <typename T>
147 struct Column {
148  T* ptr; // row data
149  int64_t sz; // row count
150 
151  DEVICE T& operator[](const unsigned int index) const { return ptr[index]; }
152  DEVICE int64_t getSize() const { return sz; }
153  DEVICE void setSize(int64_t size) { this->sz = size; }
154 
155 #ifdef HAVE_TOSTRING
156 
157  std::string toString() const {
158  return ::typeName(this) + "(ptr=" + ::toString((void*)ptr) +
159  ", sz=" + std::to_string(sz) + ")";
160  }
161 #endif
162 };
int64_t coords_size
Definition: OmniSciTypes.h:100
int32_t compression
Definition: OmniSciTypes.h:103
DEVICE int32_t getCompression() const
Definition: OmniSciTypes.h:139
int8_t * ptr_coords
Definition: OmniSciTypes.h:99
std::string toString(const ExtArgumentType &sig_type)
DEVICE int32_t getInputSrid() const
Definition: OmniSciTypes.h:114
int32_t output_srid
Definition: OmniSciTypes.h:105
int32_t input_srid
Definition: OmniSciTypes.h:86
EXTENSION_NOINLINE int8_t * allocate_varlen_buffer(int64_t element_count, int64_t element_size)
DEVICE int32_t * getPolygonSizes()
Definition: OmniSciTypes.h:135
DEVICE int64_t getNumRings() const
Definition: OmniSciTypes.h:110
int64_t sz
Definition: OmniSciTypes.h:149
int64_t size
Definition: OmniSciTypes.h:33
int64_t coords_size
Definition: OmniSciTypes.h:121
DEVICE int64_t getNumPolygons() const
Definition: OmniSciTypes.h:137
int8_t * ptr
Definition: OmniSciTypes.h:67
std::string to_string(char const *&&v)
int32_t compression
Definition: OmniSciTypes.h:126
int32_t output_srid
Definition: OmniSciTypes.h:87
#define DEVICE
#define EXTENSION_NOINLINE
Definition: OmniSciTypes.h:25
DEVICE int32_t getInputSrid() const
Definition: OmniSciTypes.h:93
int32_t output_srid
Definition: OmniSciTypes.h:71
DEVICE int32_t getInputSrid() const
Definition: OmniSciTypes.h:77
DEVICE T & operator[](const unsigned int index) const
Definition: OmniSciTypes.h:151
int32_t * ring_sizes
Definition: OmniSciTypes.h:101
int32_t output_srid
Definition: OmniSciTypes.h:128
DEVICE Array(const int64_t size, const bool is_null=false)
Definition: OmniSciTypes.h:36
DEVICE void setSize(int64_t size)
Definition: OmniSciTypes.h:153
DEVICE T operator()(const unsigned int index) const
Definition: OmniSciTypes.h:46
int32_t input_srid
Definition: OmniSciTypes.h:127
DEVICE int64_t getSize() const
Definition: OmniSciTypes.h:56
DEVICE int32_t getCompression() const
Definition: OmniSciTypes.h:112
DEVICE int32_t getInputSrid() const
Definition: OmniSciTypes.h:141
int32_t compression
Definition: OmniSciTypes.h:85
int8_t is_null
Definition: OmniSciTypes.h:34
DEVICE int64_t getSize() const
Definition: OmniSciTypes.h:152
DEVICE int32_t getCompression() const
Definition: OmniSciTypes.h:75
DEVICE constexpr T null_value() const
Definition: OmniSciTypes.h:60
DEVICE int32_t getOutputSrid() const
Definition: OmniSciTypes.h:116
DEVICE int64_t getCoordsSize() const
Definition: OmniSciTypes.h:108
int8_t * ptr
Definition: OmniSciTypes.h:83
DEVICE int32_t getOutputSrid() const
Definition: OmniSciTypes.h:95
int32_t compression
Definition: OmniSciTypes.h:69
DEVICE int64_t getSize() const
Definition: OmniSciTypes.h:89
int64_t sz
Definition: OmniSciTypes.h:84
DEVICE int32_t getCompression() const
Definition: OmniSciTypes.h:91
int64_t num_rings
Definition: OmniSciTypes.h:102
T * ptr
Definition: OmniSciTypes.h:32
int32_t * ring_sizes
Definition: OmniSciTypes.h:122
DEVICE int64_t getSize() const
Definition: OmniSciTypes.h:73
DEVICE T & operator[](const unsigned int index)
Definition: OmniSciTypes.h:54
int8_t * ptr_coords
Definition: OmniSciTypes.h:120
int32_t * poly_sizes
Definition: OmniSciTypes.h:124
DEVICE int32_t * getRingSizes()
Definition: OmniSciTypes.h:107
DEVICE int64_t getNumRings() const
Definition: OmniSciTypes.h:133
DEVICE int32_t getOutputSrid() const
Definition: OmniSciTypes.h:143
DEVICE int64_t getCoordsSize() const
Definition: OmniSciTypes.h:131
DEVICE bool isNull() const
Definition: OmniSciTypes.h:58
int32_t input_srid
Definition: OmniSciTypes.h:104
DEVICE int32_t * getRingSizes()
Definition: OmniSciTypes.h:130
int32_t input_srid
Definition: OmniSciTypes.h:70
DEVICE int32_t getOutputSrid() const
Definition: OmniSciTypes.h:79