OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InlineNullValues.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 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 #ifndef INLINENULLVALUES_H
18 #define INLINENULLVALUES_H
19 
20 #include "Logger.h"
21 
22 template <typename T>
24 
25 template <>
26 constexpr inline float inline_fp_null_value<float>() {
27  return NULL_FLOAT;
28 }
29 
30 template <>
31 constexpr inline double inline_fp_null_value<double>() {
32  return NULL_DOUBLE;
33 }
34 
35 template <typename T>
37 
38 template <>
39 constexpr inline float inline_fp_null_array_value<float>() {
40  return NULL_ARRAY_FLOAT;
41 }
42 
43 template <>
44 constexpr inline double inline_fp_null_array_value<double>() {
45  return NULL_ARRAY_DOUBLE;
46 }
47 
48 template <typename SQL_TYPE_INFO>
49 inline int64_t inline_int_null_val(const SQL_TYPE_INFO& ti) {
50  auto type = ti.get_type();
51  if (ti.is_string()) {
52  CHECK_EQ(kENCODING_DICT, ti.get_compression());
53  CHECK_EQ(4, ti.get_logical_size());
54  type = kINT;
55  } else {
56  CHECK_EQ(kENCODING_NONE, ti.get_compression());
57  }
58  switch (type) {
59  case kBOOLEAN:
60  return inline_int_null_value<int8_t>();
61  case kTINYINT:
62  return inline_int_null_value<int8_t>();
63  case kSMALLINT:
64  return inline_int_null_value<int16_t>();
65  case kINT:
66  return inline_int_null_value<int32_t>();
67  case kBIGINT:
68  return inline_int_null_value<int64_t>();
69  case kTIMESTAMP:
70  case kTIME:
71  case kDATE:
72  case kINTERVAL_DAY_TIME:
74  return inline_int_null_value<int64_t>();
75  case kDECIMAL:
76  case kNUMERIC:
77  return inline_int_null_value<int64_t>();
78  default:
79  abort();
80  }
81 }
82 
83 template <typename SQL_TYPE_INFO>
84 inline int64_t inline_fixed_encoding_null_val(const SQL_TYPE_INFO& ti) {
85  if (ti.get_compression() == kENCODING_NONE) {
86  return inline_int_null_val(ti);
87  }
88  if (ti.get_compression() == kENCODING_DATE_IN_DAYS) {
89  switch (ti.get_comp_param()) {
90  case 0:
91  case 32:
92  return inline_int_null_value<int32_t>();
93  case 16:
94  return inline_int_null_value<int16_t>();
95  default:
96 #ifndef __CUDACC__
97  CHECK(false) << "Unknown encoding width for date in days: "
98  << ti.get_comp_param();
99 #else
100  CHECK(false);
101 #endif
102  }
103  }
104  if (ti.get_compression() == kENCODING_DICT) {
105  CHECK(ti.is_string());
106  switch (ti.get_size()) {
107  case 1:
108  return inline_int_null_value<uint8_t>();
109  case 2:
110  return inline_int_null_value<uint16_t>();
111  case 4:
112  return inline_int_null_value<int32_t>();
113  default:
114 #ifndef __CUDACC__
115  CHECK(false) << "Unknown size for dictionary encoded type: " << ti.get_size();
116 #else
117  CHECK(false);
118 #endif
119  }
120  }
121  CHECK_EQ(kENCODING_FIXED, ti.get_compression());
122  CHECK(ti.is_integer() || ti.is_time() || ti.is_decimal());
123  CHECK_EQ(0, ti.get_comp_param() % 8);
124  return -(1L << (ti.get_comp_param() - 1));
125 }
126 
127 template <typename SQL_TYPE_INFO>
128 inline double inline_fp_null_val(const SQL_TYPE_INFO& ti) {
129  CHECK(ti.is_fp());
130  const auto type = ti.get_type();
131  switch (type) {
132  case kFLOAT:
134  case kDOUBLE:
136  default:
137  abort();
138  }
139 }
140 
141 // NULL_ARRAY sentinels
142 template <typename SQL_TYPE_INFO>
143 inline int64_t inline_int_null_array_val(const SQL_TYPE_INFO& ti) {
144  auto type = ti.get_type();
145  if (ti.is_string()) {
146  CHECK_EQ(kENCODING_DICT, ti.get_compression());
147  CHECK_EQ(4, ti.get_logical_size());
148  type = kINT;
149  } else {
150  CHECK_EQ(kENCODING_NONE, ti.get_compression());
151  }
152  // For all of the types below NULL sentinel is min of the range,
153  // the value right above it is the NULL_ARRAY sentinel
154  switch (type) {
155  case kBOOLEAN:
156  return inline_int_null_array_value<int8_t>();
157  case kTINYINT:
158  return inline_int_null_array_value<int8_t>();
159  case kSMALLINT:
160  return inline_int_null_array_value<int16_t>();
161  case kINT:
162  return inline_int_null_array_value<int32_t>();
163  case kBIGINT:
164  return inline_int_null_array_value<int64_t>();
165  case kTIMESTAMP:
166  case kTIME:
167  case kDATE:
168  case kINTERVAL_DAY_TIME:
170  return inline_int_null_array_value<int64_t>();
171  case kDECIMAL:
172  case kNUMERIC:
173  return inline_int_null_array_value<int64_t>();
174  default:
175  abort();
176  }
177 }
178 
179 template <typename SQL_TYPE_INFO>
180 inline int64_t inline_fixed_encoding_null_array_val(const SQL_TYPE_INFO& ti) {
181  if (ti.get_compression() == kENCODING_NONE) {
182  return inline_int_null_array_val(ti);
183  }
184  if (ti.get_compression() == kENCODING_DATE_IN_DAYS) {
185  switch (ti.get_comp_param()) {
186  case 0:
187  case 32:
188  return inline_int_null_array_value<int32_t>();
189  case 16:
190  return inline_int_null_array_value<int16_t>();
191  default:
192 #ifndef __CUDACC__
193  CHECK(false) << "Unknown encoding width for date in days: "
194  << ti.get_comp_param();
195 #else
196  CHECK(false);
197 #endif
198  }
199  }
200  if (ti.get_compression() == kENCODING_DICT) {
201  CHECK(ti.is_string());
202 #ifndef __CUDACC__
203  CHECK(false) << "Currently don't support fixed length arrays of dict encoded strings";
204 #else
205  CHECK(false);
206 #endif
207  switch (ti.get_size()) {
208  case 1:
209  return inline_int_null_array_value<uint8_t>();
210  case 2:
211  return inline_int_null_array_value<uint16_t>();
212  case 4:
213  return inline_int_null_array_value<int32_t>();
214  default:
215 #ifndef __CUDACC__
216  CHECK(false) << "Unknown size for dictionary encoded type: " << ti.get_size();
217 #else
218  CHECK(false);
219 #endif
220  }
221  }
222 #ifndef __CUDACC__
223  CHECK(false) << "Currently don't support fixed length arrays with fixed encoding";
224 #else
225  CHECK(false);
226 #endif
227  CHECK_EQ(kENCODING_FIXED, ti.get_compression());
228  CHECK(ti.is_integer() || ti.is_time() || ti.is_decimal());
229  CHECK_EQ(0, ti.get_comp_param() % 8);
230  // The value of the NULL sentinel for fixed encoding is:
231  // -(1L << (ti.get_comp_param() - 1))
232  // NULL_ARRAY sentinel would have to be the value just above NULL:
233  return -(1L << (ti.get_comp_param() - 1)) + 1;
234 }
235 
236 #endif
#define CHECK_EQ(x, y)
Definition: Logger.h:198
#define NULL_DOUBLE
Definition: sqltypes.h:179
Definition: sqltypes.h:52
#define NULL_ARRAY_DOUBLE
Definition: sqltypes.h:187
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
CHECK(cgen_state)
#define NULL_FLOAT
Definition: sqltypes.h:178
T inline_fp_null_value()
T inline_fp_null_array_value()
int64_t inline_int_null_array_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:56
constexpr double inline_fp_null_array_value< double >()
constexpr float inline_fp_null_value< float >()
constexpr double inline_fp_null_value< double >()
int64_t inline_fixed_encoding_null_array_val(const SQL_TYPE_INFO &ti)
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
int64_t inline_fixed_encoding_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:48
constexpr float inline_fp_null_array_value< float >()
#define NULL_ARRAY_FLOAT
Definition: sqltypes.h:186