OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sqltypes.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, 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 
23 #pragma once
24 
25 #if !(defined(__CUDACC__) || defined(NO_BOOST))
26 #include "toString.h"
27 #else
28 #ifndef PRINT
29 #define PRINT(...)
30 #endif
31 #endif
32 
33 #include "../Logger/Logger.h"
34 #include "../QueryEngine/Utils/FlatBuffer.h"
35 #include "Datum.h"
36 #include "funcannotations.h"
37 #include "sqltypes_lite.h"
38 
39 #include <cassert>
40 #include <ctime>
41 #include <memory>
42 #include <ostream>
43 #include <sstream>
44 #include <string>
45 #include <type_traits>
46 #include <vector>
47 
48 #include "Shared/DbObjectKeys.h"
49 
50 namespace sql_constants {
51 /*
52 The largest precision an SQL type is allowed to specify is currently 18 digits,
53 however, the most precise numeric value we can represent is actually precise to 19 digits.
54 This means that we can be slightly more relaxed when doing internal calculations than when
55 setting column types (e.g. a CAST from double to numeric could use precision 19 as long as
56 it doesn't overflow but a column cannot be specified to have precision 19+).
57 */
58 constexpr static int32_t kMaxNumericPrecision =
59  std::numeric_limits<int64_t>::digits10; // 18
60 constexpr static int32_t kMaxRepresentableNumericPrecision =
61  kMaxNumericPrecision + 1; // 19
62 } // namespace sql_constants
63 
64 // must not change because these values persist in catalogs.
65 enum SQLTypes {
66  kNULLT = 0, // type for null values
67  kBOOLEAN = 1,
68  kCHAR = 2,
69  kVARCHAR = 3,
70  kNUMERIC = 4,
71  kDECIMAL = 5,
72  kINT = 6,
73  kSMALLINT = 7,
74  kFLOAT = 8,
75  kDOUBLE = 9,
76  kTIME = 10,
77  kTIMESTAMP = 11,
78  kBIGINT = 12,
79  kTEXT = 13,
80  kDATE = 14,
81  kARRAY = 15,
84  kPOINT = 18,
86  kPOLYGON = 20,
88  kTINYINT = 22,
89  kGEOMETRY = 23,
90  kGEOGRAPHY = 24,
91  kEVAL_CONTEXT_TYPE = 25, // Placeholder Type for ANY
92  kVOID = 26,
93  kCURSOR = 27,
94  kCOLUMN = 28,
99 };
100 
101 #if !(defined(__CUDACC__) || defined(NO_BOOST))
102 
103 inline std::string toString(const SQLTypes& type) {
104  switch (type) {
105  case kNULLT:
106  return "NULL";
107  case kBOOLEAN:
108  return "BOOL";
109  case kCHAR:
110  return "CHAR";
111  case kVARCHAR:
112  return "VARCHAR";
113  case kNUMERIC:
114  return "NUMERIC";
115  case kDECIMAL:
116  return "DECIMAL";
117  case kINT:
118  return "INT";
119  case kSMALLINT:
120  return "SMALLINT";
121  case kFLOAT:
122  return "FLOAT";
123  case kDOUBLE:
124  return "DOUBLE";
125  case kTIME:
126  return "TIME";
127  case kTIMESTAMP:
128  return "TIMESTAMP";
129  case kBIGINT:
130  return "BIGINT";
131  case kTEXT:
132  return "TEXT";
133  case kDATE:
134  return "DATE";
135  case kARRAY:
136  return "ARRAY";
137  case kINTERVAL_DAY_TIME:
138  return "DAY TIME INTERVAL";
140  return "YEAR MONTH INTERVAL";
141  case kPOINT:
142  return "POINT";
143  case kMULTIPOINT:
144  return "MULTIPOINT";
145  case kLINESTRING:
146  return "LINESTRING";
147  case kMULTILINESTRING:
148  return "MULTILINESTRING";
149  case kPOLYGON:
150  return "POLYGON";
151  case kMULTIPOLYGON:
152  return "MULTIPOLYGON";
153  case kTINYINT:
154  return "TINYINT";
155  case kGEOMETRY:
156  return "GEOMETRY";
157  case kGEOGRAPHY:
158  return "GEOGRAPHY";
159  case kEVAL_CONTEXT_TYPE:
160  return "UNEVALUATED ANY";
161  case kVOID:
162  return "VOID";
163  case kCURSOR:
164  return "CURSOR";
165  case kCOLUMN:
166  return "COLUMN";
167  case kCOLUMN_LIST:
168  return "COLUMN_LIST";
169  case kSQLTYPE_LAST:
170  break;
171  }
172  LOG(FATAL) << "Invalid SQL type: " << type;
173  return "";
174 }
175 
176 inline std::ostream& operator<<(std::ostream& os, SQLTypes const sql_type) {
177  os << toString(sql_type);
178  return os;
179 }
180 
181 #endif // #if !(defined(__CUDACC__) || defined(NO_BOOST))
182 
184  void operator()(int8_t*) {}
185 };
186 struct FreeDeleter {
187  void operator()(int8_t* p) { free(p); }
188 };
189 
190 struct HostArrayDatum : public VarlenDatum {
191  using ManagedPtr = std::shared_ptr<int8_t>;
192 
193  HostArrayDatum() = default;
194 
195  HostArrayDatum(size_t const l, ManagedPtr p, bool const n)
196  : VarlenDatum(l, p.get(), n), data_ptr(p) {}
197 
198  HostArrayDatum(size_t const l, int8_t* p, bool const n)
199  : VarlenDatum(l, p, n), data_ptr(p, FreeDeleter()){};
200 
201  template <typename CUSTOM_DELETER,
202  typename = std::enable_if_t<
203  std::is_void<std::result_of_t<CUSTOM_DELETER(int8_t*)> >::value> >
204  HostArrayDatum(size_t const l, int8_t* p, CUSTOM_DELETER custom_deleter)
205  : VarlenDatum(l, p, 0 == l), data_ptr(p, custom_deleter) {}
206 
207  template <typename CUSTOM_DELETER,
208  typename = std::enable_if_t<
209  std::is_void<std::result_of_t<CUSTOM_DELETER(int8_t*)> >::value> >
210  HostArrayDatum(size_t const l, int8_t* p, bool const n, CUSTOM_DELETER custom_deleter)
211  : VarlenDatum(l, p, n), data_ptr(p, custom_deleter) {}
212 
214 };
215 
216 struct DeviceArrayDatum : public VarlenDatum {
218 };
219 
220 inline DEVICE constexpr bool is_cuda_compiler() {
221 #ifdef __CUDACC__
222  return true;
223 #else
224  return false;
225 #endif
226 }
227 
228 using ArrayDatum =
229  std::conditional_t<is_cuda_compiler(), DeviceArrayDatum, HostArrayDatum>;
230 
231 #ifndef __CUDACC__
233  int8_t* numbersPtr;
234  std::vector<std::string>* stringsPtr;
235  std::vector<ArrayDatum>* arraysPtr;
236 };
237 #endif
238 
239 // must not change because these values persist in catalogs.
241  kENCODING_NONE = 0, // no encoding
242  kENCODING_FIXED = 1, // Fixed-bit encoding
243  kENCODING_RL = 2, // Run Length encoding
244  kENCODING_DIFF = 3, // Differential encoding
245  kENCODING_DICT = 4, // Dictionary encoding
246  kENCODING_SPARSE = 5, // Null encoding for sparse columns
247  kENCODING_GEOINT = 6, // Encoding coordinates as intergers
248  kENCODING_DATE_IN_DAYS = 7, // Date encoding in days
249  kENCODING_ARRAY = 8, // Array encoding for columns of arrays
250  kENCODING_ARRAY_DICT = 9, // Array encoding for columns of text encoding dict arrays
252 };
253 
254 #if !(defined(__CUDACC__) || defined(NO_BOOST))
255 
256 inline std::ostream& operator<<(std::ostream& os, EncodingType const type) {
257  switch (type) {
258  case kENCODING_NONE:
259  os << "NONE";
260  break;
261  case kENCODING_FIXED:
262  os << "FIXED";
263  break;
264  case kENCODING_RL:
265  os << "RL";
266  break;
267  case kENCODING_DIFF:
268  os << "DIFF";
269  break;
270  case kENCODING_DICT:
271  os << "DICT";
272  break;
273  case kENCODING_SPARSE:
274  os << "SPARSE";
275  break;
276  case kENCODING_GEOINT:
277  os << "GEOINT";
278  break;
280  os << "DATE_IN_DAYS";
281  break;
282  case kENCODING_ARRAY:
283  os << "ARRAY";
284  break;
286  os << "ARRAY_DICT";
287  break;
288  case kENCODING_LAST:
289  break;
290  default:
291  LOG(FATAL) << "Invalid EncodingType: " << type;
292  }
293  return os;
294 }
295 
296 inline std::string toString(const EncodingType& type) {
297  std::ostringstream ss;
298  ss << type;
299  return ss.str();
300 }
301 
302 #endif // #if !(defined(__CUDACC__) || defined(NO_BOOST))
303 
304 #define IS_INTEGER(T) \
305  (((T) == kINT) || ((T) == kSMALLINT) || ((T) == kBIGINT) || ((T) == kTINYINT))
306 #define IS_NUMBER(T) \
307  (((T) == kINT) || ((T) == kSMALLINT) || ((T) == kDOUBLE) || ((T) == kFLOAT) || \
308  ((T) == kBIGINT) || ((T) == kNUMERIC) || ((T) == kDECIMAL) || ((T) == kTINYINT))
309 #define IS_STRING(T) (((T) == kTEXT) || ((T) == kVARCHAR) || ((T) == kCHAR))
310 #define IS_GEO(T) \
311  (((T) == kPOINT) || ((T) == kLINESTRING) || ((T) == kMULTILINESTRING) || \
312  ((T) == kMULTIPOINT) || ((T) == kPOLYGON) || ((T) == kMULTIPOLYGON))
313 #define IS_INTERVAL(T) ((T) == kINTERVAL_DAY_TIME || (T) == kINTERVAL_YEAR_MONTH)
314 #define IS_DECIMAL(T) ((T) == kNUMERIC || (T) == kDECIMAL)
315 #define IS_GEO_POLY(T) (((T) == kPOLYGON) || ((T) == kMULTIPOLYGON))
316 #define IS_GEO_LINE(T) (((T) == kLINESTRING) || ((T) == kMULTILINESTRING))
317 #define IS_GEO_MULTI(T) \
318  (((T) == kMULTIPOLYGON) || ((T) == kMULTILINESTRING) || ((T) == kMULTIPOINT))
319 
320 #include "InlineNullValues.h"
321 
322 #define TRANSIENT_DICT(ID) (-(ID))
323 #define REGULAR_DICT(TRANSIENTID) (-(TRANSIENTID))
324 
325 constexpr auto is_datetime(SQLTypes type) {
326  return type == kTIME || type == kTIMESTAMP || type == kDATE;
327 }
328 
329 // @type SQLTypeInfo
330 // @brief a structure to capture all type information including
331 // length, precision, scale, etc.
332 class SQLTypeInfo {
333  public:
334  SQLTypeInfo(SQLTypes t, int d, int s, bool n, EncodingType c, int p, SQLTypes st)
335  : type(t)
336  , subtype(st)
337  , dimension(d)
338  , scale(s)
339  , notnull(n)
340  , compression(c)
341  , comp_param(p)
342  , size(get_storage_size()) {}
343  SQLTypeInfo(SQLTypes t, int d, int s, bool n)
344  : type(t)
345  , subtype(kNULLT)
346  , dimension(d)
347  , scale(s)
348  , notnull(n)
350  , comp_param(0)
351  , size(get_storage_size()) {}
353  : type(t)
354  , subtype(st)
355  , dimension(0)
356  , scale(0)
357  , notnull(false)
358  , compression(c)
359  , comp_param(p)
360  , size(get_storage_size()) {}
361  SQLTypeInfo(SQLTypes t, int d, int s) : SQLTypeInfo(t, d, s, false) {}
363  : type(t)
364  , subtype(kNULLT)
365  , dimension(0)
366  , scale(0)
367  , notnull(n)
369  , comp_param(0)
370  , size(get_storage_size()) {}
373  : type(t)
374  , subtype(kNULLT)
375  , dimension(0)
376  , scale(0)
377  , notnull(n)
378  , compression(c)
379  , comp_param(0)
380  , size(get_storage_size()) {}
382  : type(kNULLT)
383  , subtype(kNULLT)
384  , dimension(0)
385  , scale(0)
386  , notnull(false)
388  , comp_param(0)
389  , size(0) {}
390 
391  HOST DEVICE inline SQLTypes get_type() const { return type; }
392  HOST DEVICE inline SQLTypes get_subtype() const { return subtype; }
393  HOST DEVICE inline int get_dimension() const { return dimension; }
394  inline int get_precision() const { return dimension; }
395  HOST DEVICE inline int get_input_srid() const { return dimension; }
396  HOST DEVICE inline int get_scale() const { return scale; }
397  HOST DEVICE inline int get_output_srid() const { return scale; }
398  HOST DEVICE inline bool get_notnull() const { return notnull; }
400  // TODO: Remove ambiguous `comp_param` attribute and replace with a comp_size enum.
401  // dict_key should be used uniformly for dictionary ID.
402  HOST DEVICE inline int get_comp_param() const { return comp_param; }
403  HOST DEVICE inline int get_size() const { return size; }
404  // Valid only for IS_STRING(T) types
405  HOST DEVICE inline size_t get_max_strlen() const {
406  return compression == kENCODING_DICT
407  ? ~(~size_t(0) << 15) // std::numeric_limits<int16_t>::max()
408  : ~size_t(0); // std::numeric_limits<size_t>::max()
409  }
410 
411  inline int is_logical_geo_type() const {
412  if (type == kPOINT || type == kLINESTRING || type == kMULTILINESTRING ||
413  type == kMULTIPOINT || type == kPOLYGON || type == kMULTIPOLYGON) {
414  return true;
415  }
416  return false;
417  }
418 
419  inline int get_logical_size() const {
422  return ti.get_size();
423  }
424  if (compression == kENCODING_DICT) {
425  return 4;
426  }
427  return get_size();
428  }
429 
430  inline int get_physical_cols() const {
431  switch (type) {
432  case kPOINT:
433  return 1; // coords
434  case kMULTIPOINT:
435  return 2; // coords, bounds
436  case kLINESTRING:
437  return 2; // coords, bounds
438  case kMULTILINESTRING:
439  return 3; // coords, linestring_sizes, bounds
440  case kPOLYGON:
441  return 3; // coords, ring_sizes, bounds
442  case kMULTIPOLYGON:
443  return 4; // coords, ring_sizes, poly_rings, bounds
444  default:
445  break;
446  }
447  return 0;
448  }
449  inline int get_physical_coord_cols() const {
450  // Return the number of extra columns which need to go through the executor,
451  // as opposed to those which are only needed by CPU. In other words, we omit
452  // any Bounds column.
453  return has_bounds() ? get_physical_cols() - 1 : get_physical_cols();
454  }
455  inline bool has_bounds() const {
456  switch (type) {
457  case kMULTIPOINT:
458  case kLINESTRING:
459  case kMULTILINESTRING:
460  case kPOLYGON:
461  case kMULTIPOLYGON:
462  return true;
463  default:
464  break;
465  }
466  return false;
467  }
468  HOST DEVICE inline void set_type(SQLTypes t) { type = t; }
469  HOST DEVICE inline void set_subtype(SQLTypes st) { subtype = st; }
470  inline void set_dimension(int d) { dimension = d; }
471  inline void set_precision(int d) { dimension = d; }
472  inline void set_input_srid(int d) { dimension = d; }
473  inline void set_scale(int s) { scale = s; }
474  inline void set_output_srid(int s) { scale = s; }
475  inline void set_notnull(bool n) { notnull = n; }
476  inline void set_size(int s) { size = s; }
477  inline void set_fixed_size() { size = get_storage_size(); }
478  inline void set_dict_intersection() { dict_intersection = true; }
479  inline void set_compression(EncodingType c) { compression = c; }
480  inline void set_comp_param(int p) { comp_param = p; }
481 #ifndef __CUDACC__
482  inline std::string get_type_name() const {
483  if (IS_GEO(type)) {
484  std::string srid_string = "";
485  if (get_output_srid() > 0) {
486  srid_string = ", " + std::to_string(get_output_srid());
487  }
488  CHECK_LT(static_cast<int>(subtype), kSQLTYPE_LAST);
489  return type_name[static_cast<int>(subtype)] + "(" +
490  type_name[static_cast<int>(type)] + srid_string + ")";
491  }
492  std::string ps = "";
493  if (type == kDECIMAL || type == kNUMERIC) {
494  ps = "(" + std::to_string(dimension) + "," + std::to_string(scale) + ")";
495  } else if (type == kTIMESTAMP) {
496  ps = "(" + std::to_string(dimension) + ")";
497  }
498  if (type == kARRAY) {
499  auto elem_ti = get_elem_type();
500  auto num_elems = (size > 0) ? std::to_string(size / elem_ti.get_size()) : "";
501  CHECK_LT(static_cast<int>(subtype), kSQLTYPE_LAST);
502  return elem_ti.get_type_name() + ps + "[" + num_elems + "]";
503  }
504  if (type == kCOLUMN) {
505  auto elem_ti = get_elem_type();
506  auto num_elems =
507  (size > 0) ? "[" + std::to_string(size / elem_ti.get_size()) + "]" : "";
508  CHECK_LT(static_cast<int>(subtype), kSQLTYPE_LAST);
509  return "COLUMN<" + elem_ti.get_type_name() + ps + ">" + num_elems;
510  }
511  if (type == kCOLUMN_LIST) {
512  auto elem_ti = get_elem_type();
513  auto num_elems =
514  (size > 0) ? "[" + std::to_string(size / elem_ti.get_size()) + "]" : "";
515  CHECK_LT(static_cast<int>(subtype), kSQLTYPE_LAST);
516  return "COLUMN_LIST<" + elem_ti.get_type_name() + ps + ">" + num_elems;
517  }
518  return type_name[static_cast<int>(type)] + ps;
519  }
520  inline std::string get_compression_name() const {
521  return comp_name[(int)compression];
522  }
523  std::string toString() const {
524  return to_string();
525  } // for PRINT macro
526  inline std::string to_string() const {
527  std::ostringstream oss;
528  oss << "(type=" << type_name[static_cast<int>(type)]
529  << ", dimension=" << get_dimension() << ", scale=" << get_scale()
530  << ", null=" << (get_notnull() ? "not nullable" : "nullable")
531  << ", compression_name=" << get_compression_name()
532  << ", comp_param=" << get_comp_param()
533  << ", subtype=" << type_name[static_cast<int>(subtype)] << ", size=" << get_size()
534  << ", element_size=" << get_elem_type().get_size() << ", dict_key=" << dict_key_
535  << ", uses_flatbuffer=" << uses_flatbuffer_ << ")";
536  return oss.str();
537  }
538 
539  inline std::string get_buffer_name() const {
540  if (is_array()) {
541  return "Array";
542  }
543  if (is_text_encoding_none()) {
544  return "TextEncodingNone";
545  }
546 
547  if (is_column()) {
548  return "Column";
549  }
550 
551  assert(false);
552  return "";
553  }
554 #endif
555  template <SQLTypes... types>
556  bool is_any() const {
557  return (... || (types == type));
558  }
559  inline bool is_string() const {
560  return IS_STRING(type);
561  }
562  inline bool is_string_array() const {
563  return (type == kARRAY) && IS_STRING(subtype);
564  }
565  inline bool is_integer() const {
566  return IS_INTEGER(type);
567  }
568  inline bool is_decimal() const {
569  return type == kDECIMAL || type == kNUMERIC;
570  }
571  inline bool is_fp() const {
572  return type == kFLOAT || type == kDOUBLE;
573  }
574  inline bool is_number() const {
575  return IS_NUMBER(type);
576  }
577  inline bool is_time() const {
578  return is_datetime(type);
579  }
580  inline bool is_boolean() const {
581  return type == kBOOLEAN;
582  }
583  inline bool is_array() const {
584  return type == kARRAY;
585  } // Array
586  inline bool is_varlen_array() const {
587  return type == kARRAY && size <= 0;
588  }
589  inline bool is_fixlen_array() const {
590  return type == kARRAY && size > 0;
591  }
592  inline bool is_timeinterval() const {
593  return IS_INTERVAL(type);
594  }
595  inline bool is_geometry() const {
596  return IS_GEO(type);
597  }
598  inline bool is_column() const {
599  return type == kCOLUMN;
600  } // Column
601  inline bool is_column_list() const {
602  return type == kCOLUMN_LIST;
603  } // ColumnList
604  inline bool is_column_array() const {
605  const auto c = get_compression();
606  return type == kCOLUMN && (c == kENCODING_ARRAY || c == kENCODING_ARRAY_DICT);
607  } // ColumnArray
608  inline bool is_column_list_array() const {
609  const auto c = get_compression();
610  return type == kCOLUMN_LIST && (c == kENCODING_ARRAY || c == kENCODING_ARRAY_DICT);
611  } // ColumnList of ColumnArray
612  inline bool is_text_encoding_none() const {
613  return type == kTEXT && get_compression() == kENCODING_NONE;
614  }
615  inline bool is_text_encoding_dict() const {
616  return type == kTEXT && get_compression() == kENCODING_DICT;
617  }
618  inline bool is_text_encoding_dict_array() const {
619  return type == kARRAY && subtype == kTEXT && get_compression() == kENCODING_DICT;
620  }
621  inline bool is_buffer() const {
622  return is_array() || is_column() || is_column_list() || is_text_encoding_none();
623  }
624  inline bool transforms() const {
625  return IS_GEO(type) && get_input_srid() > 0 && get_output_srid() > 0 &&
627  }
628 
629  inline bool is_varlen() const { // TODO: logically this should ignore fixlen arrays
630  return (IS_STRING(type) && compression != kENCODING_DICT) || type == kARRAY ||
631  IS_GEO(type);
632  }
633 
634  // need this here till is_varlen can be fixed w/o negative impact to existing code
635  inline bool is_varlen_indeed() const {
636  // SQLTypeInfo.is_varlen() is broken with fixedlen array now
637  // and seems left broken for some concern, so fix it locally
638  return is_varlen() && !is_fixlen_array();
639  }
640 
641  inline bool is_dict_encoded_string() const {
642  return is_string() && compression == kENCODING_DICT;
643  }
644 
645  inline bool is_none_encoded_string() const {
646  return is_string() && compression == kENCODING_NONE;
647  }
648 
649  inline bool is_subtype_dict_encoded_string() const {
651  }
652 
653  inline bool is_dict_encoded_type() const {
654  return is_dict_encoded_string() ||
656  }
657 
658  inline bool is_dict_intersection() const {
659  return dict_intersection;
660  }
661 
662  inline bool has_same_itemtype(const SQLTypeInfo& other) const {
663  if ((is_column() || is_column_list()) &&
664  (other.is_column() || other.is_column_list())) {
665  return subtype == other.get_subtype() &&
667  compression == other.get_compression());
668  }
669  return subtype == other.get_subtype();
670  }
671 
672  HOST DEVICE inline bool operator!=(const SQLTypeInfo& rhs) const {
673  return type != rhs.get_type() || subtype != rhs.get_subtype() ||
674  dimension != rhs.get_dimension() || scale != rhs.get_scale() ||
675  compression != rhs.get_compression() ||
678  notnull != rhs.get_notnull() || dict_key_ != rhs.dict_key_;
679  }
680  HOST DEVICE inline bool operator==(const SQLTypeInfo& rhs) const {
681  return type == rhs.get_type() && subtype == rhs.get_subtype() &&
682  dimension == rhs.get_dimension() && scale == rhs.get_scale() &&
683  compression == rhs.get_compression() &&
686  notnull == rhs.get_notnull() && dict_key_ == rhs.dict_key_;
687  }
688 
689  inline int get_array_context_logical_size() const {
690  if (is_string()) {
691  auto comp_type(get_compression());
692  if (comp_type == kENCODING_DICT || comp_type == kENCODING_FIXED ||
693  comp_type == kENCODING_NONE) {
694  return sizeof(int32_t);
695  }
696  }
697  return get_logical_size();
698  }
699 
700  HOST DEVICE inline void operator=(const SQLTypeInfo& rhs) {
701  type = rhs.get_type();
702  subtype = rhs.get_subtype();
703  dimension = rhs.get_dimension();
704  scale = rhs.get_scale();
705  notnull = rhs.get_notnull();
707  comp_param = rhs.get_comp_param();
708  size = rhs.get_size();
709  dict_key_ = rhs.dict_key_;
711  }
712 
713  inline bool is_castable(const SQLTypeInfo& new_type_info) const {
714  // can always cast between the same type but different precision/scale/encodings
715  if (type == new_type_info.get_type()) {
716  return true;
717  // can always cast between strings
718  } else if (is_string() && new_type_info.is_string()) {
719  return true;
720  } else if (is_string() && !new_type_info.is_string()) {
721  return false;
722  } else if (!is_string() && new_type_info.is_string()) {
723  return true;
724  // can cast between numbers
725  } else if (is_number() && new_type_info.is_number()) {
726  return true;
727  // can cast from timestamp or date to number (epoch)
728  } else if ((type == kTIMESTAMP || type == kDATE) && new_type_info.is_number()) {
729  return true;
730  // can cast from number (epoch) to timestamp, date, or time
731  } else if (is_number() && new_type_info.is_time()) {
732  return true;
733  // can cast from date to timestamp
734  } else if (type == kDATE && new_type_info.get_type() == kTIMESTAMP) {
735  return true;
736  } else if (type == kTIMESTAMP && new_type_info.get_type() == kDATE) {
737  return true;
738  } else if (type == kTIMESTAMP && new_type_info.get_type() == kTIME) {
739  return true;
740  } else if (type == kBOOLEAN && new_type_info.is_number()) {
741  return true;
742  } else if (type == kARRAY && new_type_info.get_type() == kARRAY) {
743  return get_elem_type().is_castable(new_type_info.get_elem_type());
744  } else if (type == kCOLUMN && new_type_info.get_type() == kCOLUMN) {
745  return get_elem_type().is_castable(new_type_info.get_elem_type());
746  } else if (type == kCOLUMN_LIST && new_type_info.get_type() == kCOLUMN_LIST) {
747  return get_elem_type().is_castable(new_type_info.get_elem_type());
748  } else {
749  return false;
750  }
751  }
752 
761  inline bool is_numeric_scalar_auto_castable(const SQLTypeInfo& new_type_info) const {
762  const auto& new_type = new_type_info.get_type();
763  switch (type) {
764  case kBOOLEAN:
765  return new_type == kBOOLEAN;
766  case kTINYINT:
767  case kSMALLINT:
768  case kINT:
769  if (!new_type_info.is_number()) {
770  return false;
771  }
772  if (new_type_info.is_fp()) {
773  // We can lose precision here, but preserving existing behavior
774  return true;
775  }
776  return new_type_info.get_logical_size() >= get_logical_size();
777  case kBIGINT:
778  return new_type == kBIGINT || new_type == kDOUBLE || new_type == kFLOAT;
779  case kFLOAT:
780  case kDOUBLE:
781  if (!new_type_info.is_fp()) {
782  return false;
783  }
784  return (new_type_info.get_logical_size() >= get_logical_size());
785  case kDECIMAL:
786  case kNUMERIC:
787  switch (new_type) {
788  case kDECIMAL:
789  case kNUMERIC:
790  return new_type_info.get_dimension() >= get_dimension();
791  case kDOUBLE:
792  return true;
793  case kFLOAT:
794  return get_dimension() <= 7;
795  default:
796  return false;
797  }
798  case kTIMESTAMP:
799  if (new_type != kTIMESTAMP) {
800  return false;
801  }
802  return new_type_info.get_dimension() >= get_dimension();
803  case kDATE:
804  return new_type == kDATE;
805  case kTIME:
806  return new_type == kTIME;
807  default:
808  UNREACHABLE();
809  return false;
810  }
811  }
812 
822  inline int32_t get_numeric_scalar_scale() const {
823  CHECK(type == kBOOLEAN || type == kTINYINT || type == kSMALLINT || type == kINT ||
824  type == kBIGINT || type == kFLOAT || type == kDOUBLE || type == kDECIMAL ||
825  type == kNUMERIC || type == kTIMESTAMP || type == kDATE || type == kTIME);
826  switch (type) {
827  case kBOOLEAN:
828  return 1;
829  case kTINYINT:
830  case kSMALLINT:
831  case kINT:
832  case kBIGINT:
833  case kFLOAT:
834  case kDOUBLE:
835  return get_logical_size();
836  case kDECIMAL:
837  case kNUMERIC:
838  if (get_dimension() > 7) {
839  return 8;
840  } else {
841  return 4;
842  }
843  case kTIMESTAMP:
844  switch (get_dimension()) {
845  case 9:
846  return 8;
847  case 6:
848  return 4;
849  case 3:
850  return 2;
851  case 0:
852  return 1;
853  default:
854  UNREACHABLE();
855  }
856  case kDATE:
857  return 1;
858  case kTIME:
859  return 1;
860  default:
861  UNREACHABLE();
862  return 0;
863  }
864  }
865 
866  HOST DEVICE inline bool is_null(const Datum& d) const {
867  // assuming Datum is always uncompressed
868  switch (type) {
869  case kBOOLEAN:
870  return (int8_t)d.boolval == NULL_BOOLEAN;
871  case kTINYINT:
872  return d.tinyintval == NULL_TINYINT;
873  case kSMALLINT:
874  return d.smallintval == NULL_SMALLINT;
875  case kINT:
876  return d.intval == NULL_INT;
877  case kBIGINT:
878  case kNUMERIC:
879  case kDECIMAL:
880  return d.bigintval == NULL_BIGINT;
881  case kFLOAT:
882  return d.floatval == NULL_FLOAT;
883  case kDOUBLE:
884  return d.doubleval == NULL_DOUBLE;
885  case kTIME:
886  case kTIMESTAMP:
887  case kDATE:
888  return d.bigintval == NULL_BIGINT;
889  case kTEXT:
890  case kVARCHAR:
891  case kCHAR:
892  // @TODO handle null strings
893  break;
894  case kNULLT:
895  return true;
896  case kARRAY:
897  return d.arrayval == NULL || d.arrayval->is_null;
898  default:
899  break;
900  }
901  return false;
902  }
903  HOST DEVICE inline bool is_null(const int8_t* val) const {
904  if (type == kFLOAT) {
905  return *(float*)val == NULL_FLOAT;
906  }
907  if (type == kDOUBLE) {
908  return *(double*)val == NULL_DOUBLE;
909  }
910  // val can be either compressed or uncompressed
911  switch (size) {
912  case 1:
913  return *val == NULL_TINYINT;
914  case 2:
915  return *(int16_t*)val == NULL_SMALLINT;
916  case 4:
917  return *(int32_t*)val == NULL_INT;
918  case 8:
919  return *(int64_t*)val == NULL_BIGINT;
920  case kNULLT:
921  return true;
922  default:
923  // @TODO(wei) handle null strings
924  break;
925  }
926  return false;
927  }
928  HOST DEVICE inline bool is_null_fixlen_array(const int8_t* val, int array_size) const {
929  // Check if fixed length array has a NULL_ARRAY sentinel as the first element
930  if (type == kARRAY && val && array_size > 0 && array_size == size) {
931  // Need to create element type to get the size, but can't call get_elem_type()
932  // since this is a HOST DEVICE function. Going through copy constructor instead.
933  auto elem_ti{*this};
934  elem_ti.set_type(subtype);
935  elem_ti.set_subtype(kNULLT);
936  auto elem_size = elem_ti.get_storage_size();
937  if (elem_size < 1) {
938  return false;
939  }
940  if (subtype == kFLOAT) {
941  return *(float*)val == NULL_ARRAY_FLOAT;
942  }
943  if (subtype == kDOUBLE) {
944  return *(double*)val == NULL_ARRAY_DOUBLE;
945  }
946  switch (elem_size) {
947  case 1:
948  return *val == NULL_ARRAY_TINYINT;
949  case 2:
950  return *(int16_t*)val == NULL_ARRAY_SMALLINT;
951  case 4:
952  return *(int32_t*)val == NULL_ARRAY_INT;
953  case 8:
954  return *(int64_t*)val == NULL_ARRAY_BIGINT;
955  default:
956  return false;
957  }
958  }
959  return false;
960  }
961  HOST DEVICE inline bool is_null_point_coord_array(const int8_t* val,
962  int array_size) const {
963  if (type == kARRAY && subtype == kTINYINT && val && array_size > 0 &&
964  array_size == size) {
965  if (array_size == 2 * sizeof(double)) {
966  return *(double*)val == NULL_ARRAY_DOUBLE;
967  }
968  if (array_size == 2 * sizeof(int32_t)) {
969  return *(uint32_t*)val == NULL_ARRAY_COMPRESSED_32;
970  }
971  }
972  return false;
973  }
974 
975  inline SQLTypeInfo get_elem_type() const {
976  SQLTypeInfo type_info = *this;
977  if ((type == kCOLUMN || type == kCOLUMN_LIST) && compression == kENCODING_ARRAY) {
978  type_info.set_type(kARRAY);
979  type_info.set_compression(kENCODING_NONE);
980  } else if ((type == kCOLUMN || type == kCOLUMN_LIST) &&
982  type_info.set_type(kARRAY);
983  type_info.set_compression(kENCODING_DICT);
984  } else if ((type == kCOLUMN || type == kCOLUMN_LIST) && IS_GEO(subtype)) {
985  type_info.set_type(subtype);
986  type_info.set_subtype(kGEOMETRY);
987  } else if (IS_GEO(type)) {
988  if (type_info.get_compression() == kENCODING_GEOINT) {
989  type_info.set_type(kINT);
990  type_info.set_compression(kENCODING_NONE);
991  } else {
992  type_info.set_type(kDOUBLE);
993  }
994  type_info.set_subtype(kNULLT);
995  } else if (type == kARRAY) {
996  type_info.set_type(subtype);
997  type_info.set_subtype(kNULLT);
998  type_info.set_notnull(false);
999  type_info.setUsesFlatBuffer(false);
1000  } else {
1001  type_info.set_type(subtype);
1002  type_info.set_subtype(kNULLT);
1003  }
1004  type_info.setStorageSize();
1005  return type_info;
1006  }
1007 
1008  inline SQLTypeInfo get_array_type() const {
1009  SQLTypeInfo type_info = *this;
1010  type_info.set_type(kARRAY);
1011  type_info.set_subtype(type);
1012  type_info.setStorageSize();
1013  return type_info;
1014  }
1015 
1016  inline bool is_date_in_days() const {
1017  if (type == kDATE) {
1018  const auto comp_type = get_compression();
1019  if (comp_type == kENCODING_DATE_IN_DAYS) {
1020  return true;
1021  }
1022  }
1023  return false;
1024  }
1025 
1026  inline bool is_date() const {
1027  return type == kDATE;
1028  }
1029 
1030  inline bool is_time_or_date() const {
1031  return type == kDATE || type == kTIME || type == kTIMESTAMP;
1032  }
1033 
1034  inline bool is_high_precision_timestamp() const {
1035  if (type == kTIMESTAMP) {
1036  const auto dimension = get_dimension();
1037  if (dimension > 0) {
1038  return true;
1039  }
1040  }
1041  return false;
1042  }
1043 
1044  inline bool is_timestamp() const {
1045  return type == kTIMESTAMP;
1046  }
1047  inline bool is_encoded_timestamp() const {
1048  return is_timestamp() && compression == kENCODING_FIXED;
1049  }
1050 
1052  size = get_storage_size();
1053  }
1054 
1056  // If comp_param is set, it should equal dict_id.
1058  return dict_key_;
1059  }
1060 
1061  void setStringDictKey(const shared::StringDictKey& dict_key) {
1062  dict_key_ = dict_key;
1063  // If comp_param is set, it should equal dict_id.
1065  }
1066 
1067  // TODO: Remove below *SkipCompParamCheck methods as part of comp_param refactor
1069  return dict_key_;
1070  }
1071 
1073  dict_key_ = dict_key;
1074  }
1075 
1076  // a column or an ouput column of this type may use FlatBuffer storage.
1077  inline void setUsesFlatBuffer(bool uses_flatbuffer = true) {
1078  uses_flatbuffer_ = uses_flatbuffer;
1079  }
1080 
1081  inline bool usesFlatBuffer() const {
1082  return uses_flatbuffer_;
1083  }
1084 
1085  // Checks if a column of this type can use FlatBuffer storage
1086  inline bool supportsFlatBuffer() const {
1087  switch (type) {
1088  case kARRAY:
1089  case kPOINT:
1090  case kLINESTRING:
1091  case kPOLYGON:
1092  case kMULTIPOINT:
1093  case kMULTILINESTRING:
1094  case kMULTIPOLYGON:
1095  return true;
1096  case kTEXT:
1097  return get_compression() == kENCODING_NONE;
1098  case kCOLUMN:
1099  case kCOLUMN_LIST:
1100  // calling supportsFlatBuffer on a column type is not meaningful
1101  UNREACHABLE();
1102  default:;
1103  }
1104  return false;
1105  }
1106 
1108  SQLTypeInfoLite ti_lite;
1109  switch (type) {
1110  case kPOINT:
1111  ti_lite.type = SQLTypeInfoLite::POINT;
1113  break;
1114  case kLINESTRING:
1117  break;
1118  case kPOLYGON:
1119  ti_lite.type = SQLTypeInfoLite::POLYGON;
1121  break;
1122  case kMULTIPOINT:
1125  break;
1126  case kMULTILINESTRING:
1129  break;
1130  case kMULTIPOLYGON:
1133  break;
1134  case kTEXT:
1135  ti_lite.type = SQLTypeInfoLite::TEXT;
1137  break;
1138  case kARRAY:
1139  ti_lite.type = SQLTypeInfoLite::ARRAY;
1140  switch (subtype) {
1141  case kBOOLEAN:
1143  break;
1144  case kTINYINT:
1146  break;
1147  case kSMALLINT:
1149  break;
1150  case kINT:
1151  ti_lite.subtype = SQLTypeInfoLite::INT;
1152  break;
1153  case kBIGINT:
1154  ti_lite.subtype = SQLTypeInfoLite::BIGINT;
1155  break;
1156  case kFLOAT:
1157  ti_lite.subtype = SQLTypeInfoLite::FLOAT;
1158  break;
1159  case kDOUBLE:
1160  ti_lite.subtype = SQLTypeInfoLite::DOUBLE;
1161  break;
1162  case kTEXT:
1163  ti_lite.subtype = SQLTypeInfoLite::TEXT;
1164  break;
1165  default:
1166  UNREACHABLE();
1167  }
1168  break;
1169  default:
1170  UNREACHABLE();
1171  }
1172  if (is_geometry()) {
1173  switch (get_compression()) {
1174  case kENCODING_NONE:
1176  break;
1177  case kENCODING_GEOINT:
1179  break;
1180  default:
1181  UNREACHABLE();
1182  }
1183  ti_lite.dimension = get_input_srid();
1184  ti_lite.scale = get_output_srid();
1185  ti_lite.db_id = 0; // unused
1186  ti_lite.dict_id = 0; // unused
1187  } else if (type == kTEXT) {
1188  switch (get_compression()) {
1189  case kENCODING_NONE:
1191  break;
1192  case kENCODING_DICT:
1194  break;
1195  default:
1196  UNREACHABLE();
1197  }
1198  ti_lite.dimension = 0; // unused
1199  ti_lite.scale = 0; // unused
1200  ti_lite.db_id = dict_key_.db_id;
1201  ti_lite.dict_id = dict_key_.dict_id;
1202  } else if (type == kARRAY) {
1203  if (subtype == kTEXT) {
1204  switch (get_compression()) {
1205  case kENCODING_NONE:
1207  break;
1208  case kENCODING_DICT:
1210  break;
1211  default:
1212  UNREACHABLE();
1213  }
1214  }
1215  ti_lite.dimension = 0; // unused
1216  ti_lite.scale = 0; // unused
1217  ti_lite.db_id = dict_key_.db_id;
1218  ti_lite.dict_id = dict_key_.dict_id;
1219  } else {
1220  UNREACHABLE();
1221  }
1222  return ti_lite;
1223  }
1224 
1226  SQLTypes sql_value_type =
1227  ((type == kCOLUMN || type == kCOLUMN_LIST || type == kARRAY) ? subtype : type);
1228  switch (sql_value_type) {
1229  case kPOINT:
1230  case kLINESTRING:
1231  case kPOLYGON:
1232  case kMULTIPOINT:
1233  case kMULTILINESTRING:
1234  case kMULTIPOLYGON:
1237  case kBOOLEAN:
1238  return FlatBufferManager::Bool8;
1239  case kTINYINT:
1240  return FlatBufferManager::Int8;
1241  case kSMALLINT:
1242  return FlatBufferManager::Int16;
1243  case kINT:
1244  return FlatBufferManager::Int32;
1245  case kBIGINT:
1246  return FlatBufferManager::Int64;
1247  case kFLOAT:
1249  case kDOUBLE:
1251  case kTEXT: {
1252  switch (get_compression()) {
1253  case kENCODING_NONE:
1254  return FlatBufferManager::Int8;
1255  case kENCODING_DICT:
1256  return FlatBufferManager::Int32;
1257  default:
1258  UNREACHABLE();
1259  }
1260  } break;
1261  default:
1262  UNREACHABLE();
1263  }
1264  return {};
1265  }
1266 
1267  private:
1268  SQLTypes type; // type id
1269  SQLTypes subtype; // element type of arrays or columns
1270  int dimension; // VARCHAR/CHAR length or NUMERIC/DECIMAL precision or COLUMN_LIST
1271  // length or TIMESTAMP precision
1272  int scale; // NUMERIC/DECIMAL scale
1273  bool notnull; // nullable? a hint, not used for type checking
1274  EncodingType compression; // compression scheme
1275  int comp_param; // compression parameter when applicable for certain schemes
1276  int size; // size of the type in bytes. -1 for variable size
1277  bool dict_intersection{false};
1278 #ifndef __CUDACC__
1279  static std::string type_name[kSQLTYPE_LAST];
1280  static std::string comp_name[kENCODING_LAST];
1281 #endif
1283  bool uses_flatbuffer_{false};
1284  HOST DEVICE inline int get_storage_size() const {
1285  switch (type) {
1286  case kBOOLEAN:
1287  return sizeof(int8_t);
1288  case kTINYINT:
1289  return sizeof(int8_t);
1290  case kSMALLINT:
1291  switch (compression) {
1292  case kENCODING_NONE:
1293  return sizeof(int16_t);
1294  case kENCODING_FIXED:
1295  case kENCODING_SPARSE:
1296  return comp_param / 8;
1297  case kENCODING_RL:
1298  case kENCODING_DIFF:
1299  break;
1300  default:
1301  assert(false);
1302  }
1303  break;
1304  case kINT:
1305  switch (compression) {
1306  case kENCODING_NONE:
1307  return sizeof(int32_t);
1308  case kENCODING_FIXED:
1309  case kENCODING_SPARSE:
1310  case kENCODING_GEOINT:
1311  return comp_param / 8;
1312  case kENCODING_RL:
1313  case kENCODING_DIFF:
1314  break;
1315  default:
1316  assert(false);
1317  }
1318  break;
1319  case kBIGINT:
1320  case kNUMERIC:
1321  case kDECIMAL:
1322  switch (compression) {
1323  case kENCODING_NONE:
1324  return sizeof(int64_t);
1325  case kENCODING_FIXED:
1326  case kENCODING_SPARSE:
1327  return comp_param / 8;
1328  case kENCODING_RL:
1329  case kENCODING_DIFF:
1330  break;
1331  default:
1332  assert(false);
1333  }
1334  break;
1335  case kFLOAT:
1336  switch (compression) {
1337  case kENCODING_NONE:
1338  return sizeof(float);
1339  case kENCODING_FIXED:
1340  case kENCODING_RL:
1341  case kENCODING_DIFF:
1342  case kENCODING_SPARSE:
1343  assert(false);
1344  break;
1345  default:
1346  assert(false);
1347  }
1348  break;
1349  case kDOUBLE:
1350  switch (compression) {
1351  case kENCODING_NONE:
1352  return sizeof(double);
1353  case kENCODING_FIXED:
1354  case kENCODING_RL:
1355  case kENCODING_DIFF:
1356  case kENCODING_SPARSE:
1357  assert(false);
1358  break;
1359  default:
1360  assert(false);
1361  }
1362  break;
1363  case kTIMESTAMP:
1364  case kTIME:
1365  case kINTERVAL_DAY_TIME:
1366  case kINTERVAL_YEAR_MONTH:
1367  case kDATE:
1368  switch (compression) {
1369  case kENCODING_NONE:
1370  return sizeof(int64_t);
1371  case kENCODING_FIXED:
1372  if (type == kTIMESTAMP && dimension > 0) {
1373  assert(false); // disable compression for timestamp precisions
1374  }
1375  return comp_param / 8;
1376  case kENCODING_RL:
1377  case kENCODING_DIFF:
1378  case kENCODING_SPARSE:
1379  assert(false);
1380  break;
1382  switch (comp_param) {
1383  case 0:
1384  return 4; // Default date encoded in days is 32 bits
1385  case 16:
1386  case 32:
1387  return comp_param / 8;
1388  default:
1389  assert(false);
1390  break;
1391  }
1392  default:
1393  assert(false);
1394  }
1395  break;
1396  case kTEXT:
1397  case kVARCHAR:
1398  case kCHAR:
1399  if (compression == kENCODING_DICT) {
1400  return sizeof(int32_t); // @TODO(wei) must check DictDescriptor
1401  }
1402  break;
1403  case kARRAY:
1404  // TODO: return size for fixlen arrays?
1405  break;
1406  case kPOINT:
1407  case kMULTIPOINT:
1408  case kLINESTRING:
1409  case kMULTILINESTRING:
1410  case kPOLYGON:
1411  case kMULTIPOLYGON:
1412  case kCOLUMN:
1413  case kCOLUMN_LIST:
1414  break;
1415  default:
1416  break;
1417  }
1418  return -1;
1419  }
1420 };
1421 
1423 
1425 
1426 #ifndef __CUDACC__
1427 #include <string_view>
1428 
1429 Datum NullDatum(const SQLTypeInfo& ti);
1430 bool IsNullDatum(const Datum d, const SQLTypeInfo& ti);
1431 Datum StringToDatum(const std::string_view s, SQLTypeInfo& ti);
1432 std::string DatumToString(const Datum d, const SQLTypeInfo& ti);
1433 int64_t extract_int_type_from_datum(const Datum datum, const SQLTypeInfo& ti);
1434 double extract_fp_type_from_datum(const Datum datum, const SQLTypeInfo& ti);
1435 bool DatumEqual(const Datum, const Datum, const SQLTypeInfo& ti);
1436 int64_t convert_decimal_value_to_scale(const int64_t decimal_value,
1437  const SQLTypeInfo& type_info,
1438  const SQLTypeInfo& new_type_info);
1439 #endif
1440 
1441 #ifdef HAVE_TOSTRING
1442 inline std::ostream& operator<<(std::ostream& os, const SQLTypeInfo& type_info) {
1443  os << toString(type_info);
1444  return os;
1445 }
1446 #endif
1447 
1448 #include "../QueryEngine/DateAdd.h"
1449 #include "../QueryEngine/DateTruncate.h"
1450 #include "../QueryEngine/ExtractFromTime.h"
1451 
1452 inline SQLTypes get_int_type_by_size(size_t const nbytes) {
1453  switch (nbytes) {
1454  case 1:
1455  return kTINYINT;
1456  case 2:
1457  return kSMALLINT;
1458  case 4:
1459  return kINT;
1460  case 8:
1461  return kBIGINT;
1462  default:
1463 #if !(defined(__CUDACC__) || defined(NO_BOOST))
1464  UNREACHABLE() << "Invalid number of bytes=" << nbytes;
1465 #endif
1466  return {};
1467  }
1468 }
1469 
1471  EncodingType encoding = type_info.get_compression();
1472  if (encoding == kENCODING_DATE_IN_DAYS ||
1473  (encoding == kENCODING_FIXED && type_info.get_type() != kARRAY)) {
1474  encoding = kENCODING_NONE;
1475  }
1476  auto type_info_copy = type_info;
1477  type_info_copy.set_compression(encoding);
1478  type_info_copy.setStorageSize();
1479  return type_info_copy;
1480 }
1481 
1483  SQLTypeInfo nullable_type_info = type_info;
1484  nullable_type_info.set_notnull(false);
1485  return nullable_type_info;
1486 }
1487 
1489  SQLTypeInfo nullable_type_info = get_logical_type_info(type_info);
1490  return get_nullable_type_info(nullable_type_info);
1491 }
1492 
1493 using StringOffsetT = int32_t;
1494 using ArrayOffsetT = int32_t;
1495 
1496 int8_t* append_datum(int8_t* buf, const Datum& d, const SQLTypeInfo& ti);
1497 
1498 // clang-format off
1499 /*
1500 
1501 A note on representing collection types using SQLTypeInfo
1502 =========================================================
1503 
1504 In general, a collection type is a type of collection of items. A
1505 collection can be an array, a column, or a column list. A column list
1506 is as collection of columns that have the same item type. An item can
1507 be of scalar type (bool, integers, floats, text encoding dict's, etc)
1508 or of collection type (array of scalars, column of scalars, column of
1509 array of scalars).
1510 
1511 SQLTypeInfo provides a structure to represent both item and collection
1512 types using the following list of attributes:
1513  SQLTypes type
1514  SQLTypes subtype
1515  int dimension
1516  int scale
1517  bool notnull
1518  EncodingType compression
1519  int comp_param
1520  int size
1521 
1522 To represent a particular type, not all attributes are used. However,
1523 there may exists multiple ways to represent the same type using
1524 various combinations of these attributes and this note can be used as
1525 a guideline to how to represent a newly introduced collection type
1526 using the SQLTypeInfo structure.
1527 
1528 Scalar types
1529 ------------
1530 
1531 - Scalar types are booleans, integers, and floats that are defined
1532  by type and size attributes,
1533 
1534  SQLTypeInfo(type=kSCALAR)
1535 
1536  where SCALAR is in {BOOL, BIGINT, INT, SMALLINT, TINYINT, DOUBLE,
1537  FLOAT} while the corresponding size is specified in
1538  get_storage_size(). For example, SQLTypeInfo(type=kFLOAT)
1539  represents FLOAT and its size is implemented as 4 in the
1540  get_storage_size() method,
1541 
1542 - Text encoding dict (as defined as index and string dictionary) is
1543  represented as a 32-bit integer value and its type is specified as
1544 
1545  SQLTypeInfo(type=kTEXT, compression=kENCODING_DICT, comp_param=<dict id>)
1546 
1547  and size is defined as 4 by get_storage_size().
1548 
1549 Collection types
1550 ----------------
1551 
1552 - The type of a varlen array of scalar items is specified as
1553 
1554  SQLTypeInfo(type=kARRAY, subtype=kSCALAR)
1555 
1556  and size is defined as -1 by get_storage_size() which can be interpreted as N/A.
1557 
1558 - The type of a varlen array of text encoding dict is specified as
1559 
1560  SQLTypeInfo(type=kARRAY, subtype=kTEXT, compression=kENCODING_DICT, comp_param=<dict id>)
1561 
1562  Notice that the compression and comp_param attributes apply to
1563  subtype rather than to type. This quirk exemplifies the fact that
1564  SQLTypeInfo provides limited ability to support composite types.
1565 
1566 - Similarly, the types of a column of scalar and text encoded dict
1567  items are specified as
1568 
1569  SQLTypeInfo(type=kCOLUMN, subtype=kSCALAR)
1570 
1571  and
1572 
1573  SQLTypeInfo(type=kCOLUMN, subtype=kTEXT, compression=kENCODING_DICT, comp_param=<dict id>)
1574 
1575  respectively.
1576 
1577 - The type of column list with scalar items is specified as
1578 
1579  SQLTypeInfo(type=kCOLUMN_LIST, subtype=kSCALAR, dimension=<nof columns>)
1580 
1581  WARNING: Column list with items that type use compression (such as
1582  TIMESTAMP), cannot be supported! See QE-427.
1583 
1584 - The type of column list with text encoded dict items is specified as
1585 
1586  SQLTypeInfo(type=kCOLUMN_LIST, subtype=kTEXT, compression=kENCODING_DICT, dimension=<nof columns>)
1587 
1588 - The type of a column of arrays of scalar items is specified as
1589 
1590  SQLTypeInfo(type=kCOLUMN, subtype=kSCALAR, compression=kENCODING_ARRAY)
1591 
1592  Notice that the "a collection of collections of items" is specified
1593  by introducing a new compression scheme that descibes the
1594  "collections" part while the subtype attribute specifies the type of
1595  items.
1596 
1597 - The type of a column of arrays of text encoding dict items is specified as
1598 
1599  SQLTypeInfo(type=kCOLUMN, subtype=kTEXT, compression=kENCODING_ARRAY_DICT, comp_param=<dict id>)
1600 
1601  where the compression attribute kENCODING_ARRAY_DICT carries two
1602  pieces of information: (i) the items type is dict encoded string and
1603  (ii) the type represents a "column of arrays".
1604 
1605 
1606 - The type of a column list of arrays of scalar items is specified as
1607 
1608  SQLTypeInfo(type=kCOLUMN_LIST, subtype=kSCALAR, compression=kENCODING_ARRAY, dimension=<nof columns>)
1609 
1610 - The type of a column list of arrays of text encoding dict items is specified as
1611 
1612  SQLTypeInfo(type=kCOLUMN_LIST, subtype=kTEXT, compression=kENCODING_ARRAY_DICT, comp_param=<dict id>, dimension=<nof columns>)
1613 
1614  that is the most complicated currently supported type of "a
1615  collection(=list) of collections(=columns) of collections(=arrays)
1616  of items(=text)" with a specified compression scheme and comp_param
1617  attributes.
1618 
1619 - The type of a column of geometru points is specified as
1620 
1621  SQLTypeInfo(type=kCOLUMN, subtype=kPOINT, dimension=<input srid>, scale=<output srid>, compression=<kENCODING_NONE|kENCODING_GEOINT>)
1622 
1623 
1624 */
1625 // clang-format on
1626 
1627 inline auto generate_column_type(const SQLTypeInfo& elem_ti) {
1628  SQLTypes elem_type = elem_ti.get_type();
1629  if (elem_type == kCOLUMN) {
1630  if (elem_ti.get_subtype() == kVARCHAR) {
1631  auto new_elem_ti = elem_ti;
1632  new_elem_ti.set_subtype(kTEXT);
1633  return new_elem_ti;
1634  }
1635  return elem_ti;
1636  }
1637  auto c = elem_ti.get_compression();
1638  auto d = elem_ti.get_dimension();
1639  auto s = elem_ti.get_scale();
1640  auto p = elem_ti.get_comp_param();
1641  switch (elem_type) {
1642  case kBOOLEAN:
1643  case kTINYINT:
1644  case kSMALLINT:
1645  case kINT:
1646  case kBIGINT:
1647  case kFLOAT:
1648  case kDOUBLE:
1649  if (c == kENCODING_NONE && p == 0) {
1650  break; // here and below `break` means supported element type
1651  // for extension functions
1652  }
1653  case kPOINT:
1654  case kLINESTRING:
1655  case kPOLYGON:
1656  case kMULTIPOINT:
1657  case kMULTILINESTRING:
1658  case kMULTIPOLYGON:
1659  if (c == kENCODING_NONE && p == 0) {
1660  break;
1661  }
1662  if (c == kENCODING_GEOINT && p == 32) {
1663  break;
1664  }
1665  case kTEXT:
1666  case kVARCHAR:
1667  elem_type = kTEXT;
1668  if (c == kENCODING_DICT) {
1669  break;
1670  }
1671  case kTIMESTAMP:
1672  if (c == kENCODING_NONE && p == 0 && (d == 9 || d == 6 || d == 0)) {
1673  break;
1674  }
1675  case kARRAY:
1676  elem_type = elem_ti.get_subtype();
1677  if (IS_NUMBER(elem_type) || elem_type == kBOOLEAN || elem_type == kTEXT) {
1678  if (c == kENCODING_NONE && p == 0) {
1679  c = kENCODING_ARRAY;
1680  break;
1681  } else if (c == kENCODING_DICT) {
1683  break;
1684  }
1685  }
1686  default:
1687  elem_type = kNULLT; // indicates unsupported element type that
1688  // the caller needs to handle accordingly
1689  }
1690  auto ti = SQLTypeInfo(kCOLUMN, c, p, elem_type);
1691  ti.set_dimension(d);
1692  if (c == kENCODING_DICT) {
1693  ti.setStringDictKey(elem_ti.getStringDictKey());
1694  }
1695  ti.set_scale(s);
1696  return ti;
1697 }
1698 
1699 inline auto generate_column_list_type(const SQLTypeInfo& elem_ti) {
1700  auto type_info = generate_column_type(elem_ti);
1701  if (type_info.get_subtype() != kNULLT) {
1702  type_info.set_type(kCOLUMN_LIST);
1703  }
1704  if (type_info.get_subtype() == kTIMESTAMP) {
1705  // ColumnList<Timestamp> is not supported, see QE-472
1706  type_info.set_subtype(kNULLT);
1707  }
1708  return type_info;
1709 }
1710 
1711 // SQLTypeInfo-friendly interface to FlatBuffer:
1712 
1713 // ChunkIter_get_nth variant for array buffers using FlatBuffer storage schema:
1714 DEVICE inline void VarlenArray_get_nth(int8_t* buf,
1715  int n,
1716  ArrayDatum* result,
1717  bool* is_end) {
1718  FlatBufferManager m{buf};
1719  FlatBufferManager::Status status{};
1720  if (m.isNestedArray()) {
1722  status = m.getItem(n, item);
1723  if (status == FlatBufferManager::Status::Success) {
1724  result->length = item.nof_values * m.getValueSize();
1725  result->pointer = item.values;
1726  result->is_null = item.is_null;
1727  *is_end = false;
1728  } else {
1729  result->length = 0;
1730  result->pointer = NULL;
1731  result->is_null = true;
1732  *is_end = true;
1733 #ifndef __CUDACC__
1734  // out of range indexing is equivalent to returning NULL (SQL AT)
1735  CHECK_EQ(status, FlatBufferManager::Status::ItemUnspecifiedError);
1736 #endif
1737  }
1738  } else {
1739  // to be deprecated
1740  auto status = m.getItemOld(n, result->length, result->pointer, result->is_null);
1741  if (status == FlatBufferManager::Status::IndexError) {
1742  *is_end = true;
1743  result->length = 0;
1744  result->pointer = NULL;
1745  result->is_null = true;
1746  } else {
1747  *is_end = false;
1748 #ifndef __CUDACC__
1749  CHECK_EQ(status, FlatBufferManager::Status::Success);
1750 #endif
1751  }
1752  }
1753 }
1754 
1755 DEVICE inline void VarlenArray_get_nth(int8_t* buf,
1756  int n,
1757  bool uncompress,
1759  bool* is_end) {
1760  FlatBufferManager m{buf};
1761  FlatBufferManager::Status status{};
1762 #ifndef __CUDACC__
1763  CHECK(m.isNestedArray());
1764 #endif
1766  status = m.getItem(n, item);
1767  if (status == FlatBufferManager::Status::Success) {
1768  result->length = item.nof_values * m.getValueSize();
1769  result->pointer = item.values;
1770  result->is_null = item.is_null;
1771  *is_end = false;
1772 #ifndef __CUDACC__
1773  CHECK(!uncompress); // NOT IMPLEMENTED
1774 #endif
1775  } else {
1776  result->length = 0;
1777  result->pointer = NULL;
1778  result->is_null = true;
1779  *is_end = true;
1780 #ifndef __CUDACC__
1781  // out of range indexing is equivalent to returning NULL (SQL AT)
1782  CHECK_EQ(status, FlatBufferManager::Status::IndexError);
1783 #endif
1784  }
1785 }
1786 
1787 inline void getFlatBufferNDimsAndSizes(const int64_t items_count,
1788  const int64_t max_nof_values,
1789  const SQLTypeInfo& ti,
1790  size_t& ndims,
1791  int64_t& max_nof_sizes) {
1792  ndims = 0;
1793  max_nof_sizes = 0;
1794  switch (ti.get_type()) {
1795  case kPOINT:
1796  ndims = 0;
1797  break;
1798  case kARRAY:
1799  if (ti.get_subtype() == kTEXT && ti.get_compression() == kENCODING_NONE) {
1800  ndims = 2;
1801  max_nof_sizes = items_count + 2 * max_nof_values / 3;
1802  } else {
1803  ndims = 1;
1804  max_nof_sizes = items_count + max_nof_values / 3;
1805  }
1806  break;
1807  case kLINESTRING:
1808  case kMULTIPOINT:
1809  ndims = 1;
1810  max_nof_sizes = items_count + max_nof_values / 3;
1811  break;
1812  case kPOLYGON:
1813  case kMULTILINESTRING:
1814  ndims = 2;
1815  max_nof_sizes = items_count + 2 * max_nof_values / 3;
1816  break;
1817  case kMULTIPOLYGON:
1818  ndims = 3;
1819  max_nof_sizes = items_count + max_nof_values;
1820  break;
1821  case kTEXT:
1822  switch (ti.get_compression()) {
1823  case kENCODING_NONE:
1824  ndims = 1;
1825  max_nof_sizes = items_count + max_nof_values / 3;
1826  break;
1827  case kENCODING_DICT:
1828  ndims = 0;
1829  break;
1830  default:
1831  UNREACHABLE();
1832  }
1833  break;
1834  default:
1835  UNREACHABLE();
1836  }
1837 }
1838 
1839 inline int64_t getFlatBufferSize(int64_t items_count,
1840  int64_t max_nof_values,
1841  const SQLTypeInfo& ti) {
1842  if (ti.get_type() == kPOINT) {
1843  // to be deprecated
1844  FlatBufferManager::GeoPoint metadata{items_count,
1845  ti.get_input_srid(),
1846  ti.get_output_srid(),
1849  GeoPointFormatId, reinterpret_cast<const int8_t*>(&metadata));
1850  } else {
1851  size_t ndims = 0;
1852  int64_t max_nof_sizes = 0;
1853  getFlatBufferNDimsAndSizes(items_count, max_nof_values, ti, ndims, max_nof_sizes);
1855  /* ndims= */ ndims,
1856  /* total_items_count= */ items_count,
1857  /* total sizes count= */ max_nof_sizes,
1858  /* total values count= */ max_nof_values,
1859  ti.toValueType(),
1860  /* user data size= */ sizeof(SQLTypeInfoLite));
1861  }
1862 }
1863 
1864 typedef union {
1865  struct {
1866  int8_t i8;
1867  };
1868  struct {
1869  int16_t i16;
1870  };
1871  struct {
1872  int32_t i32;
1873  };
1874  struct {
1875  int64_t i64;
1876  };
1877  struct {
1878  float f32;
1879  };
1880  struct {
1881  double f64;
1882  };
1883  struct {
1884  uint32_t geoint[2];
1885  };
1886  struct {
1887  double geodouble[2];
1888  };
1889 } null_value_t;
1890 
1892  null_value_t null_value{};
1893  switch (ti.get_type()) {
1894  case kBOOLEAN:
1895  null_value.i8 = NULL_BOOLEAN;
1896  break;
1897  case kTINYINT:
1898  null_value.i8 = NULL_TINYINT;
1899  break;
1900  case kSMALLINT:
1901  null_value.i16 = NULL_SMALLINT;
1902  break;
1903  case kINT:
1904  null_value.i32 = NULL_INT;
1905  break;
1906  case kBIGINT:
1907  null_value.i64 = NULL_BIGINT;
1908  break;
1909  case kFLOAT:
1910  null_value.f32 = NULL_FLOAT;
1911  break;
1912  case kDOUBLE:
1913  null_value.f64 = NULL_DOUBLE;
1914  break;
1915  case kPOINT:
1916  case kMULTIPOINT:
1917  case kLINESTRING:
1918  case kMULTILINESTRING:
1919  case kPOLYGON:
1920  case kMULTIPOLYGON:
1921  if (ti.get_compression() == kENCODING_GEOINT) {
1922  null_value.geoint[0] = null_value.geoint[1] = NULL_ARRAY_COMPRESSED_32;
1923  } else if (ti.get_compression() == kENCODING_NONE) {
1924  null_value.geodouble[0] = null_value.geodouble[1] = NULL_ARRAY_DOUBLE;
1925  } else {
1926  UNREACHABLE();
1927  }
1928  break;
1929  case kARRAY:
1930  switch (ti.get_subtype()) {
1931  case kBOOLEAN:
1932  null_value.i8 = NULL_ARRAY_BOOLEAN;
1933  break;
1934  case kTINYINT:
1935  null_value.i8 = NULL_ARRAY_TINYINT;
1936  break;
1937  case kSMALLINT:
1938  null_value.i16 = NULL_ARRAY_SMALLINT;
1939  break;
1940  case kINT:
1941  null_value.i32 = NULL_ARRAY_INT;
1942  break;
1943  case kTIMESTAMP:
1944  case kTIME:
1945  case kDATE:
1946  case kINTERVAL_DAY_TIME:
1947  case kINTERVAL_YEAR_MONTH:
1948  case kDECIMAL:
1949  case kNUMERIC:
1950  case kBIGINT:
1951  null_value.i64 = NULL_ARRAY_BIGINT;
1952  break;
1953  case kFLOAT:
1954  null_value.f32 = NULL_ARRAY_FLOAT;
1955  break;
1956  case kDOUBLE:
1957  null_value.f64 = NULL_ARRAY_FLOAT;
1958  break;
1959  case kTEXT:
1960  if (ti.get_compression() == kENCODING_DICT) {
1961  CHECK_EQ(ti.get_logical_size(), 4);
1962  null_value.i32 = NULL_ARRAY_COMPRESSED_32;
1963  } else if (ti.get_compression() == kENCODING_NONE) {
1964  null_value.i8 = NULL_ARRAY_TINYINT;
1965  } else {
1966  UNREACHABLE();
1967  }
1968  break;
1969  default:
1970  UNREACHABLE();
1971  break;
1972  }
1973  break;
1974  case kTEXT:
1975  if (ti.get_compression() == kENCODING_DICT) {
1976  CHECK_EQ(ti.get_logical_size(), 4);
1977  null_value.i32 = NULL_INT;
1978  } else if (ti.get_compression() == kENCODING_NONE) {
1979  null_value.i32 = NULL_TINYINT;
1980  } else {
1981  UNREACHABLE();
1982  }
1983  break;
1984  default:
1985  UNREACHABLE();
1986  break;
1987  }
1988  return null_value;
1989 }
1990 
1992  int64_t items_count,
1993  int64_t max_nof_values,
1994  const SQLTypeInfo& ti) {
1995  if (ti.get_type() == kPOINT) {
1996  // to be deprecated
1997  FlatBufferManager::GeoPoint metadata{items_count,
1998  ti.get_input_srid(),
1999  ti.get_output_srid(),
2001  m.initialize(GeoPointFormatId, reinterpret_cast<const int8_t*>(&metadata));
2002  } else {
2003  size_t ndims = 0;
2004  int64_t max_nof_sizes = 0;
2005  getFlatBufferNDimsAndSizes(items_count, max_nof_values, ti, ndims, max_nof_sizes);
2006  SQLTypeInfoLite ti_lite = ti.toLite();
2007  null_value_t null_value = get_null_value(ti);
2008  int8_t* null_value_ptr = &null_value.i8;
2009  auto status = m.initializeNestedArray(
2010  /* ndims= */ ndims,
2011  /* total_items_count= */ items_count,
2012  /* total_sizes_count= */ max_nof_sizes,
2013  /* total_values_count= */ max_nof_values,
2014  ti.toValueType(),
2015  /* null value buffer=*/null_value_ptr, // null value buffer size
2016  // is defined by value type
2017  /* user data buffer=*/reinterpret_cast<const int8_t*>(&ti_lite),
2018  /* user data buffer size=*/sizeof(SQLTypeInfoLite));
2020  }
2021 }
2022 
2024  size_t index;
2027 };
2028 
2029 inline bool geo_promoted_type_match(const SQLTypes a, const SQLTypes b) {
2030  return (a == b) || (a == kPOINT && b == kMULTIPOINT) ||
2031  (a == kLINESTRING && b == kMULTILINESTRING) ||
2032  (a == kPOLYGON && b == kMULTIPOLYGON);
2033 }
int8_t tinyintval
Definition: Datum.h:71
bool geo_promoted_type_match(const SQLTypes a, const SQLTypes b)
Definition: sqltypes.h:2029
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:392
void set_compression(EncodingType c)
Definition: sqltypes.h:479
void set_size(int s)
Definition: sqltypes.h:476
static constexpr int32_t kMaxRepresentableNumericPrecision
Definition: sqltypes.h:60
#define CHECK_EQ(x, y)
Definition: Logger.h:301
#define NULL_DOUBLE
HOST DEVICE int get_size() const
Definition: sqltypes.h:403
HOST DEVICE void operator=(const SQLTypeInfo &rhs)
Definition: sqltypes.h:700
shared::StringDictKey dict_key_
Definition: sqltypes.h:1282
int8_t * append_datum(int8_t *buf, const Datum &d, const SQLTypeInfo &ti)
Definition: Datum.cpp:580
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:460
bool is_varlen_array() const
Definition: sqltypes.h:586
static constexpr int32_t kMaxNumericPrecision
Definition: sqltypes.h:58
Definition: sqltypes.h:76
bool is_text_encoding_dict_array() const
Definition: sqltypes.h:618
DEVICE constexpr bool is_cuda_compiler()
Definition: sqltypes.h:220
SQLTypes
Definition: sqltypes.h:65
std::vector< std::string > * stringsPtr
Definition: sqltypes.h:234
bool is_timestamp() const
Definition: sqltypes.h:1044
std::vector< ArrayDatum > * arraysPtr
Definition: sqltypes.h:235
#define NULL_ARRAY_INT
bool is_column_list_array() const
Definition: sqltypes.h:608
SQLTypes subtype
Definition: sqltypes_lite.h:54
const shared::StringDictKey & getStringDictKeySkipCompParamCheck() const
Definition: sqltypes.h:1068
#define NULL_FLOAT
bool is_null
Definition: Datum.h:57
#define NULL_BIGINT
bool is_time_or_date() const
Definition: sqltypes.h:1030
SQLTypeInfo get_nullable_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1488
#define LOG(tag)
Definition: Logger.h:285
HOST DEVICE bool operator==(const SQLTypeInfo &rhs) const
Definition: sqltypes.h:680
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:57
bool is_fp() const
Definition: sqltypes.h:571
HOST DEVICE int get_scale() const
Definition: sqltypes.h:396
bool is_varlen() const
Definition: sqltypes.h:629
#define NULL_ARRAY_SMALLINT
int8_t boolval
Definition: Datum.h:70
std::string get_compression_name() const
Definition: sqltypes.h:520
VarlenDatum * arrayval
Definition: Datum.h:77
#define UNREACHABLE()
Definition: Logger.h:338
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:469
Definitions for core Datum union type.
SQLTypeInfo(SQLTypes t, int d, int s)
Definition: sqltypes.h:361
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1470
void initializeFlatBuffer(FlatBufferManager &m, int64_t items_count, int64_t max_nof_values, const SQLTypeInfo &ti)
Definition: sqltypes.h:1991
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
Definition: sqltypes.h:92
#define NULL_ARRAY_TINYINT
HOST DEVICE bool is_null_fixlen_array(const int8_t *val, int array_size) const
Definition: sqltypes.h:928
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
void setStringDictKeySkipCompParamCheck(const shared::StringDictKey &dict_key)
Definition: sqltypes.h:1072
bool is_number() const
Definition: sqltypes.h:574
int32_t intval
Definition: Datum.h:73
bool is_time() const
Definition: sqltypes.h:577
std::string to_string(char const *&&v)
HostArrayDatum(size_t const l, int8_t *p, bool const n, CUSTOM_DELETER custom_deleter)
Definition: sqltypes.h:210
int8_t * pointer
Definition: Datum.h:56
#define NULL_INT
SQLTypeInfo ti
Definition: sqltypes.h:2025
int32_t StringOffsetT
Definition: sqltypes.h:1493
#define DEVICE
constexpr double a
Definition: Utm.h:32
std::conditional_t< is_cuda_compiler(), DeviceArrayDatum, HostArrayDatum > ArrayDatum
Definition: sqltypes.h:229
#define HOST
void initialize(FlatBufferFormat format_id, const int8_t *format_metadata_ptr)
Definition: FlatBuffer.h:833
EncodingType compression
Definition: sqltypes_lite.h:55
void set_input_srid(int d)
Definition: sqltypes.h:472
float floatval
Definition: Datum.h:75
std::string to_string() const
Definition: sqltypes.h:526
EncodingType
Definition: sqltypes.h:240
int get_physical_cols() const
Definition: sqltypes.h:430
bool is_fixlen_array() const
Definition: sqltypes.h:589
bool is_castable(const SQLTypeInfo &new_type_info) const
Definition: sqltypes.h:713
#define IS_INTERVAL(T)
Definition: sqltypes.h:313
void set_fixed_size()
Definition: sqltypes.h:477
std::shared_ptr< int8_t > ManagedPtr
Definition: sqltypes.h:191
HOST DEVICE bool operator!=(const SQLTypeInfo &rhs) const
Definition: sqltypes.h:672
int get_logical_size() const
Definition: sqltypes.h:419
bool DatumEqual(const Datum a, const Datum b, const SQLTypeInfo &ti)
Definition: Datum.cpp:408
static std::string type_name[kSQLTYPE_LAST]
Definition: sqltypes.h:1279
bool is_integer() const
Definition: sqltypes.h:565
bool is_subtype_dict_encoded_string() const
Definition: sqltypes.h:649
int64_t extract_int_type_from_datum(const Datum datum, const SQLTypeInfo &ti)
Definition: Datum.cpp:523
bool is_column_array() const
Definition: sqltypes.h:604
#define NULL_ARRAY_COMPRESSED_32
SQLTypes subtype
Definition: sqltypes.h:1269
bool has_same_itemtype(const SQLTypeInfo &other) const
Definition: sqltypes.h:662
bool is_text_encoding_dict() const
Definition: sqltypes.h:615
void set_scale(int s)
Definition: sqltypes.h:473
bool notnull
Definition: sqltypes.h:1273
int64_t bigintval
Definition: Datum.h:74
bool has_bounds() const
Definition: sqltypes.h:455
HostArrayDatum(size_t const l, int8_t *p, CUSTOM_DELETER custom_deleter)
Definition: sqltypes.h:204
FlatBufferManager::ValueType toValueType() const
Definition: sqltypes.h:1225
bool is_timeinterval() const
Definition: sqltypes.h:592
#define NULL_ARRAY_FLOAT
void setStorageSize()
Definition: sqltypes.h:1051
bool supportsFlatBuffer() const
Definition: sqltypes.h:1086
bool is_numeric_scalar_auto_castable(const SQLTypeInfo &new_type_info) const
returns true if the sql_type can be cast to the type specified by new_type_info with no loss of preci...
Definition: sqltypes.h:761
int64_t getFlatBufferSize(int64_t items_count, int64_t max_nof_values, const SQLTypeInfo &ti)
Definition: sqltypes.h:1839
ManagedPtr data_ptr
Definition: sqltypes.h:213
int32_t i32
Definition: sqltypes.h:1872
int is_logical_geo_type() const
Definition: sqltypes.h:411
HostArrayDatum()=default
int16_t smallintval
Definition: Datum.h:72
bool is_dict_intersection() const
Definition: sqltypes.h:658
bool is_dict_encoded_type() const
Definition: sqltypes.h:653
Datum StringToDatum(const std::string_view s, SQLTypeInfo &ti)
Definition: Datum.cpp:339
SQLTypeInfo(SQLTypes t, int d, int s, bool n)
Definition: sqltypes.h:343
bool usesFlatBuffer() const
Definition: sqltypes.h:1081
std::string toString() const
Definition: sqltypes.h:523
bool is_boolean() const
Definition: sqltypes.h:580
HostArrayDatum(size_t const l, int8_t *p, bool const n)
Definition: sqltypes.h:198
void operator()(int8_t *p)
Definition: sqltypes.h:187
SQLTypeInfo(SQLTypes t, int d, int s, bool n, EncodingType c, int p, SQLTypes st)
Definition: sqltypes.h:334
SQLTypeInfo(SQLTypes t)
Definition: sqltypes.h:371
bool IsNullDatum(const Datum datum, const SQLTypeInfo &ti)
Definition: Datum.cpp:331
#define NULL_BOOLEAN
std::string get_buffer_name() const
Definition: sqltypes.h:539
SQLTypeInfo(SQLTypes t, bool n, EncodingType c)
Definition: sqltypes.h:372
SQLTypeInfo get_array_type() const
Definition: sqltypes.h:1008
EncodingType compression
Definition: sqltypes.h:1274
Datum NullDatum(const SQLTypeInfo &ti)
Definition: Datum.cpp:288
int get_precision() const
Definition: sqltypes.h:394
void set_output_srid(int s)
Definition: sqltypes.h:474
bool is_buffer() const
Definition: sqltypes.h:621
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:561
static int64_t compute_flatbuffer_size(FlatBufferFormat format_id, const int8_t *format_metadata_ptr)
Definition: FlatBuffer.h:639
int8_t i8
Definition: sqltypes.h:1866
SQLTypeInfoLite toLite() const
Definition: sqltypes.h:1107
bool is_column() const
Definition: sqltypes.h:598
DEVICE DeviceArrayDatum()
Definition: sqltypes.h:217
HOST DEVICE bool is_null(const Datum &d) const
Definition: sqltypes.h:866
auto generate_column_type(const SQLTypeInfo &elem_ti)
Definition: sqltypes.h:1627
void set_comp_param(int p)
Definition: sqltypes.h:480
HOST DEVICE int get_storage_size() const
Definition: sqltypes.h:1284
#define CHECK_LT(x, y)
Definition: Logger.h:303
Definition: sqltypes.h:79
Definition: sqltypes.h:80
bool dict_intersection
Definition: sqltypes.h:1277
int16_t i16
Definition: sqltypes.h:1869
static std::string comp_name[kENCODING_LAST]
Definition: sqltypes.h:1280
double f64
Definition: sqltypes.h:1881
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
void setUsesFlatBuffer(bool uses_flatbuffer=true)
Definition: sqltypes.h:1077
bool is_date_in_days() const
Definition: sqltypes.h:1016
int get_array_context_logical_size() const
Definition: sqltypes.h:689
int64_t convert_decimal_value_to_scale(const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
Definition: Datum.cpp:624
auto generate_column_list_type(const SQLTypeInfo &elem_ti)
Definition: sqltypes.h:1699
bool uses_flatbuffer_
Definition: sqltypes.h:1283
int32_t ArrayOffsetT
Definition: sqltypes.h:1494
void set_dimension(int d)
Definition: sqltypes.h:470
void setStringDictKey(const shared::StringDictKey &dict_key)
Definition: sqltypes.h:1061
SQLTypes get_int_type_by_size(size_t const nbytes)
Definition: sqltypes.h:1452
bool is_none_encoded_string() const
Definition: sqltypes.h:645
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:393
static int64_t computeBufferSizeNestedArray(int64_t ndims, int64_t total_items_count, int64_t total_sizes_count, int64_t total_values_count, ValueType value_type, size_t user_data_size)
Definition: FlatBuffer.h:718
#define IS_INTEGER(T)
Definition: sqltypes.h:304
std::string get_type_name() const
Definition: sqltypes.h:482
int32_t get_numeric_scalar_scale() const
returns integer between 1 and 8 indicating what is roughly equivalent to the logical byte size of a s...
Definition: sqltypes.h:822
Definition: sqltypes.h:68
Status initializeNestedArray(int64_t ndims, int64_t total_items_count, int64_t total_sizes_count, int64_t total_values_count, ValueType value_type, const int8_t *null_value_ptr, const int8_t *user_data_ptr, size_t user_data_size)
Definition: FlatBuffer.h:743
#define IS_STRING(T)
Definition: sqltypes.h:309
void getFlatBufferNDimsAndSizes(const int64_t items_count, const int64_t max_nof_values, const SQLTypeInfo &ti, size_t &ndims, int64_t &max_nof_sizes)
Definition: sqltypes.h:1787
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:402
HOST DEVICE int get_input_srid() const
Definition: sqltypes.h:395
void set_dict_intersection()
Definition: sqltypes.h:478
#define NULL_TINYINT
#define NULL_ARRAY_DOUBLE
bool is_column_list() const
Definition: sqltypes.h:601
bool g_enable_watchdog false
Definition: Execute.cpp:80
void set_notnull(bool n)
Definition: sqltypes.h:475
#define CHECK(condition)
Definition: Logger.h:291
bool is_geometry() const
Definition: sqltypes.h:595
bool is_encoded_timestamp() const
Definition: sqltypes.h:1047
bool is_high_precision_timestamp() const
Definition: sqltypes.h:1034
SQLTypes type
Definition: sqltypes.h:1268
#define NULL_SMALLINT
V get_null_value()
double extract_fp_type_from_datum(const Datum datum, const SQLTypeInfo &ti)
Definition: Datum.cpp:549
bool is_any() const
Definition: sqltypes.h:556
HostArrayDatum(size_t const l, ManagedPtr p, bool const n)
Definition: sqltypes.h:195
#define NULL_ARRAY_BIGINT
bool is_dict_encoded_string() const
Definition: sqltypes.h:641
Definition: sqltypes.h:72
bool is_varlen_indeed() const
Definition: sqltypes.h:635
#define NULL_ARRAY_BOOLEAN
bool is_string() const
Definition: sqltypes.h:559
SQLTypeInfo(SQLTypes t, EncodingType c, int p, SQLTypes st)
Definition: sqltypes.h:352
constexpr double n
Definition: Utm.h:38
bool transforms() const
Definition: sqltypes.h:624
SQLTypeInfo(SQLTypes t, bool n)
Definition: sqltypes.h:362
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:398
int8_t * numbersPtr
Definition: sqltypes.h:233
HOST DEVICE size_t get_max_strlen() const
Definition: sqltypes.h:405
bool is_text_encoding_none() const
Definition: sqltypes.h:612
bool is_string_array() const
Definition: sqltypes.h:562
size_t index
Definition: sqltypes.h:2024
Definition: Datum.h:69
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:975
bool is_decimal() const
Definition: sqltypes.h:568
int get_physical_coord_cols() const
Definition: sqltypes.h:449
#define IS_NUMBER(T)
Definition: sqltypes.h:306
void operator()(int8_t *)
Definition: sqltypes.h:184
#define IS_GEO(T)
Definition: sqltypes.h:310
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:322
int comp_param
Definition: sqltypes.h:1275
bool is_date() const
Definition: sqltypes.h:1026
bool is_array() const
Definition: sqltypes.h:583
void set_precision(int d)
Definition: sqltypes.h:471
SQLTypeInfo get_nullable_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1482
int dimension
Definition: sqltypes.h:1270
HOST DEVICE bool is_null_point_coord_array(const int8_t *val, int array_size) const
Definition: sqltypes.h:961
double doubleval
Definition: Datum.h:76
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:397
DEVICE void VarlenArray_get_nth(int8_t *buf, int n, ArrayDatum *result, bool *is_end)
Definition: sqltypes.h:1714
int64_t i64
Definition: sqltypes.h:1875
constexpr auto is_datetime(SQLTypes type)
Definition: sqltypes.h:325
const shared::StringDictKey & getStringDictKey() const
Definition: sqltypes.h:1055
HOST DEVICE bool is_null(const int8_t *val) const
Definition: sqltypes.h:903
size_t length
Definition: Datum.h:55
SQLTypes string_dict_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:565
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:468