OmniSciDB  2e3a973ef4
ArrayMetadataStats.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 "Shared/sqltypes.h"
20 
21 namespace foreign_storage {
22 
24  public:
26 
27  void updateStats(const SQLTypeInfo& type_info, const Datum& min, const Datum& max) {
28  switch (type_info.get_type()) {
29  case kBOOLEAN: {
32  break;
33  }
34  case kTINYINT: {
37  break;
38  }
39  case kSMALLINT: {
42  break;
43  }
44  case kINT: {
47  break;
48  }
49  case kBIGINT:
50  case kNUMERIC:
51  case kDECIMAL: {
54  break;
55  }
56  case kTIME:
57  case kTIMESTAMP:
58  case kDATE: {
61  break;
62  }
63  case kFLOAT: {
66  break;
67  }
68  case kDOUBLE: {
71  break;
72  }
73  case kVARCHAR:
74  case kCHAR:
75  case kTEXT:
76  if (type_info.get_compression() == kENCODING_DICT) {
79  }
80  break;
81  case kPOINT:
82  case kLINESTRING:
83  case kPOLYGON:
84  case kMULTIPOLYGON:
85  UNREACHABLE();
86  default:
87  UNREACHABLE();
88  }
89  }
90 
91  template <typename T>
92  void updateStats(const SQLTypeInfo& type_info, const T& min, const T& max) {
93  switch (type_info.get_type()) {
94  case kBOOLEAN: {
97  break;
98  }
99  case kTINYINT: {
100  updateMin(min_.tinyintval, min);
101  updateMax(max_.tinyintval, max);
102  break;
103  }
104  case kSMALLINT: {
105  updateMin(min_.smallintval, min);
106  updateMax(max_.smallintval, max);
107  break;
108  }
109  case kINT: {
110  updateMin(min_.intval, min);
111  updateMax(max_.intval, max);
112  break;
113  }
114  case kBIGINT:
115  case kNUMERIC:
116  case kDECIMAL: {
117  updateMin(min_.bigintval, min);
118  updateMax(max_.bigintval, max);
119  break;
120  }
121  case kTIME:
122  case kTIMESTAMP:
123  case kDATE: {
124  updateMin(min_.bigintval, min);
125  updateMax(max_.bigintval, max);
126  break;
127  }
128  case kFLOAT: {
129  updateMin(min_.floatval, min);
130  updateMax(max_.floatval, max);
131  break;
132  }
133  case kDOUBLE: {
134  updateMin(min_.doubleval, min);
135  updateMax(max_.doubleval, max);
136  break;
137  }
138  case kVARCHAR:
139  case kCHAR:
140  case kTEXT:
141  if (type_info.get_compression() == kENCODING_DICT) {
142  updateMin(min_.intval, min);
143  updateMax(max_.intval, max);
144  }
145  break;
146  case kPOINT:
147  case kLINESTRING:
148  case kPOLYGON:
149  case kMULTIPOLYGON:
150  UNREACHABLE();
151  default:
152  UNREACHABLE();
153  }
154  }
155 
156  Datum getMin(const SQLTypeInfo& type_info) const {
157  if (is_min_initialized_) {
158  return min_;
159  }
160  return getUninitializedMin(type_info);
161  }
162 
163  Datum getMax(const SQLTypeInfo& type_info) const {
164  if (is_max_initialized_) {
165  return max_;
166  }
167  return getUninitializedMax(type_info);
168  }
169 
170  private:
171  Datum getUninitializedMin(const SQLTypeInfo& type_info) const {
172  Datum d;
173  auto type = type_info.get_type();
174  switch (type) {
175  case kSMALLINT:
176  d.smallintval = std::numeric_limits<int16_t>::max();
177  break;
178  case kBOOLEAN:
179  case kTINYINT:
180  d.tinyintval = std::numeric_limits<int8_t>::max();
181  break;
182  case kFLOAT:
183  d.floatval = std::numeric_limits<float>::max();
184  break;
185  case kDOUBLE:
186  d.doubleval = std::numeric_limits<double>::max();
187  break;
188  case kTEXT:
189  case kVARCHAR:
190  case kCHAR:
191  case kINT:
192  d.intval = std::numeric_limits<int32_t>::max();
193  break;
194  case kTIME:
195  case kTIMESTAMP:
196  case kDATE:
197  case kBIGINT:
198  case kNUMERIC:
199  case kDECIMAL:
200  d.bigintval = std::numeric_limits<int64_t>::max();
201  break;
202  case kPOINT:
203  case kLINESTRING:
204  case kPOLYGON:
205  case kMULTIPOLYGON:
206  UNREACHABLE();
207  default:
208  UNREACHABLE();
209  }
210  return d;
211  }
212 
213  Datum getUninitializedMax(const SQLTypeInfo& type_info) const {
214  Datum d;
215  auto type = type_info.get_type();
216  switch (type) {
217  case kSMALLINT:
218  d.smallintval = std::numeric_limits<int16_t>::lowest();
219  break;
220  case kBOOLEAN:
221  case kTINYINT:
222  d.tinyintval = std::numeric_limits<int8_t>::lowest();
223  break;
224  case kFLOAT:
225  d.floatval = std::numeric_limits<float>::lowest();
226  break;
227  case kDOUBLE:
228  d.doubleval = std::numeric_limits<double>::lowest();
229  break;
230  case kTEXT:
231  case kVARCHAR:
232  case kCHAR:
233  case kINT:
234  d.intval = std::numeric_limits<int32_t>::lowest();
235  break;
236  case kTIME:
237  case kTIMESTAMP:
238  case kDATE:
239  case kBIGINT:
240  case kNUMERIC:
241  case kDECIMAL:
242  d.bigintval = std::numeric_limits<int64_t>::lowest();
243  break;
244  case kPOINT:
245  case kLINESTRING:
246  case kPOLYGON:
247  case kMULTIPOLYGON:
248  UNREACHABLE();
249  default:
250  UNREACHABLE();
251  }
252  return d;
253  }
254 
255  template <typename V, typename T>
256  void updateMin(V& current_min, const T& value) {
257  if (!is_min_initialized_) {
258  current_min = value;
259  } else {
260  current_min = std::min<V>(current_min, value);
261  }
262  is_min_initialized_ = true;
263  }
264 
265  template <typename V, typename T>
266  void updateMax(V& current_max, const T& value) {
267  if (!is_max_initialized_) {
268  current_max = value;
269  } else {
270  current_max = std::max<V>(current_max, value);
271  }
272  is_max_initialized_ = true;
273  }
274 
278 };
279 
280 } // namespace foreign_storage
int8_t tinyintval
Definition: sqltypes.h:135
Definition: sqltypes.h:51
#define UNREACHABLE()
Definition: Logger.h:241
Constants for Builtin SQL Types supported by OmniSci.
void updateStats(const SQLTypeInfo &type_info, const Datum &min, const Datum &max)
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:267
int32_t intval
Definition: sqltypes.h:137
void updateStats(const SQLTypeInfo &type_info, const T &min, const T &max)
float floatval
Definition: sqltypes.h:139
int64_t bigintval
Definition: sqltypes.h:138
Datum getUninitializedMin(const SQLTypeInfo &type_info) const
Datum getUninitializedMax(const SQLTypeInfo &type_info) const
int16_t smallintval
Definition: sqltypes.h:136
Datum getMax(const SQLTypeInfo &type_info) const
Definition: sqltypes.h:54
Definition: sqltypes.h:55
Datum getMin(const SQLTypeInfo &type_info) const
Definition: sqltypes.h:43
void updateMin(V &current_min, const T &value)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:259
Definition: sqltypes.h:47
void updateMax(V &current_max, const T &value)
double doubleval
Definition: sqltypes.h:140