OmniSciDB  a5dc49c757
 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 bool is_variable_size() const { return size == -1; }
420 
421  inline int get_logical_size() const {
424  return ti.get_size();
425  }
426  if (compression == kENCODING_DICT) {
427  return 4;
428  }
429  return get_size();
430  }
431 
432  inline int get_physical_cols() const {
433  switch (type) {
434  case kPOINT:
435  return 1; // coords
436  case kMULTIPOINT:
437  return 2; // coords, bounds
438  case kLINESTRING:
439  return 2; // coords, bounds
440  case kMULTILINESTRING:
441  return 3; // coords, linestring_sizes, bounds
442  case kPOLYGON:
443  return 3; // coords, ring_sizes, bounds
444  case kMULTIPOLYGON:
445  return 4; // coords, ring_sizes, poly_rings, bounds
446  default:
447  break;
448  }
449  return 0;
450  }
451  inline int get_physical_coord_cols() const {
452  // Return the number of extra columns which need to go through the executor,
453  // as opposed to those which are only needed by CPU. In other words, we omit
454  // any Bounds column.
455  return has_bounds() ? get_physical_cols() - 1 : get_physical_cols();
456  }
457  inline bool has_bounds() const {
458  switch (type) {
459  case kMULTIPOINT:
460  case kLINESTRING:
461  case kMULTILINESTRING:
462  case kPOLYGON:
463  case kMULTIPOLYGON:
464  return true;
465  default:
466  break;
467  }
468  return false;
469  }
470  HOST DEVICE inline void set_type(SQLTypes t) { type = t; }
471  HOST DEVICE inline void set_subtype(SQLTypes st) { subtype = st; }
472  inline void set_dimension(int d) { dimension = d; }
473  inline void set_precision(int d) { dimension = d; }
474  inline void set_input_srid(int d) { dimension = d; }
475  inline void set_scale(int s) { scale = s; }
476  inline void set_output_srid(int s) { scale = s; }
477  inline void set_notnull(bool n) { notnull = n; }
478  inline void set_size(int s) { size = s; }
479  inline void set_fixed_size() { size = get_storage_size(); }
480  inline void set_dict_intersection() { dict_intersection = true; }
481  inline void set_compression(EncodingType c) { compression = c; }
482  inline void set_comp_param(int p) { comp_param = p; }
483 #ifndef __CUDACC__
484  inline std::string get_type_name() const {
485  if (IS_GEO(type)) {
486  std::string srid_string = "";
487  if (get_output_srid() > 0) {
488  srid_string = ", " + std::to_string(get_output_srid());
489  }
490  CHECK_LT(static_cast<int>(subtype), kSQLTYPE_LAST);
491  return type_name[static_cast<int>(subtype)] + "(" +
492  type_name[static_cast<int>(type)] + srid_string + ")";
493  }
494  std::string ps = "";
495  if (type == kDECIMAL || type == kNUMERIC) {
496  ps = "(" + std::to_string(dimension) + "," + std::to_string(scale) + ")";
497  } else if (type == kTIMESTAMP) {
498  ps = "(" + std::to_string(dimension) + ")";
499  }
500  if (type == kARRAY) {
501  auto elem_ti = get_elem_type();
502  auto num_elems = (size > 0) ? std::to_string(size / elem_ti.get_size()) : "";
503  CHECK_LT(static_cast<int>(subtype), kSQLTYPE_LAST);
504  return elem_ti.get_type_name() + ps + "[" + num_elems + "]";
505  }
506  if (type == kCOLUMN) {
507  auto elem_ti = get_elem_type();
508  auto num_elems =
509  (size > 0) ? "[" + std::to_string(size / elem_ti.get_size()) + "]" : "";
510  CHECK_LT(static_cast<int>(subtype), kSQLTYPE_LAST);
511  return "COLUMN<" + elem_ti.get_type_name() + ps + ">" + num_elems;
512  }
513  if (type == kCOLUMN_LIST) {
514  auto elem_ti = get_elem_type();
515  auto num_elems =
516  (size > 0) ? "[" + std::to_string(size / elem_ti.get_size()) + "]" : "";
517  CHECK_LT(static_cast<int>(subtype), kSQLTYPE_LAST);
518  return "COLUMN_LIST<" + elem_ti.get_type_name() + ps + ">" + num_elems;
519  }
520  return type_name[static_cast<int>(type)] + ps;
521  }
522  inline std::string get_compression_name() const {
523  return comp_name[(int)compression];
524  }
525  std::string toString() const {
526  return to_string();
527  } // for PRINT macro
528  inline std::string to_string() const {
529  std::ostringstream oss;
530  oss << "(type=" << type_name[static_cast<int>(type)]
531  << ", dimension=" << get_dimension() << ", scale=" << get_scale()
532  << ", null=" << (get_notnull() ? "not nullable" : "nullable")
533  << ", compression_name=" << get_compression_name()
534  << ", comp_param=" << get_comp_param()
535  << ", subtype=" << type_name[static_cast<int>(subtype)] << ", size=" << get_size()
536  << ", element_size=" << get_elem_type().get_size() << ", dict_key=" << dict_key_
537  << ", uses_flatbuffer=" << uses_flatbuffer_ << ")";
538  return oss.str();
539  }
540 
541  inline std::string get_buffer_name() const {
542  if (is_array()) {
543  return "Array";
544  }
545  if (is_text_encoding_none()) {
546  return "TextEncodingNone";
547  }
548 
549  if (is_column()) {
550  return "Column";
551  }
552 
553  assert(false);
554  return "";
555  }
556 #endif
557  template <SQLTypes... types>
558  bool is_any() const {
559  return (... || (types == type));
560  }
561  inline bool is_string() const {
562  return IS_STRING(type);
563  }
564  inline bool is_string_array() const {
565  return (type == kARRAY) && IS_STRING(subtype);
566  }
567  inline bool is_integer() const {
568  return IS_INTEGER(type);
569  }
570  inline bool is_decimal() const {
571  return type == kDECIMAL || type == kNUMERIC;
572  }
573  inline bool is_fp() const {
574  return type == kFLOAT || type == kDOUBLE;
575  }
576  inline bool is_number() const {
577  return IS_NUMBER(type);
578  }
579  inline bool is_time() const {
580  return is_datetime(type);
581  }
582  inline bool is_boolean() const {
583  return type == kBOOLEAN;
584  }
585  inline bool is_array() const {
586  return type == kARRAY;
587  } // Array
588  inline bool is_varlen_array() const {
589  return type == kARRAY && size <= 0;
590  }
591  inline bool is_fixlen_array() const {
592  return type == kARRAY && size > 0;
593  }
594  inline bool is_timeinterval() const {
595  return IS_INTERVAL(type);
596  }
597  inline bool is_geometry() const {
598  return IS_GEO(type);
599  }
600  inline bool is_column() const {
601  return type == kCOLUMN;
602  } // Column
603  inline bool is_column_list() const {
604  return type == kCOLUMN_LIST;
605  } // ColumnList
606  inline bool is_column_array() const {
607  const auto c = get_compression();
608  return type == kCOLUMN && (c == kENCODING_ARRAY || c == kENCODING_ARRAY_DICT);
609  } // ColumnArray
610  inline bool is_column_list_array() const {
611  const auto c = get_compression();
612  return type == kCOLUMN_LIST && (c == kENCODING_ARRAY || c == kENCODING_ARRAY_DICT);
613  } // ColumnList of ColumnArray
614  inline bool is_text_encoding_none() const {
615  return type == kTEXT && get_compression() == kENCODING_NONE;
616  }
617  inline bool is_text_encoding_dict() const {
618  return type == kTEXT && get_compression() == kENCODING_DICT;
619  }
620  inline bool is_text_encoding_dict_array() const {
621  return type == kARRAY && subtype == kTEXT && get_compression() == kENCODING_DICT;
622  }
623  inline bool is_buffer() const {
624  return is_array() || is_column() || is_column_list() || is_text_encoding_none();
625  }
626  inline bool transforms() const {
627  return IS_GEO(type) && get_input_srid() > 0 && get_output_srid() > 0 &&
629  }
630 
631  inline bool is_varlen() const { // TODO: logically this should ignore fixlen arrays
632  return (IS_STRING(type) && compression != kENCODING_DICT) || type == kARRAY ||
633  IS_GEO(type);
634  }
635 
636  // need this here till is_varlen can be fixed w/o negative impact to existing code
637  inline bool is_varlen_indeed() const {
638  // SQLTypeInfo.is_varlen() is broken with fixedlen array now
639  // and seems left broken for some concern, so fix it locally
640  return is_varlen() && !is_fixlen_array();
641  }
642 
643  inline bool is_dict_encoded_string() const {
644  return is_string() && compression == kENCODING_DICT;
645  }
646 
647  inline bool is_none_encoded_string() const {
648  return is_string() && compression == kENCODING_NONE;
649  }
650 
651  inline bool is_subtype_dict_encoded_string() const {
653  }
654 
655  inline bool is_dict_encoded_type() const {
656  return is_dict_encoded_string() ||
658  }
659 
660  inline bool is_dict_intersection() const {
661  return dict_intersection;
662  }
663 
664  inline bool has_same_itemtype(const SQLTypeInfo& other) const {
665  if ((is_column() || is_column_list()) &&
666  (other.is_column() || other.is_column_list())) {
667  return subtype == other.get_subtype() &&
669  compression == other.get_compression());
670  }
671  return subtype == other.get_subtype();
672  }
673 
674  HOST DEVICE inline bool operator!=(const SQLTypeInfo& rhs) const {
675  return type != rhs.get_type() || subtype != rhs.get_subtype() ||
676  dimension != rhs.get_dimension() || scale != rhs.get_scale() ||
677  compression != rhs.get_compression() ||
680  notnull != rhs.get_notnull() || dict_key_ != rhs.dict_key_;
681  }
682  HOST DEVICE inline bool operator==(const SQLTypeInfo& rhs) const {
683  return type == rhs.get_type() && subtype == rhs.get_subtype() &&
684  dimension == rhs.get_dimension() && scale == rhs.get_scale() &&
685  compression == rhs.get_compression() &&
688  notnull == rhs.get_notnull() && dict_key_ == rhs.dict_key_;
689  }
690 
691  inline int get_array_context_logical_size() const {
692  if (is_string()) {
693  auto comp_type(get_compression());
694  if (comp_type == kENCODING_DICT || comp_type == kENCODING_FIXED ||
695  comp_type == kENCODING_NONE) {
696  return sizeof(int32_t);
697  }
698  }
699  return get_logical_size();
700  }
701 
702  HOST DEVICE inline void operator=(const SQLTypeInfo& rhs) {
703  type = rhs.get_type();
704  subtype = rhs.get_subtype();
705  dimension = rhs.get_dimension();
706  scale = rhs.get_scale();
707  notnull = rhs.get_notnull();
709  comp_param = rhs.get_comp_param();
710  size = rhs.get_size();
711  dict_key_ = rhs.dict_key_;
713  }
714 
715  inline bool is_castable(const SQLTypeInfo& new_type_info) const {
716  // can always cast between the same type but different precision/scale/encodings
717  if (type == new_type_info.get_type()) {
718  return true;
719  // can always cast between strings
720  } else if (is_string() && new_type_info.is_string()) {
721  return true;
722  } else if (is_string() && !new_type_info.is_string()) {
723  return false;
724  } else if (!is_string() && new_type_info.is_string()) {
725  return true;
726  // can cast between numbers
727  } else if (is_number() && new_type_info.is_number()) {
728  return true;
729  // can cast from timestamp or date to number (epoch)
730  } else if ((type == kTIMESTAMP || type == kDATE) && new_type_info.is_number()) {
731  return true;
732  // can cast from number (epoch) to timestamp, date, or time
733  } else if (is_number() && new_type_info.is_time()) {
734  return true;
735  // can cast from date to timestamp
736  } else if (type == kDATE && new_type_info.get_type() == kTIMESTAMP) {
737  return true;
738  } else if (type == kTIMESTAMP && new_type_info.get_type() == kDATE) {
739  return true;
740  } else if (type == kTIMESTAMP && new_type_info.get_type() == kTIME) {
741  return true;
742  } else if (type == kBOOLEAN && new_type_info.is_number()) {
743  return true;
744  } else if (type == kARRAY && new_type_info.get_type() == kARRAY) {
745  return get_elem_type().is_castable(new_type_info.get_elem_type());
746  } else if (type == kCOLUMN && new_type_info.get_type() == kCOLUMN) {
747  return get_elem_type().is_castable(new_type_info.get_elem_type());
748  } else if (type == kCOLUMN_LIST && new_type_info.get_type() == kCOLUMN_LIST) {
749  return get_elem_type().is_castable(new_type_info.get_elem_type());
750  } else {
751  return false;
752  }
753  }
754 
763  inline bool is_numeric_scalar_auto_castable(const SQLTypeInfo& new_type_info) const {
764  const auto& new_type = new_type_info.get_type();
765  switch (type) {
766  case kBOOLEAN:
767  return new_type == kBOOLEAN;
768  case kTINYINT:
769  case kSMALLINT:
770  case kINT:
771  if (!new_type_info.is_number()) {
772  return false;
773  }
774  if (new_type_info.is_fp()) {
775  // We can lose precision here, but preserving existing behavior
776  return true;
777  }
778  return new_type_info.get_logical_size() >= get_logical_size();
779  case kBIGINT:
780  return new_type == kBIGINT || new_type == kDOUBLE || new_type == kFLOAT;
781  case kFLOAT:
782  case kDOUBLE:
783  if (!new_type_info.is_fp()) {
784  return false;
785  }
786  return (new_type_info.get_logical_size() >= get_logical_size());
787  case kDECIMAL:
788  case kNUMERIC:
789  switch (new_type) {
790  case kDECIMAL:
791  case kNUMERIC:
792  return new_type_info.get_dimension() >= get_dimension();
793  case kDOUBLE:
794  return true;
795  case kFLOAT:
796  return get_dimension() <= 7;
797  default:
798  return false;
799  }
800  case kTIMESTAMP:
801  if (new_type != kTIMESTAMP) {
802  return false;
803  }
804  return new_type_info.get_dimension() >= get_dimension();
805  case kDATE:
806  return new_type == kDATE;
807  case kTIME:
808  return new_type == kTIME;
809  default:
810  UNREACHABLE();
811  return false;
812  }
813  }
814 
824  inline int32_t get_numeric_scalar_scale() const {
825  CHECK(type == kBOOLEAN || type == kTINYINT || type == kSMALLINT || type == kINT ||
826  type == kBIGINT || type == kFLOAT || type == kDOUBLE || type == kDECIMAL ||
827  type == kNUMERIC || type == kTIMESTAMP || type == kDATE || type == kTIME);
828  switch (type) {
829  case kBOOLEAN:
830  return 1;
831  case kTINYINT:
832  case kSMALLINT:
833  case kINT:
834  case kBIGINT:
835  case kFLOAT:
836  case kDOUBLE:
837  return get_logical_size();
838  case kDECIMAL:
839  case kNUMERIC:
840  if (get_dimension() > 7) {
841  return 8;
842  } else {
843  return 4;
844  }
845  case kTIMESTAMP:
846  switch (get_dimension()) {
847  case 9:
848  return 8;
849  case 6:
850  return 4;
851  case 3:
852  return 2;
853  case 0:
854  return 1;
855  default:
856  UNREACHABLE();
857  }
858  case kDATE:
859  return 1;
860  case kTIME:
861  return 1;
862  default:
863  UNREACHABLE();
864  return 0;
865  }
866  }
867 
868  HOST DEVICE inline bool is_null(const Datum& d) const {
869  // assuming Datum is always uncompressed
870  switch (type) {
871  case kBOOLEAN:
872  return (int8_t)d.boolval == NULL_BOOLEAN;
873  case kTINYINT:
874  return d.tinyintval == NULL_TINYINT;
875  case kSMALLINT:
876  return d.smallintval == NULL_SMALLINT;
877  case kINT:
878  return d.intval == NULL_INT;
879  case kBIGINT:
880  case kNUMERIC:
881  case kDECIMAL:
882  return d.bigintval == NULL_BIGINT;
883  case kFLOAT:
884  return d.floatval == NULL_FLOAT;
885  case kDOUBLE:
886  return d.doubleval == NULL_DOUBLE;
887  case kTIME:
888  case kTIMESTAMP:
889  case kDATE:
890  return d.bigintval == NULL_BIGINT;
891  case kTEXT:
892  case kVARCHAR:
893  case kCHAR:
894  // @TODO handle null strings
895  break;
896  case kNULLT:
897  return true;
898  case kARRAY:
899  return d.arrayval == NULL || d.arrayval->is_null;
900  default:
901  break;
902  }
903  return false;
904  }
905  HOST DEVICE inline bool is_null(const int8_t* val) const {
906  if (type == kFLOAT) {
907  return *(float*)val == NULL_FLOAT;
908  }
909  if (type == kDOUBLE) {
910  return *(double*)val == NULL_DOUBLE;
911  }
912  // val can be either compressed or uncompressed
913  switch (size) {
914  case 1:
915  return *val == NULL_TINYINT;
916  case 2:
917  return *(int16_t*)val == NULL_SMALLINT;
918  case 4:
919  return *(int32_t*)val == NULL_INT;
920  case 8:
921  return *(int64_t*)val == NULL_BIGINT;
922  case kNULLT:
923  return true;
924  default:
925  // @TODO(wei) handle null strings
926  break;
927  }
928  return false;
929  }
930  HOST DEVICE inline bool is_null_fixlen_array(const int8_t* val, int array_size) const {
931  // Check if fixed length array has a NULL_ARRAY sentinel as the first element
932  if (type == kARRAY && val && array_size > 0 && array_size == size) {
933  // Need to create element type to get the size, but can't call get_elem_type()
934  // since this is a HOST DEVICE function. Going through copy constructor instead.
935  auto elem_ti{*this};
936  elem_ti.set_type(subtype);
937  elem_ti.set_subtype(kNULLT);
938  auto elem_size = elem_ti.get_storage_size();
939  if (elem_size < 1) {
940  return false;
941  }
942  if (subtype == kFLOAT) {
943  return *(float*)val == NULL_ARRAY_FLOAT;
944  }
945  if (subtype == kDOUBLE) {
946  return *(double*)val == NULL_ARRAY_DOUBLE;
947  }
948  switch (elem_size) {
949  case 1:
950  return *val == NULL_ARRAY_TINYINT;
951  case 2:
952  return *(int16_t*)val == NULL_ARRAY_SMALLINT;
953  case 4:
954  return *(int32_t*)val == NULL_ARRAY_INT;
955  case 8:
956  return *(int64_t*)val == NULL_ARRAY_BIGINT;
957  default:
958  return false;
959  }
960  }
961  return false;
962  }
963  HOST DEVICE inline bool is_null_point_coord_array(const int8_t* val,
964  int array_size) const {
965  if (type == kARRAY && subtype == kTINYINT && val && array_size > 0 &&
966  array_size == size) {
967  if (array_size == 2 * sizeof(double)) {
968  return *(double*)val == NULL_ARRAY_DOUBLE;
969  }
970  if (array_size == 2 * sizeof(int32_t)) {
971  return *(uint32_t*)val == NULL_ARRAY_COMPRESSED_32;
972  }
973  }
974  return false;
975  }
976 
977  inline SQLTypeInfo get_elem_type() const {
978  SQLTypeInfo type_info = *this;
979  if ((type == kCOLUMN || type == kCOLUMN_LIST) && compression == kENCODING_ARRAY) {
980  type_info.set_type(kARRAY);
981  type_info.set_compression(kENCODING_NONE);
982  } else if ((type == kCOLUMN || type == kCOLUMN_LIST) &&
984  type_info.set_type(kARRAY);
985  type_info.set_compression(kENCODING_DICT);
986  } else if ((type == kCOLUMN || type == kCOLUMN_LIST) && IS_GEO(subtype)) {
987  type_info.set_type(subtype);
988  type_info.set_subtype(kGEOMETRY);
989  } else if (IS_GEO(type)) {
990  if (type_info.get_compression() == kENCODING_GEOINT) {
991  type_info.set_type(kINT);
992  type_info.set_compression(kENCODING_NONE);
993  } else {
994  type_info.set_type(kDOUBLE);
995  }
996  type_info.set_subtype(kNULLT);
997  } else if (type == kARRAY) {
998  type_info.set_type(subtype);
999  type_info.set_subtype(kNULLT);
1000  type_info.set_notnull(false);
1001  type_info.setUsesFlatBuffer(false);
1002  } else {
1003  type_info.set_type(subtype);
1004  type_info.set_subtype(kNULLT);
1005  }
1006  type_info.setStorageSize();
1007  return type_info;
1008  }
1009 
1010  inline SQLTypeInfo get_array_type() const {
1011  SQLTypeInfo type_info = *this;
1012  type_info.set_type(kARRAY);
1013  type_info.set_subtype(type);
1014  type_info.setStorageSize();
1015  return type_info;
1016  }
1017 
1018  inline bool is_date_in_days() const {
1019  if (type == kDATE) {
1020  const auto comp_type = get_compression();
1021  if (comp_type == kENCODING_DATE_IN_DAYS) {
1022  return true;
1023  }
1024  }
1025  return false;
1026  }
1027 
1028  inline bool is_date() const {
1029  return type == kDATE;
1030  }
1031 
1032  inline bool is_time_or_date() const {
1033  return type == kDATE || type == kTIME || type == kTIMESTAMP;
1034  }
1035 
1036  inline bool is_high_precision_timestamp() const {
1037  if (type == kTIMESTAMP) {
1038  const auto dimension = get_dimension();
1039  if (dimension > 0) {
1040  return true;
1041  }
1042  }
1043  return false;
1044  }
1045 
1046  inline bool is_timestamp() const {
1047  return type == kTIMESTAMP;
1048  }
1049  inline bool is_encoded_timestamp() const {
1050  return is_timestamp() && compression == kENCODING_FIXED;
1051  }
1052 
1054  size = get_storage_size();
1055  }
1056 
1058  // If comp_param is set, it should equal dict_id.
1060  return dict_key_;
1061  }
1062 
1063  void setStringDictKey(const shared::StringDictKey& dict_key) {
1064  dict_key_ = dict_key;
1065  // If comp_param is set, it should equal dict_id.
1067  }
1068 
1069  // TODO: Remove below *SkipCompParamCheck methods as part of comp_param refactor
1071  return dict_key_;
1072  }
1073 
1075  dict_key_ = dict_key;
1076  }
1077 
1078  // a column or an ouput column of this type may use FlatBuffer storage.
1079  inline void setUsesFlatBuffer(bool uses_flatbuffer = true) {
1080  uses_flatbuffer_ = uses_flatbuffer;
1081  }
1082 
1083  inline bool usesFlatBuffer() const {
1084  return uses_flatbuffer_;
1085  }
1086 
1087  // Checks if a column of this type can use FlatBuffer storage
1088  inline bool supportsFlatBuffer() const {
1089  switch (type) {
1090  case kARRAY:
1091  case kPOINT:
1092  case kLINESTRING:
1093  case kPOLYGON:
1094  case kMULTIPOINT:
1095  case kMULTILINESTRING:
1096  case kMULTIPOLYGON:
1097  return true;
1098  case kTEXT:
1099  return get_compression() == kENCODING_NONE;
1100  case kCOLUMN:
1101  case kCOLUMN_LIST:
1102  // calling supportsFlatBuffer on a column type is not meaningful
1103  UNREACHABLE();
1104  default:;
1105  }
1106  return false;
1107  }
1108 
1110  SQLTypeInfoLite ti_lite;
1111  switch (type) {
1112  case kPOINT:
1113  ti_lite.type = SQLTypeInfoLite::POINT;
1115  break;
1116  case kLINESTRING:
1119  break;
1120  case kPOLYGON:
1121  ti_lite.type = SQLTypeInfoLite::POLYGON;
1123  break;
1124  case kMULTIPOINT:
1127  break;
1128  case kMULTILINESTRING:
1131  break;
1132  case kMULTIPOLYGON:
1135  break;
1136  case kTEXT:
1137  ti_lite.type = SQLTypeInfoLite::TEXT;
1139  break;
1140  case kARRAY:
1141  ti_lite.type = SQLTypeInfoLite::ARRAY;
1142  switch (subtype) {
1143  case kBOOLEAN:
1145  break;
1146  case kTINYINT:
1148  break;
1149  case kSMALLINT:
1151  break;
1152  case kINT:
1153  ti_lite.subtype = SQLTypeInfoLite::INT;
1154  break;
1155  case kBIGINT:
1156  ti_lite.subtype = SQLTypeInfoLite::BIGINT;
1157  break;
1158  case kFLOAT:
1159  ti_lite.subtype = SQLTypeInfoLite::FLOAT;
1160  break;
1161  case kDOUBLE:
1162  ti_lite.subtype = SQLTypeInfoLite::DOUBLE;
1163  break;
1164  case kTEXT:
1165  ti_lite.subtype = SQLTypeInfoLite::TEXT;
1166  break;
1167  default:
1168  UNREACHABLE();
1169  }
1170  break;
1171  default:
1172  UNREACHABLE();
1173  }
1174  if (is_geometry()) {
1175  switch (get_compression()) {
1176  case kENCODING_NONE:
1178  break;
1179  case kENCODING_GEOINT:
1181  break;
1182  default:
1183  UNREACHABLE();
1184  }
1185  ti_lite.dimension = get_input_srid();
1186  ti_lite.scale = get_output_srid();
1187  ti_lite.db_id = 0; // unused
1188  ti_lite.dict_id = 0; // unused
1189  } else if (type == kTEXT) {
1190  switch (get_compression()) {
1191  case kENCODING_NONE:
1193  break;
1194  case kENCODING_DICT:
1196  break;
1197  default:
1198  UNREACHABLE();
1199  }
1200  ti_lite.dimension = 0; // unused
1201  ti_lite.scale = 0; // unused
1202  ti_lite.db_id = dict_key_.db_id;
1203  ti_lite.dict_id = dict_key_.dict_id;
1204  } else if (type == kARRAY) {
1205  if (subtype == kTEXT) {
1206  switch (get_compression()) {
1207  case kENCODING_NONE:
1209  break;
1210  case kENCODING_DICT:
1212  break;
1213  default:
1214  UNREACHABLE();
1215  }
1216  }
1217  ti_lite.dimension = 0; // unused
1218  ti_lite.scale = 0; // unused
1219  ti_lite.db_id = dict_key_.db_id;
1220  ti_lite.dict_id = dict_key_.dict_id;
1221  } else {
1222  UNREACHABLE();
1223  }
1224  return ti_lite;
1225  }
1226 
1228  SQLTypes sql_value_type =
1229  ((type == kCOLUMN || type == kCOLUMN_LIST || type == kARRAY) ? subtype : type);
1230  switch (sql_value_type) {
1231  case kPOINT:
1232  case kLINESTRING:
1233  case kPOLYGON:
1234  case kMULTIPOINT:
1235  case kMULTILINESTRING:
1236  case kMULTIPOLYGON:
1239  case kBOOLEAN:
1240  return FlatBufferManager::Bool8;
1241  case kTINYINT:
1242  return FlatBufferManager::Int8;
1243  case kSMALLINT:
1244  return FlatBufferManager::Int16;
1245  case kINT:
1246  return FlatBufferManager::Int32;
1247  case kBIGINT:
1248  return FlatBufferManager::Int64;
1249  case kFLOAT:
1251  case kDOUBLE:
1253  case kTEXT: {
1254  switch (get_compression()) {
1255  case kENCODING_NONE:
1256  return FlatBufferManager::Int8;
1257  case kENCODING_DICT:
1258  return FlatBufferManager::Int32;
1259  default:
1260  UNREACHABLE();
1261  }
1262  } break;
1263  default:
1264  UNREACHABLE();
1265  }
1266  return {};
1267  }
1268 
1269  private:
1270  SQLTypes type; // type id
1271  SQLTypes subtype; // element type of arrays or columns
1272  int dimension; // VARCHAR/CHAR length or NUMERIC/DECIMAL precision or COLUMN_LIST
1273  // length or TIMESTAMP precision
1274  int scale; // NUMERIC/DECIMAL scale
1275  bool notnull; // nullable? a hint, not used for type checking
1276  EncodingType compression; // compression scheme
1277  int comp_param; // compression parameter when applicable for certain schemes
1278  int size; // size of the type in bytes. -1 for variable size
1279  bool dict_intersection{false};
1280 #ifndef __CUDACC__
1281  static std::string type_name[kSQLTYPE_LAST];
1282  static std::string comp_name[kENCODING_LAST];
1283 #endif
1285  bool uses_flatbuffer_{false};
1286  HOST DEVICE inline int get_storage_size() const {
1287  switch (type) {
1288  case kBOOLEAN:
1289  return sizeof(int8_t);
1290  case kTINYINT:
1291  return sizeof(int8_t);
1292  case kSMALLINT:
1293  switch (compression) {
1294  case kENCODING_NONE:
1295  return sizeof(int16_t);
1296  case kENCODING_FIXED:
1297  case kENCODING_SPARSE:
1298  return comp_param / 8;
1299  case kENCODING_RL:
1300  case kENCODING_DIFF:
1301  break;
1302  default:
1303  assert(false);
1304  }
1305  break;
1306  case kINT:
1307  switch (compression) {
1308  case kENCODING_NONE:
1309  return sizeof(int32_t);
1310  case kENCODING_FIXED:
1311  case kENCODING_SPARSE:
1312  case kENCODING_GEOINT:
1313  return comp_param / 8;
1314  case kENCODING_RL:
1315  case kENCODING_DIFF:
1316  break;
1317  default:
1318  assert(false);
1319  }
1320  break;
1321  case kBIGINT:
1322  case kNUMERIC:
1323  case kDECIMAL:
1324  switch (compression) {
1325  case kENCODING_NONE:
1326  return sizeof(int64_t);
1327  case kENCODING_FIXED:
1328  case kENCODING_SPARSE:
1329  return comp_param / 8;
1330  case kENCODING_RL:
1331  case kENCODING_DIFF:
1332  break;
1333  default:
1334  assert(false);
1335  }
1336  break;
1337  case kFLOAT:
1338  switch (compression) {
1339  case kENCODING_NONE:
1340  return sizeof(float);
1341  case kENCODING_FIXED:
1342  case kENCODING_RL:
1343  case kENCODING_DIFF:
1344  case kENCODING_SPARSE:
1345  assert(false);
1346  break;
1347  default:
1348  assert(false);
1349  }
1350  break;
1351  case kDOUBLE:
1352  switch (compression) {
1353  case kENCODING_NONE:
1354  return sizeof(double);
1355  case kENCODING_FIXED:
1356  case kENCODING_RL:
1357  case kENCODING_DIFF:
1358  case kENCODING_SPARSE:
1359  assert(false);
1360  break;
1361  default:
1362  assert(false);
1363  }
1364  break;
1365  case kTIMESTAMP:
1366  case kTIME:
1367  case kINTERVAL_DAY_TIME:
1368  case kINTERVAL_YEAR_MONTH:
1369  case kDATE:
1370  switch (compression) {
1371  case kENCODING_NONE:
1372  return sizeof(int64_t);
1373  case kENCODING_FIXED:
1374  if (type == kTIMESTAMP && dimension > 0) {
1375  assert(false); // disable compression for timestamp precisions
1376  }
1377  return comp_param / 8;
1378  case kENCODING_RL:
1379  case kENCODING_DIFF:
1380  case kENCODING_SPARSE:
1381  assert(false);
1382  break;
1384  switch (comp_param) {
1385  case 0:
1386  return 4; // Default date encoded in days is 32 bits
1387  case 16:
1388  case 32:
1389  return comp_param / 8;
1390  default:
1391  assert(false);
1392  break;
1393  }
1394  default:
1395  assert(false);
1396  }
1397  break;
1398  case kTEXT:
1399  case kVARCHAR:
1400  case kCHAR:
1401  if (compression == kENCODING_DICT) {
1402  return sizeof(int32_t); // @TODO(wei) must check DictDescriptor
1403  }
1404  break;
1405  case kARRAY:
1406  // TODO: return size for fixlen arrays?
1407  break;
1408  case kPOINT:
1409  case kMULTIPOINT:
1410  case kLINESTRING:
1411  case kMULTILINESTRING:
1412  case kPOLYGON:
1413  case kMULTIPOLYGON:
1414  case kCOLUMN:
1415  case kCOLUMN_LIST:
1416  break;
1417  default:
1418  break;
1419  }
1420  return -1;
1421  }
1422 };
1423 
1425 
1427 
1428 #ifndef __CUDACC__
1429 #include <string_view>
1430 
1431 Datum NullDatum(const SQLTypeInfo& ti);
1432 bool IsNullDatum(const Datum d, const SQLTypeInfo& ti);
1433 Datum StringToDatum(const std::string_view s, SQLTypeInfo& ti);
1434 std::string DatumToString(const Datum d, const SQLTypeInfo& ti);
1435 int64_t extract_int_type_from_datum(const Datum datum, const SQLTypeInfo& ti);
1436 double extract_fp_type_from_datum(const Datum datum, const SQLTypeInfo& ti);
1437 bool DatumEqual(const Datum, const Datum, const SQLTypeInfo& ti);
1438 int64_t convert_decimal_value_to_scale(const int64_t decimal_value,
1439  const SQLTypeInfo& type_info,
1440  const SQLTypeInfo& new_type_info);
1441 #endif
1442 
1443 #ifdef HAVE_TOSTRING
1444 inline std::ostream& operator<<(std::ostream& os, const SQLTypeInfo& type_info) {
1445  os << toString(type_info);
1446  return os;
1447 }
1448 #endif
1449 
1450 #include "../QueryEngine/DateAdd.h"
1451 #include "../QueryEngine/DateTruncate.h"
1452 #include "../QueryEngine/ExtractFromTime.h"
1453 
1454 inline SQLTypes get_int_type_by_size(size_t const nbytes) {
1455  switch (nbytes) {
1456  case 1:
1457  return kTINYINT;
1458  case 2:
1459  return kSMALLINT;
1460  case 4:
1461  return kINT;
1462  case 8:
1463  return kBIGINT;
1464  default:
1465 #if !(defined(__CUDACC__) || defined(NO_BOOST))
1466  UNREACHABLE() << "Invalid number of bytes=" << nbytes;
1467 #endif
1468  return {};
1469  }
1470 }
1471 
1473  EncodingType encoding = type_info.get_compression();
1474  if (encoding == kENCODING_DATE_IN_DAYS ||
1475  (encoding == kENCODING_FIXED && type_info.get_type() != kARRAY)) {
1476  encoding = kENCODING_NONE;
1477  }
1478  auto type_info_copy = type_info;
1479  type_info_copy.set_compression(encoding);
1480  type_info_copy.setStorageSize();
1481  return type_info_copy;
1482 }
1483 
1485  SQLTypeInfo nullable_type_info = type_info;
1486  nullable_type_info.set_notnull(false);
1487  return nullable_type_info;
1488 }
1489 
1491  SQLTypeInfo nullable_type_info = get_logical_type_info(type_info);
1492  return get_nullable_type_info(nullable_type_info);
1493 }
1494 
1495 using StringOffsetT = int32_t;
1496 using ArrayOffsetT = int32_t;
1497 
1498 int8_t* append_datum(int8_t* buf, const Datum& d, const SQLTypeInfo& ti);
1499 
1500 // clang-format off
1501 /*
1502 
1503 A note on representing collection types using SQLTypeInfo
1504 =========================================================
1505 
1506 In general, a collection type is a type of collection of items. A
1507 collection can be an array, a column, or a column list. A column list
1508 is as collection of columns that have the same item type. An item can
1509 be of scalar type (bool, integers, floats, text encoding dict's, etc)
1510 or of collection type (array of scalars, column of scalars, column of
1511 array of scalars).
1512 
1513 SQLTypeInfo provides a structure to represent both item and collection
1514 types using the following list of attributes:
1515  SQLTypes type
1516  SQLTypes subtype
1517  int dimension
1518  int scale
1519  bool notnull
1520  EncodingType compression
1521  int comp_param
1522  int size
1523 
1524 To represent a particular type, not all attributes are used. However,
1525 there may exists multiple ways to represent the same type using
1526 various combinations of these attributes and this note can be used as
1527 a guideline to how to represent a newly introduced collection type
1528 using the SQLTypeInfo structure.
1529 
1530 Scalar types
1531 ------------
1532 
1533 - Scalar types are booleans, integers, and floats that are defined
1534  by type and size attributes,
1535 
1536  SQLTypeInfo(type=kSCALAR)
1537 
1538  where SCALAR is in {BOOL, BIGINT, INT, SMALLINT, TINYINT, DOUBLE,
1539  FLOAT} while the corresponding size is specified in
1540  get_storage_size(). For example, SQLTypeInfo(type=kFLOAT)
1541  represents FLOAT and its size is implemented as 4 in the
1542  get_storage_size() method,
1543 
1544 - Text encoding dict (as defined as index and string dictionary) is
1545  represented as a 32-bit integer value and its type is specified as
1546 
1547  SQLTypeInfo(type=kTEXT, compression=kENCODING_DICT, comp_param=<dict id>)
1548 
1549  and size is defined as 4 by get_storage_size().
1550 
1551 Collection types
1552 ----------------
1553 
1554 - The type of a varlen array of scalar items is specified as
1555 
1556  SQLTypeInfo(type=kARRAY, subtype=kSCALAR)
1557 
1558  and size is defined as -1 by get_storage_size() which can be interpreted as N/A.
1559 
1560 - The type of a varlen array of text encoding dict is specified as
1561 
1562  SQLTypeInfo(type=kARRAY, subtype=kTEXT, compression=kENCODING_DICT, comp_param=<dict id>)
1563 
1564  Notice that the compression and comp_param attributes apply to
1565  subtype rather than to type. This quirk exemplifies the fact that
1566  SQLTypeInfo provides limited ability to support composite types.
1567 
1568 - Similarly, the types of a column of scalar and text encoded dict
1569  items are specified as
1570 
1571  SQLTypeInfo(type=kCOLUMN, subtype=kSCALAR)
1572 
1573  and
1574 
1575  SQLTypeInfo(type=kCOLUMN, subtype=kTEXT, compression=kENCODING_DICT, comp_param=<dict id>)
1576 
1577  respectively.
1578 
1579 - The type of column list with scalar items is specified as
1580 
1581  SQLTypeInfo(type=kCOLUMN_LIST, subtype=kSCALAR, dimension=<nof columns>)
1582 
1583  WARNING: Column list with items that type use compression (such as
1584  TIMESTAMP), cannot be supported! See QE-427.
1585 
1586 - The type of column list with text encoded dict items is specified as
1587 
1588  SQLTypeInfo(type=kCOLUMN_LIST, subtype=kTEXT, compression=kENCODING_DICT, dimension=<nof columns>)
1589 
1590 - The type of a column of arrays of scalar items is specified as
1591 
1592  SQLTypeInfo(type=kCOLUMN, subtype=kSCALAR, compression=kENCODING_ARRAY)
1593 
1594  Notice that the "a collection of collections of items" is specified
1595  by introducing a new compression scheme that descibes the
1596  "collections" part while the subtype attribute specifies the type of
1597  items.
1598 
1599 - The type of a column of arrays of text encoding dict items is specified as
1600 
1601  SQLTypeInfo(type=kCOLUMN, subtype=kTEXT, compression=kENCODING_ARRAY_DICT, comp_param=<dict id>)
1602 
1603  where the compression attribute kENCODING_ARRAY_DICT carries two
1604  pieces of information: (i) the items type is dict encoded string and
1605  (ii) the type represents a "column of arrays".
1606 
1607 
1608 - The type of a column list of arrays of scalar items is specified as
1609 
1610  SQLTypeInfo(type=kCOLUMN_LIST, subtype=kSCALAR, compression=kENCODING_ARRAY, dimension=<nof columns>)
1611 
1612 - The type of a column list of arrays of text encoding dict items is specified as
1613 
1614  SQLTypeInfo(type=kCOLUMN_LIST, subtype=kTEXT, compression=kENCODING_ARRAY_DICT, comp_param=<dict id>, dimension=<nof columns>)
1615 
1616  that is the most complicated currently supported type of "a
1617  collection(=list) of collections(=columns) of collections(=arrays)
1618  of items(=text)" with a specified compression scheme and comp_param
1619  attributes.
1620 
1621 - The type of a column of geometru points is specified as
1622 
1623  SQLTypeInfo(type=kCOLUMN, subtype=kPOINT, dimension=<input srid>, scale=<output srid>, compression=<kENCODING_NONE|kENCODING_GEOINT>)
1624 
1625 
1626 */
1627 // clang-format on
1628 
1629 inline auto generate_column_type(const SQLTypeInfo& elem_ti) {
1630  SQLTypes elem_type = elem_ti.get_type();
1631  if (elem_type == kCOLUMN) {
1632  if (elem_ti.get_subtype() == kVARCHAR) {
1633  auto new_elem_ti = elem_ti;
1634  new_elem_ti.set_subtype(kTEXT);
1635  return new_elem_ti;
1636  }
1637  return elem_ti;
1638  }
1639  auto c = elem_ti.get_compression();
1640  auto d = elem_ti.get_dimension();
1641  auto s = elem_ti.get_scale();
1642  auto p = elem_ti.get_comp_param();
1643  switch (elem_type) {
1644  case kBOOLEAN:
1645  case kTINYINT:
1646  case kSMALLINT:
1647  case kINT:
1648  case kBIGINT:
1649  case kFLOAT:
1650  case kDOUBLE:
1651  if (c == kENCODING_NONE && p == 0) {
1652  break; // here and below `break` means supported element type
1653  // for extension functions
1654  }
1655  case kPOINT:
1656  case kLINESTRING:
1657  case kPOLYGON:
1658  case kMULTIPOINT:
1659  case kMULTILINESTRING:
1660  case kMULTIPOLYGON:
1661  if (c == kENCODING_NONE && p == 0) {
1662  break;
1663  }
1664  if (c == kENCODING_GEOINT && p == 32) {
1665  break;
1666  }
1667  case kTEXT:
1668  case kVARCHAR:
1669  elem_type = kTEXT;
1670  if (c == kENCODING_DICT) {
1671  break;
1672  }
1673  case kTIMESTAMP:
1674  if (c == kENCODING_NONE && p == 0 && (d == 9 || d == 6 || d == 0)) {
1675  break;
1676  }
1677  case kARRAY:
1678  elem_type = elem_ti.get_subtype();
1679  if (IS_NUMBER(elem_type) || elem_type == kBOOLEAN || elem_type == kTEXT) {
1680  if (c == kENCODING_NONE && p == 0) {
1681  c = kENCODING_ARRAY;
1682  break;
1683  } else if (c == kENCODING_DICT) {
1685  break;
1686  }
1687  }
1688  default:
1689  elem_type = kNULLT; // indicates unsupported element type that
1690  // the caller needs to handle accordingly
1691  }
1692  auto ti = SQLTypeInfo(kCOLUMN, c, p, elem_type);
1693  ti.set_dimension(d);
1694  if (c == kENCODING_DICT) {
1695  ti.setStringDictKey(elem_ti.getStringDictKey());
1696  }
1697  ti.set_scale(s);
1698  return ti;
1699 }
1700 
1701 inline auto generate_column_list_type(const SQLTypeInfo& elem_ti) {
1702  auto type_info = generate_column_type(elem_ti);
1703  if (type_info.get_subtype() != kNULLT) {
1704  type_info.set_type(kCOLUMN_LIST);
1705  }
1706  if (type_info.get_subtype() == kTIMESTAMP) {
1707  // ColumnList<Timestamp> is not supported, see QE-472
1708  type_info.set_subtype(kNULLT);
1709  }
1710  return type_info;
1711 }
1712 
1713 // SQLTypeInfo-friendly interface to FlatBuffer:
1714 
1715 // ChunkIter_get_nth variant for array buffers using FlatBuffer storage schema:
1716 DEVICE inline void VarlenArray_get_nth(int8_t* buf,
1717  int n,
1718  ArrayDatum* result,
1719  bool* is_end) {
1720  FlatBufferManager m{buf};
1721  FlatBufferManager::Status status{};
1722  if (m.isNestedArray()) {
1724  status = m.getItem(n, item);
1725  if (status == FlatBufferManager::Status::Success) {
1726  result->length = item.nof_values * m.getValueSize();
1727  result->pointer = item.values;
1728  result->is_null = item.is_null;
1729  *is_end = false;
1730  } else {
1731  result->length = 0;
1732  result->pointer = NULL;
1733  result->is_null = true;
1734  *is_end = true;
1735 #ifndef __CUDACC__
1736  // out of range indexing is equivalent to returning NULL (SQL AT)
1737  CHECK_EQ(status, FlatBufferManager::Status::ItemUnspecifiedError);
1738 #endif
1739  }
1740  } else {
1741  // to be deprecated
1742  auto status = m.getItemOld(n, result->length, result->pointer, result->is_null);
1743  if (status == FlatBufferManager::Status::IndexError) {
1744  *is_end = true;
1745  result->length = 0;
1746  result->pointer = NULL;
1747  result->is_null = true;
1748  } else {
1749  *is_end = false;
1750 #ifndef __CUDACC__
1751  CHECK_EQ(status, FlatBufferManager::Status::Success);
1752 #endif
1753  }
1754  }
1755 }
1756 
1757 DEVICE inline void VarlenArray_get_nth(int8_t* buf,
1758  int n,
1759  bool uncompress,
1761  bool* is_end) {
1762  FlatBufferManager m{buf};
1763  FlatBufferManager::Status status{};
1764 #ifndef __CUDACC__
1765  CHECK(m.isNestedArray());
1766 #endif
1768  status = m.getItem(n, item);
1769  if (status == FlatBufferManager::Status::Success) {
1770  result->length = item.nof_values * m.getValueSize();
1771  result->pointer = item.values;
1772  result->is_null = item.is_null;
1773  *is_end = false;
1774 #ifndef __CUDACC__
1775  CHECK(!uncompress); // NOT IMPLEMENTED
1776 #endif
1777  } else {
1778  result->length = 0;
1779  result->pointer = NULL;
1780  result->is_null = true;
1781  *is_end = true;
1782 #ifndef __CUDACC__
1783  // out of range indexing is equivalent to returning NULL (SQL AT)
1784  CHECK_EQ(status, FlatBufferManager::Status::IndexError);
1785 #endif
1786  }
1787 }
1788 
1789 inline void getFlatBufferNDimsAndSizes(const int64_t items_count,
1790  const int64_t max_nof_values,
1791  const SQLTypeInfo& ti,
1792  size_t& ndims,
1793  int64_t& max_nof_sizes) {
1794  ndims = 0;
1795  max_nof_sizes = 0;
1796  switch (ti.get_type()) {
1797  case kPOINT:
1798  ndims = 0;
1799  break;
1800  case kARRAY:
1801  if (ti.get_subtype() == kTEXT && ti.get_compression() == kENCODING_NONE) {
1802  ndims = 2;
1803  max_nof_sizes = items_count + 2 * max_nof_values / 3;
1804  } else {
1805  ndims = 1;
1806  max_nof_sizes = items_count + max_nof_values / 3;
1807  }
1808  break;
1809  case kLINESTRING:
1810  case kMULTIPOINT:
1811  ndims = 1;
1812  max_nof_sizes = items_count + max_nof_values / 3;
1813  break;
1814  case kPOLYGON:
1815  case kMULTILINESTRING:
1816  ndims = 2;
1817  max_nof_sizes = items_count + 2 * max_nof_values / 3;
1818  break;
1819  case kMULTIPOLYGON:
1820  ndims = 3;
1821  max_nof_sizes = items_count + max_nof_values;
1822  break;
1823  case kTEXT:
1824  switch (ti.get_compression()) {
1825  case kENCODING_NONE:
1826  ndims = 1;
1827  max_nof_sizes = items_count + max_nof_values / 3;
1828  break;
1829  case kENCODING_DICT:
1830  ndims = 0;
1831  break;
1832  default:
1833  UNREACHABLE();
1834  }
1835  break;
1836  default:
1837  UNREACHABLE();
1838  }
1839 }
1840 
1841 inline int64_t getFlatBufferSize(int64_t items_count,
1842  int64_t max_nof_values,
1843  const SQLTypeInfo& ti) {
1844  if (ti.get_type() == kPOINT) {
1845  // to be deprecated
1846  FlatBufferManager::GeoPoint metadata{items_count,
1847  ti.get_input_srid(),
1848  ti.get_output_srid(),
1851  GeoPointFormatId, reinterpret_cast<const int8_t*>(&metadata));
1852  } else {
1853  size_t ndims = 0;
1854  int64_t max_nof_sizes = 0;
1855  getFlatBufferNDimsAndSizes(items_count, max_nof_values, ti, ndims, max_nof_sizes);
1857  /* ndims= */ ndims,
1858  /* total_items_count= */ items_count,
1859  /* total sizes count= */ max_nof_sizes,
1860  /* total values count= */ max_nof_values,
1861  ti.toValueType(),
1862  /* user data size= */ sizeof(SQLTypeInfoLite));
1863  }
1864 }
1865 
1866 typedef union {
1867  struct {
1868  int8_t i8;
1869  };
1870  struct {
1871  int16_t i16;
1872  };
1873  struct {
1874  int32_t i32;
1875  };
1876  struct {
1877  int64_t i64;
1878  };
1879  struct {
1880  float f32;
1881  };
1882  struct {
1883  double f64;
1884  };
1885  struct {
1886  uint32_t geoint[2];
1887  };
1888  struct {
1889  double geodouble[2];
1890  };
1891 } null_value_t;
1892 
1894  null_value_t null_value{};
1895  switch (ti.get_type()) {
1896  case kBOOLEAN:
1897  null_value.i8 = NULL_BOOLEAN;
1898  break;
1899  case kTINYINT:
1900  null_value.i8 = NULL_TINYINT;
1901  break;
1902  case kSMALLINT:
1903  null_value.i16 = NULL_SMALLINT;
1904  break;
1905  case kINT:
1906  null_value.i32 = NULL_INT;
1907  break;
1908  case kBIGINT:
1909  null_value.i64 = NULL_BIGINT;
1910  break;
1911  case kFLOAT:
1912  null_value.f32 = NULL_FLOAT;
1913  break;
1914  case kDOUBLE:
1915  null_value.f64 = NULL_DOUBLE;
1916  break;
1917  case kPOINT:
1918  case kMULTIPOINT:
1919  case kLINESTRING:
1920  case kMULTILINESTRING:
1921  case kPOLYGON:
1922  case kMULTIPOLYGON:
1923  if (ti.get_compression() == kENCODING_GEOINT) {
1924  null_value.geoint[0] = null_value.geoint[1] = NULL_ARRAY_COMPRESSED_32;
1925  } else if (ti.get_compression() == kENCODING_NONE) {
1926  null_value.geodouble[0] = null_value.geodouble[1] = NULL_ARRAY_DOUBLE;
1927  } else {
1928  UNREACHABLE();
1929  }
1930  break;
1931  case kARRAY:
1932  switch (ti.get_subtype()) {
1933  case kBOOLEAN:
1934  null_value.i8 = NULL_ARRAY_BOOLEAN;
1935  break;
1936  case kTINYINT:
1937  null_value.i8 = NULL_ARRAY_TINYINT;
1938  break;
1939  case kSMALLINT:
1940  null_value.i16 = NULL_ARRAY_SMALLINT;
1941  break;
1942  case kINT:
1943  null_value.i32 = NULL_ARRAY_INT;
1944  break;
1945  case kTIMESTAMP:
1946  case kTIME:
1947  case kDATE:
1948  case kINTERVAL_DAY_TIME:
1949  case kINTERVAL_YEAR_MONTH:
1950  case kDECIMAL:
1951  case kNUMERIC:
1952  case kBIGINT:
1953  null_value.i64 = NULL_ARRAY_BIGINT;
1954  break;
1955  case kFLOAT:
1956  null_value.f32 = NULL_ARRAY_FLOAT;
1957  break;
1958  case kDOUBLE:
1959  null_value.f64 = NULL_ARRAY_FLOAT;
1960  break;
1961  case kTEXT:
1962  if (ti.get_compression() == kENCODING_DICT) {
1963  CHECK_EQ(ti.get_logical_size(), 4);
1964  null_value.i32 = NULL_ARRAY_COMPRESSED_32;
1965  } else if (ti.get_compression() == kENCODING_NONE) {
1966  null_value.i8 = NULL_ARRAY_TINYINT;
1967  } else {
1968  UNREACHABLE();
1969  }
1970  break;
1971  default:
1972  UNREACHABLE();
1973  break;
1974  }
1975  break;
1976  case kTEXT:
1977  if (ti.get_compression() == kENCODING_DICT) {
1978  CHECK_EQ(ti.get_logical_size(), 4);
1979  null_value.i32 = NULL_INT;
1980  } else if (ti.get_compression() == kENCODING_NONE) {
1981  null_value.i32 = NULL_TINYINT;
1982  } else {
1983  UNREACHABLE();
1984  }
1985  break;
1986  default:
1987  UNREACHABLE();
1988  break;
1989  }
1990  return null_value;
1991 }
1992 
1994  int64_t items_count,
1995  int64_t max_nof_values,
1996  const SQLTypeInfo& ti) {
1997  if (ti.get_type() == kPOINT) {
1998  // to be deprecated
1999  FlatBufferManager::GeoPoint metadata{items_count,
2000  ti.get_input_srid(),
2001  ti.get_output_srid(),
2003  m.initialize(GeoPointFormatId, reinterpret_cast<const int8_t*>(&metadata));
2004  } else {
2005  size_t ndims = 0;
2006  int64_t max_nof_sizes = 0;
2007  getFlatBufferNDimsAndSizes(items_count, max_nof_values, ti, ndims, max_nof_sizes);
2008  SQLTypeInfoLite ti_lite = ti.toLite();
2009  null_value_t null_value = get_null_value(ti);
2010  int8_t* null_value_ptr = &null_value.i8;
2011  auto status = m.initializeNestedArray(
2012  /* ndims= */ ndims,
2013  /* total_items_count= */ items_count,
2014  /* total_sizes_count= */ max_nof_sizes,
2015  /* total_values_count= */ max_nof_values,
2016  ti.toValueType(),
2017  /* null value buffer=*/null_value_ptr, // null value buffer size
2018  // is defined by value type
2019  /* user data buffer=*/reinterpret_cast<const int8_t*>(&ti_lite),
2020  /* user data buffer size=*/sizeof(SQLTypeInfoLite));
2022  }
2023 }
2024 
2026  size_t index;
2029 };
2030 
2031 inline bool geo_promoted_type_match(const SQLTypes a, const SQLTypes b) {
2032  return (a == b) || (a == kPOINT && b == kMULTIPOINT) ||
2033  (a == kLINESTRING && b == kMULTILINESTRING) ||
2034  (a == kPOLYGON && b == kMULTIPOLYGON);
2035 }
int8_t tinyintval
Definition: Datum.h:73
bool geo_promoted_type_match(const SQLTypes a, const SQLTypes b)
Definition: sqltypes.h:2031
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:392
void set_compression(EncodingType c)
Definition: sqltypes.h:481
void set_size(int s)
Definition: sqltypes.h:478
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:702
shared::StringDictKey dict_key_
Definition: sqltypes.h:1284
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:588
static constexpr int32_t kMaxNumericPrecision
Definition: sqltypes.h:58
Definition: sqltypes.h:76
bool is_text_encoding_dict_array() const
Definition: sqltypes.h:620
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:1046
std::vector< ArrayDatum > * arraysPtr
Definition: sqltypes.h:235
#define NULL_ARRAY_INT
bool is_column_list_array() const
Definition: sqltypes.h:610
SQLTypes subtype
Definition: sqltypes_lite.h:54
const shared::StringDictKey & getStringDictKeySkipCompParamCheck() const
Definition: sqltypes.h:1070
#define NULL_FLOAT
bool is_null
Definition: Datum.h:59
#define NULL_BIGINT
bool is_time_or_date() const
Definition: sqltypes.h:1032
SQLTypeInfo get_nullable_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1490
#define LOG(tag)
Definition: Logger.h:285
HOST DEVICE bool operator==(const SQLTypeInfo &rhs) const
Definition: sqltypes.h:682
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:57
bool is_fp() const
Definition: sqltypes.h:573
HOST DEVICE int get_scale() const
Definition: sqltypes.h:396
bool is_varlen() const
Definition: sqltypes.h:631
#define NULL_ARRAY_SMALLINT
int8_t boolval
Definition: Datum.h:72
std::string get_compression_name() const
Definition: sqltypes.h:522
VarlenDatum * arrayval
Definition: Datum.h:79
#define UNREACHABLE()
Definition: Logger.h:338
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:471
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:1472
void initializeFlatBuffer(FlatBufferManager &m, int64_t items_count, int64_t max_nof_values, const SQLTypeInfo &ti)
Definition: sqltypes.h:1993
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:930
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
void setStringDictKeySkipCompParamCheck(const shared::StringDictKey &dict_key)
Definition: sqltypes.h:1074
bool is_number() const
Definition: sqltypes.h:576
int32_t intval
Definition: Datum.h:75
bool is_time() const
Definition: sqltypes.h:579
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:58
#define NULL_INT
SQLTypeInfo ti
Definition: sqltypes.h:2027
int32_t StringOffsetT
Definition: sqltypes.h:1495
#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:474
float floatval
Definition: Datum.h:77
std::string to_string() const
Definition: sqltypes.h:528
EncodingType
Definition: sqltypes.h:240
int get_physical_cols() const
Definition: sqltypes.h:432
bool is_fixlen_array() const
Definition: sqltypes.h:591
bool is_castable(const SQLTypeInfo &new_type_info) const
Definition: sqltypes.h:715
#define IS_INTERVAL(T)
Definition: sqltypes.h:313
void set_fixed_size()
Definition: sqltypes.h:479
std::shared_ptr< int8_t > ManagedPtr
Definition: sqltypes.h:191
HOST DEVICE bool operator!=(const SQLTypeInfo &rhs) const
Definition: sqltypes.h:674
int get_logical_size() const
Definition: sqltypes.h:421
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:1281
bool is_integer() const
Definition: sqltypes.h:567
bool is_subtype_dict_encoded_string() const
Definition: sqltypes.h:651
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:606
#define NULL_ARRAY_COMPRESSED_32
SQLTypes subtype
Definition: sqltypes.h:1271
bool has_same_itemtype(const SQLTypeInfo &other) const
Definition: sqltypes.h:664
bool is_text_encoding_dict() const
Definition: sqltypes.h:617
void set_scale(int s)
Definition: sqltypes.h:475
bool notnull
Definition: sqltypes.h:1275
int64_t bigintval
Definition: Datum.h:76
bool has_bounds() const
Definition: sqltypes.h:457
HostArrayDatum(size_t const l, int8_t *p, CUSTOM_DELETER custom_deleter)
Definition: sqltypes.h:204
FlatBufferManager::ValueType toValueType() const
Definition: sqltypes.h:1227
bool is_timeinterval() const
Definition: sqltypes.h:594
#define NULL_ARRAY_FLOAT
void setStorageSize()
Definition: sqltypes.h:1053
bool supportsFlatBuffer() const
Definition: sqltypes.h:1088
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:763
int64_t getFlatBufferSize(int64_t items_count, int64_t max_nof_values, const SQLTypeInfo &ti)
Definition: sqltypes.h:1841
ManagedPtr data_ptr
Definition: sqltypes.h:213
int32_t i32
Definition: sqltypes.h:1874
int is_logical_geo_type() const
Definition: sqltypes.h:411
HostArrayDatum()=default
int16_t smallintval
Definition: Datum.h:74
bool is_dict_intersection() const
Definition: sqltypes.h:660
bool is_dict_encoded_type() const
Definition: sqltypes.h:655
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:1083
std::string toString() const
Definition: sqltypes.h:525
bool is_boolean() const
Definition: sqltypes.h:582
HostArrayDatum(size_t const l, int8_t *p, bool const n)
Definition: sqltypes.h:198
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1703
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:541
SQLTypeInfo(SQLTypes t, bool n, EncodingType c)
Definition: sqltypes.h:372
SQLTypeInfo get_array_type() const
Definition: sqltypes.h:1010
EncodingType compression
Definition: sqltypes.h:1276
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:476
bool is_buffer() const
Definition: sqltypes.h:623
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:1868
SQLTypeInfoLite toLite() const
Definition: sqltypes.h:1109
bool is_column() const
Definition: sqltypes.h:600
DEVICE DeviceArrayDatum()
Definition: sqltypes.h:217
HOST DEVICE bool is_null(const Datum &d) const
Definition: sqltypes.h:868
auto generate_column_type(const SQLTypeInfo &elem_ti)
Definition: sqltypes.h:1629
void set_comp_param(int p)
Definition: sqltypes.h:482
HOST DEVICE int get_storage_size() const
Definition: sqltypes.h:1286
#define CHECK_LT(x, y)
Definition: Logger.h:303
Definition: sqltypes.h:79
Definition: sqltypes.h:80
bool dict_intersection
Definition: sqltypes.h:1279
int16_t i16
Definition: sqltypes.h:1871
static std::string comp_name[kENCODING_LAST]
Definition: sqltypes.h:1282
double f64
Definition: sqltypes.h:1883
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
void setUsesFlatBuffer(bool uses_flatbuffer=true)
Definition: sqltypes.h:1079
bool is_date_in_days() const
Definition: sqltypes.h:1018
int get_array_context_logical_size() const
Definition: sqltypes.h:691
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:1701
bool uses_flatbuffer_
Definition: sqltypes.h:1285
int32_t ArrayOffsetT
Definition: sqltypes.h:1496
void set_dimension(int d)
Definition: sqltypes.h:472
void setStringDictKey(const shared::StringDictKey &dict_key)
Definition: sqltypes.h:1063
SQLTypes get_int_type_by_size(size_t const nbytes)
Definition: sqltypes.h:1454
bool is_none_encoded_string() const
Definition: sqltypes.h:647
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:484
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:824
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:1789
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:480
#define NULL_TINYINT
#define NULL_ARRAY_DOUBLE
bool is_column_list() const
Definition: sqltypes.h:603
bool is_variable_size() const
Definition: sqltypes.h:419
bool g_enable_watchdog false
Definition: Execute.cpp:80
void set_notnull(bool n)
Definition: sqltypes.h:477
#define CHECK(condition)
Definition: Logger.h:291
bool is_geometry() const
Definition: sqltypes.h:597
bool is_encoded_timestamp() const
Definition: sqltypes.h:1049
bool is_high_precision_timestamp() const
Definition: sqltypes.h:1036
SQLTypes type
Definition: sqltypes.h:1270
#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:558
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:643
Definition: sqltypes.h:72
bool is_varlen_indeed() const
Definition: sqltypes.h:637
#define NULL_ARRAY_BOOLEAN
bool is_string() const
Definition: sqltypes.h:561
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:626
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:614
bool is_string_array() const
Definition: sqltypes.h:564
size_t index
Definition: sqltypes.h:2026
Definition: Datum.h:71
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:977
bool is_decimal() const
Definition: sqltypes.h:570
int get_physical_coord_cols() const
Definition: sqltypes.h:451
#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:1277
bool is_date() const
Definition: sqltypes.h:1028
bool is_array() const
Definition: sqltypes.h:585
void set_precision(int d)
Definition: sqltypes.h:473
SQLTypeInfo get_nullable_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1484
int dimension
Definition: sqltypes.h:1272
HOST DEVICE bool is_null_point_coord_array(const int8_t *val, int array_size) const
Definition: sqltypes.h:963
double doubleval
Definition: Datum.h:78
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:1716
int64_t i64
Definition: sqltypes.h:1877
constexpr auto is_datetime(SQLTypes type)
Definition: sqltypes.h:325
const shared::StringDictKey & getStringDictKey() const
Definition: sqltypes.h:1057
HOST DEVICE bool is_null(const int8_t *val) const
Definition: sqltypes.h:905
size_t length
Definition: Datum.h:57
SQLTypes string_dict_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:565
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:470