OmniSciDB  72180abbfe
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sqltypes.h File Reference

Constants for Builtin SQL Types supported by OmniSci. More...

#include "StringTransform.h"
#include "funcannotations.h"
#include <cassert>
#include <cfloat>
#include <cstdint>
#include <ctime>
#include <limits>
#include <memory>
#include <string>
#include <type_traits>
#include <vector>
#include <string_view>
#include "../QueryEngine/DateAdd.h"
#include "../QueryEngine/DateTruncate.h"
#include "../QueryEngine/ExtractFromTime.h"
#include "InlineNullValues.h"
+ Include dependency graph for sqltypes.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  VarlenDatum
 
struct  DoNothingDeleter
 
struct  FreeDeleter
 
struct  HostArrayDatum
 
struct  DeviceArrayDatum
 
union  Datum
 
union  DataBlockPtr
 
class  SQLTypeInfo
 

Macros

#define IS_INTEGER(T)   (((T) == kINT) || ((T) == kSMALLINT) || ((T) == kBIGINT) || ((T) == kTINYINT))
 
#define IS_NUMBER(T)
 
#define IS_STRING(T)   (((T) == kTEXT) || ((T) == kVARCHAR) || ((T) == kCHAR))
 
#define IS_GEO(T)   (((T) == kPOINT) || ((T) == kLINESTRING) || ((T) == kPOLYGON) || ((T) == kMULTIPOLYGON))
 
#define IS_INTERVAL(T)   ((T) == kINTERVAL_DAY_TIME || (T) == kINTERVAL_YEAR_MONTH)
 
#define IS_DECIMAL(T)   ((T) == kNUMERIC || (T) == kDECIMAL)
 
#define IS_GEO_POLY(T)   (((T) == kPOLYGON) || ((T) == kMULTIPOLYGON))
 
#define NULL_BOOLEAN   INT8_MIN
 
#define NULL_TINYINT   INT8_MIN
 
#define NULL_SMALLINT   INT16_MIN
 
#define NULL_INT   INT32_MIN
 
#define NULL_BIGINT   INT64_MIN
 
#define NULL_FLOAT   FLT_MIN
 
#define NULL_DOUBLE   DBL_MIN
 
#define NULL_ARRAY_BOOLEAN   (INT8_MIN + 1)
 
#define NULL_ARRAY_TINYINT   (INT8_MIN + 1)
 
#define NULL_ARRAY_SMALLINT   (INT16_MIN + 1)
 
#define NULL_ARRAY_INT   (INT32_MIN + 1)
 
#define NULL_ARRAY_BIGINT   (INT64_MIN + 1)
 
#define NULL_ARRAY_FLOAT   (FLT_MIN * 2.0)
 
#define NULL_ARRAY_DOUBLE   (DBL_MIN * 2.0)
 
#define NULL_ARRAY_COMPRESSED_32   0x80000000U
 
#define TRANSIENT_DICT_ID   0
 
#define TRANSIENT_DICT(ID)   (-(ID))
 
#define REGULAR_DICT(TRANSIENTID)   (-(TRANSIENTID))
 

Typedefs

using ArrayDatum = std::conditional_t< is_cuda_compiler(), DeviceArrayDatum, HostArrayDatum >
 
using StringOffsetT = int32_t
 
using ArrayOffsetT = int32_t
 

Enumerations

enum  SQLTypes {
  kNULLT = 0, kBOOLEAN = 1, kCHAR = 2, kVARCHAR = 3,
  kNUMERIC = 4, kDECIMAL = 5, kINT = 6, kSMALLINT = 7,
  kFLOAT = 8, kDOUBLE = 9, kTIME = 10, kTIMESTAMP = 11,
  kBIGINT = 12, kTEXT = 13, kDATE = 14, kARRAY = 15,
  kINTERVAL_DAY_TIME = 16, kINTERVAL_YEAR_MONTH = 17, kPOINT = 18, kLINESTRING = 19,
  kPOLYGON = 20, kMULTIPOLYGON = 21, kTINYINT = 22, kGEOMETRY = 23,
  kGEOGRAPHY = 24, kEVAL_CONTEXT_TYPE = 25, kVOID = 26, kCURSOR = 27,
  kSQLTYPE_LAST = 28
}
 
enum  EncodingType {
  kINT8 = 0, kINT16 = 1, kINT32 = 2, kINT64 = 3,
  kUINT8 = 4, kUINT16 = 5, kUINT32 = 6, kUINT64 = 7,
  kENCODING_NONE = 0, kENCODING_FIXED = 1, kENCODING_RL = 2, kENCODING_DIFF = 3,
  kENCODING_DICT = 4, kENCODING_SPARSE = 5, kENCODING_GEOINT = 6, kENCODING_DATE_IN_DAYS = 7,
  kENCODING_LAST = 8
}
 

Functions

DEVICE constexpr bool is_cuda_compiler ()
 
constexpr auto is_datetime (SQLTypes type)
 
SQLTypes decimal_to_int_type (const SQLTypeInfo &)
 
Datum StringToDatum (std::string_view s, SQLTypeInfo &ti)
 
std::string DatumToString (Datum d, const SQLTypeInfo &ti)
 
bool DatumEqual (const Datum, const Datum, const SQLTypeInfo &ti)
 
int64_t convert_decimal_value_to_scale (const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
 
SQLTypeInfo get_logical_type_info (const SQLTypeInfo &type_info)
 
SQLTypeInfo get_nullable_type_info (const SQLTypeInfo &type_info)
 
SQLTypeInfo get_nullable_logical_type_info (const SQLTypeInfo &type_info)
 
template<class T >
constexpr int64_t inline_int_null_value ()
 
template<class T >
constexpr int64_t inline_int_null_array_value ()
 
template<class T >
constexpr int64_t max_valid_int_value ()
 
int8_t * appendDatum (int8_t *buf, Datum d, const SQLTypeInfo &ti)
 

Detailed Description

Constants for Builtin SQL Types supported by OmniSci.

Author
Wei Hong wei@m.nosp@m.ap-d.nosp@m..com

Definition in file sqltypes.h.

Macro Definition Documentation

#define IS_DECIMAL (   T)    ((T) == kNUMERIC || (T) == kDECIMAL)

Definition at line 175 of file sqltypes.h.

#define IS_GEO_POLY (   T)    (((T) == kPOLYGON) || ((T) == kMULTIPOLYGON))
#define IS_INTEGER (   T)    (((T) == kINT) || ((T) == kSMALLINT) || ((T) == kBIGINT) || ((T) == kTINYINT))
#define IS_INTERVAL (   T)    ((T) == kINTERVAL_DAY_TIME || (T) == kINTERVAL_YEAR_MONTH)

Definition at line 174 of file sqltypes.h.

Referenced by SQLTypeInfo::is_timeinterval().

#define IS_NUMBER (   T)
Value:
(((T) == kINT) || ((T) == kSMALLINT) || ((T) == kDOUBLE) || ((T) == kFLOAT) || \
((T) == kBIGINT) || ((T) == kNUMERIC) || ((T) == kDECIMAL) || ((T) == kTINYINT))
Definition: sqltypes.h:46

Definition at line 168 of file sqltypes.h.

Referenced by SQLTypeInfo::is_number(), and anonymous_namespace{EquiJoinCondition.cpp}::make_composite_equals_impl().

#define NULL_ARRAY_BIGINT   (INT64_MIN + 1)
#define NULL_ARRAY_BOOLEAN   (INT8_MIN + 1)

Definition at line 186 of file sqltypes.h.

Referenced by FixedLengthArrayNoneEncoder::is_null().

#define NULL_ARRAY_COMPRESSED_32   0x80000000U

Definition at line 194 of file sqltypes.h.

Referenced by SQLTypeInfo::is_null_point_coord_array().

#define NULL_ARRAY_FLOAT   (FLT_MIN * 2.0)
#define NULL_ARRAY_INT   (INT32_MIN + 1)
#define NULL_ARRAY_SMALLINT   (INT16_MIN + 1)
#define NULL_ARRAY_TINYINT   (INT8_MIN + 1)
#define NULL_DOUBLE   DBL_MIN

Definition at line 184 of file sqltypes.h.

Referenced by import_export::TypedImportBuffer::add_value(), import_export::TypedImportBuffer::add_values(), Parser::InsertValuesStmt::analyze(), CodeGenerator::codegenDiv(), CodeGenerator::codegenFpArith(), CodeGenerator::codegenIsNullNumber(), geospatial::compress_null_point(), GeoPointValueConverter::convertToColumnarFormat(), GeoLinestringValueConverter::convertToColumnarFormat(), GeoPolygonValueConverter::convertToColumnarFormat(), GeoMultiPolygonValueConverter::convertToColumnarFormat(), import_export::QueryExporterCSV::exportResults(), float_to_double_bin(), Geo_namespace::GeoPoint::getColumns(), Geo_namespace::GeoLineString::getColumns(), Geo_namespace::GeoPolygon::getColumns(), Geo_namespace::GeoMultiPolygon::getColumns(), Geo_namespace::GeoTypesFactory::getNullGeoColumns(), inline_fp_null_value< double >(), CgenState::inlineFpNull(), import_export::anonymous_namespace{QueryExporterGDAL.cpp}::insert_array_column(), import_export::anonymous_namespace{QueryExporterGDAL.cpp}::insert_scalar_column(), SQLTypeInfo::is_null(), Analyzer::anonymous_namespace{Analyzer.cpp}::is_null_value(), ResultSet::isNull(), ResultSet::makeTargetValue(), import_export::NullDatum(), import_export::Importer::set_geo_physical_import_buffer(), import_export::Importer::set_geo_physical_import_buffer_columnar(), Analyzer::Constant::set_null_value(), import_export::TDatumToDatum(), FixedLengthArrayNoneEncoder::update_elem_stats(), ArrayNoneEncoder::update_elem_stats(), DBHandler::value_to_thrift(), and DBHandler::value_to_thrift_column().

#define REGULAR_DICT (   TRANSIENTID)    (-(TRANSIENTID))

Definition at line 198 of file sqltypes.h.

Referenced by Executor::getStringDictionaryProxy().

Typedef Documentation

Definition at line 129 of file sqltypes.h.

using ArrayOffsetT = int32_t

Definition at line 856 of file sqltypes.h.

using StringOffsetT = int32_t

Definition at line 855 of file sqltypes.h.

Enumeration Type Documentation

Enumerator
kINT8 
kINT16 
kINT32 
kINT64 
kUINT8 
kUINT16 
kUINT32 
kUINT64 
kENCODING_NONE 
kENCODING_FIXED 
kENCODING_RL 
kENCODING_DIFF 
kENCODING_DICT 
kENCODING_SPARSE 
kENCODING_GEOINT 
kENCODING_DATE_IN_DAYS 
kENCODING_LAST 

Definition at line 154 of file sqltypes.h.

154  {
155  kENCODING_NONE = 0, // no encoding
156  kENCODING_FIXED = 1, // Fixed-bit encoding
157  kENCODING_RL = 2, // Run Length encoding
158  kENCODING_DIFF = 3, // Differential encoding
159  kENCODING_DICT = 4, // Dictionary encoding
160  kENCODING_SPARSE = 5, // Null encoding for sparse columns
161  kENCODING_GEOINT = 6, // Encoding coordinates as intergers
162  kENCODING_DATE_IN_DAYS = 7, // Date encoding in days
163  kENCODING_LAST = 8
164 };
enum SQLTypes
Enumerator
kNULLT 
kBOOLEAN 
kCHAR 
kVARCHAR 
kNUMERIC 
kDECIMAL 
kINT 
kSMALLINT 
kFLOAT 
kDOUBLE 
kTIME 
kTIMESTAMP 
kBIGINT 
kTEXT 
kDATE 
kARRAY 
kINTERVAL_DAY_TIME 
kINTERVAL_YEAR_MONTH 
kPOINT 
kLINESTRING 
kPOLYGON 
kMULTIPOLYGON 
kTINYINT 
kGEOMETRY 
kGEOGRAPHY 
kEVAL_CONTEXT_TYPE 
kVOID 
kCURSOR 
kSQLTYPE_LAST 

Definition at line 39 of file sqltypes.h.

39  {
40  kNULLT = 0, // type for null values
41  kBOOLEAN = 1,
42  kCHAR = 2,
43  kVARCHAR = 3,
44  kNUMERIC = 4,
45  kDECIMAL = 5,
46  kINT = 6,
47  kSMALLINT = 7,
48  kFLOAT = 8,
49  kDOUBLE = 9,
50  kTIME = 10,
51  kTIMESTAMP = 11,
52  kBIGINT = 12,
53  kTEXT = 13,
54  kDATE = 14,
55  kARRAY = 15,
56  kINTERVAL_DAY_TIME = 16,
58  kPOINT = 18,
59  kLINESTRING = 19,
60  kPOLYGON = 20,
61  kMULTIPOLYGON = 21,
62  kTINYINT = 22,
63  kGEOMETRY = 23,
64  kGEOGRAPHY = 24,
65  kEVAL_CONTEXT_TYPE = 25, // Placeholder Type for ANY
66  kVOID = 26,
67  kCURSOR = 27,
68  kSQLTYPE_LAST = 28
69 };
Definition: sqltypes.h:50
Definition: sqltypes.h:66
Definition: sqltypes.h:53
Definition: sqltypes.h:54
Definition: sqltypes.h:42
Definition: sqltypes.h:46

Function Documentation

int8_t* appendDatum ( int8_t *  buf,
Datum  d,
const SQLTypeInfo ti 
)
inline

Definition at line 858 of file sqltypes.h.

References Datum::bigintval, Datum::boolval, Datum::doubleval, Datum::floatval, SQLTypeInfo::get_type(), Datum::intval, kBIGINT, kBOOLEAN, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, kNUMERIC, kSMALLINT, kTIME, kTIMESTAMP, kTINYINT, Datum::smallintval, and Datum::tinyintval.

Referenced by RelAlgExecutor::executeSimpleInsert(), import_export::NullArray(), import_export::StringToArray(), and import_export::TDatumToArrayDatum().

858  {
859  switch (ti.get_type()) {
860  case kBOOLEAN:
861  *(bool*)buf = d.boolval;
862  return buf + sizeof(bool);
863  case kNUMERIC:
864  case kDECIMAL:
865  case kBIGINT:
866  *(int64_t*)buf = d.bigintval;
867  return buf + sizeof(int64_t);
868  case kINT:
869  *(int32_t*)buf = d.intval;
870  return buf + sizeof(int32_t);
871  case kSMALLINT:
872  *(int16_t*)buf = d.smallintval;
873  return buf + sizeof(int16_t);
874  case kTINYINT:
875  *(int8_t*)buf = d.tinyintval;
876  return buf + sizeof(int8_t);
877  case kFLOAT:
878  *(float*)buf = d.floatval;
879  return buf + sizeof(float);
880  case kDOUBLE:
881  *(double*)buf = d.doubleval;
882  return buf + sizeof(double);
883  case kTIME:
884  case kTIMESTAMP:
885  case kDATE:
886  *reinterpret_cast<int64_t*>(buf) = d.bigintval;
887  return buf + sizeof(int64_t);
888  default:
889  return nullptr;
890  }
891 }
int8_t tinyintval
Definition: sqltypes.h:133
Definition: sqltypes.h:50
bool boolval
Definition: sqltypes.h:132
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:257
int32_t intval
Definition: sqltypes.h:135
float floatval
Definition: sqltypes.h:137
int64_t bigintval
Definition: sqltypes.h:136
int16_t smallintval
Definition: sqltypes.h:134
Definition: sqltypes.h:54
Definition: sqltypes.h:46
double doubleval
Definition: sqltypes.h:138

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int64_t convert_decimal_value_to_scale ( const int64_t  decimal_value,
const SQLTypeInfo type_info,
const SQLTypeInfo new_type_info 
)

Definition at line 319 of file Datum.cpp.

References SQLTypeInfo::get_scale().

Referenced by import_export::TypedImportBuffer::add_value(), Analyzer::Constant::cast_number(), anonymous_namespace{ArrowImporter.h}::ArrowValue< Decimal128 >::operator const DATA_TYPE(), and anonymous_namespace{TypedDataAccessors.h}::put_scalar().

321  {
322  auto converted_decimal_value = decimal_value;
323  if (new_type_info.get_scale() > type_info.get_scale()) {
324  for (int i = 0; i < new_type_info.get_scale() - type_info.get_scale(); i++) {
325  converted_decimal_value *= 10;
326  }
327  } else if (new_type_info.get_scale() < type_info.get_scale()) {
328  for (int i = 0; i < type_info.get_scale() - new_type_info.get_scale(); i++) {
329  if (converted_decimal_value > 0) {
330  converted_decimal_value = (converted_decimal_value + 5) / 10;
331  } else {
332  converted_decimal_value = (converted_decimal_value - 5) / 10;
333  }
334  }
335  }
336  return converted_decimal_value;
337 }
HOST DEVICE int get_scale() const
Definition: sqltypes.h:262

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool DatumEqual ( const Datum  ,
const Datum  ,
const SQLTypeInfo ti 
)

Definition at line 187 of file Datum.cpp.

References Datum::bigintval, Datum::boolval, Datum::doubleval, Datum::floatval, SQLTypeInfo::get_compression(), SQLTypeInfo::get_type(), Datum::intval, kBIGINT, kBOOLEAN, kCHAR, kDATE, kDECIMAL, kDOUBLE, kENCODING_DICT, kFLOAT, kINT, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kNUMERIC, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, kVARCHAR, Datum::smallintval, Datum::stringval, and Datum::tinyintval.

Referenced by ChunkMetadata::operator==().

187  {
188  switch (ti.get_type()) {
189  case kBOOLEAN:
190  return a.boolval == b.boolval;
191  case kBIGINT:
192  case kNUMERIC:
193  case kDECIMAL:
194  return a.bigintval == b.bigintval;
195  case kINT:
196  return a.intval == b.intval;
197  case kSMALLINT:
198  return a.smallintval == b.smallintval;
199  case kTINYINT:
200  return a.tinyintval == b.tinyintval;
201  case kFLOAT:
202  return a.floatval == b.floatval;
203  case kDOUBLE:
204  return a.doubleval == b.doubleval;
205  case kTIME:
206  case kTIMESTAMP:
207  case kDATE:
208  case kINTERVAL_DAY_TIME:
210  return a.bigintval == b.bigintval;
211  case kTEXT:
212  case kVARCHAR:
213  case kCHAR:
214  if (ti.get_compression() == kENCODING_DICT) {
215  return a.intval == b.intval;
216  }
217  return *a.stringval == *b.stringval;
218  default:
219  return false;
220  }
221  return false;
222 }
Definition: sqltypes.h:50
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:257
Definition: sqltypes.h:53
Definition: sqltypes.h:54
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:265
Definition: sqltypes.h:42
Definition: sqltypes.h:46

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string DatumToString ( Datum  d,
const SQLTypeInfo ti 
)

Definition at line 227 of file Datum.cpp.

References Datum::bigintval, Datum::boolval, Datum::doubleval, Datum::floatval, SQLTypeInfo::get_dimension(), SQLTypeInfo::get_scale(), SQLTypeInfo::get_type(), SQLTypeInfo::get_type_name(), Datum::intval, kBIGINT, kBOOLEAN, kCHAR, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kNUMERIC, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, kVARCHAR, Datum::smallintval, Datum::stringval, Datum::tinyintval, and to_string().

Referenced by Analyzer::Constant::cast_to_string(), datum_to_string(), anonymous_namespace{ArrowImporter.h}::ArrowValue< int64_t >::operator const std::string(), Analyzer::Constant::toString(), Fragmenter_Namespace::InsertOrderFragmenter::updateChunkStats(), and ScalarExprToSql::visitConstant().

227  {
228  switch (ti.get_type()) {
229  case kBOOLEAN:
230  if (d.boolval) {
231  return "t";
232  }
233  return "f";
234  case kNUMERIC:
235  case kDECIMAL: {
236  // we need to consider buf_size including the scale and null terminator
237  char str[ti.get_dimension() + ti.get_scale() + 2];
238  double v = (double)d.bigintval / pow(10, ti.get_scale());
239  sprintf(str, "%*.*f", ti.get_dimension(), ti.get_scale(), v);
240  return std::string(str);
241  }
242  case kINT:
243  return std::to_string(d.intval);
244  case kSMALLINT:
245  return std::to_string(d.smallintval);
246  case kTINYINT:
247  return std::to_string(d.tinyintval);
248  case kBIGINT:
249  return std::to_string(d.bigintval);
250  case kFLOAT:
251  return std::to_string(d.floatval);
252  case kDOUBLE:
253  return std::to_string(d.doubleval);
254  case kTIME: {
255  std::tm tm_struct;
256  gmtime_r(reinterpret_cast<time_t*>(&d.bigintval), &tm_struct);
257  char buf[9];
258  strftime(buf, 9, "%T", &tm_struct);
259  return std::string(buf);
260  }
261  case kTIMESTAMP: {
262  std::tm tm_struct{0};
263  if (ti.get_dimension() > 0) {
264  std::string t = std::to_string(d.bigintval);
265  int cp = std::max(static_cast<int>(t.length()) - ti.get_dimension(), 1);
266  time_t sec = std::stoll(t.substr(0, cp));
267  t = t.substr(cp);
268  gmtime_r(&sec, &tm_struct);
269  char buf[21];
270  strftime(buf, 21, "%F %T.", &tm_struct);
271  return std::string(buf) += t;
272  } else {
273  time_t sec = static_cast<time_t>(d.bigintval);
274  gmtime_r(&sec, &tm_struct);
275  char buf[20];
276  strftime(buf, 20, "%F %T", &tm_struct);
277  return std::string(buf);
278  }
279  }
280  case kDATE: {
281  std::tm tm_struct;
282  time_t ntimeval = static_cast<time_t>(d.bigintval);
283  gmtime_r(&ntimeval, &tm_struct);
284  char buf[11];
285  strftime(buf, 11, "%F", &tm_struct);
286  return std::string(buf);
287  }
288  case kINTERVAL_DAY_TIME:
289  return std::to_string(d.bigintval) + " ms (day-time interval)";
291  return std::to_string(d.bigintval) + " month(s) (year-month interval)";
292  case kTEXT:
293  case kVARCHAR:
294  case kCHAR:
295  return *d.stringval;
296  default:
297  throw std::runtime_error("Internal error: invalid type " + ti.get_type_name() +
298  " in DatumToString.");
299  }
300  return "";
301 }
int8_t tinyintval
Definition: sqltypes.h:133
Definition: sqltypes.h:50
bool boolval
Definition: sqltypes.h:132
HOST DEVICE int get_scale() const
Definition: sqltypes.h:262
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:257
int32_t intval
Definition: sqltypes.h:135
std::string to_string(char const *&&v)
float floatval
Definition: sqltypes.h:137
int64_t bigintval
Definition: sqltypes.h:136
int16_t smallintval
Definition: sqltypes.h:134
std::string * stringval
Definition: sqltypes.h:141
Definition: sqltypes.h:53
Definition: sqltypes.h:54
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:259
std::string get_type_name() const
Definition: sqltypes.h:360
Definition: sqltypes.h:42
Definition: sqltypes.h:46
double doubleval
Definition: sqltypes.h:138

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SQLTypes decimal_to_int_type ( const SQLTypeInfo )

Definition at line 303 of file Datum.cpp.

References CHECK(), SQLTypeInfo::get_size(), kBIGINT, kINT, kNULLT, kSMALLINT, and kTINYINT.

Referenced by import_export::TypedImportBuffer::add_arrow_values(), import_export::TypedImportBuffer::add_value(), CodeGenerator::codegen(), CodeGenerator::codegenIntConst(), anonymous_namespace{LogicalIR.cpp}::contains_unsafe_division(), import_export::Loader::distributeToShards(), extract_from_datum(), anonymous_namespace{ColumnIR.cpp}::get_col_decoder(), CgenState::getOrAddLiteral(), foreign_storage::AllowedParquetMetadataTypeMappings::isColumnMappingSupported(), ResultSet::makeTargetValue(), import_export::NullArrayDatum(), import_export::NullDatum(), import_export::TypedImportBuffer::pop_value(), import_export::TDatumToDatum(), anonymous_namespace{ExpressionRewrite.cpp}::ConstantFoldingVisitor::visitBinOper(), and anonymous_namespace{ExpressionRewrite.cpp}::ConstantFoldingVisitor::visitUOper().

303  {
304  switch (ti.get_size()) {
305  case 1:
306  return kTINYINT;
307  case 2:
308  return kSMALLINT;
309  case 4:
310  return kINT;
311  case 8:
312  return kBIGINT;
313  default:
314  CHECK(false);
315  }
316  return kNULLT;
317 }
CHECK(cgen_state)
Definition: sqltypes.h:46

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SQLTypeInfo get_logical_type_info ( const SQLTypeInfo type_info)
inline

Definition at line 807 of file sqltypes.h.

References SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_dimension(), SQLTypeInfo::get_notnull(), SQLTypeInfo::get_scale(), SQLTypeInfo::get_subtype(), SQLTypeInfo::get_type(), kARRAY, kENCODING_DATE_IN_DAYS, kENCODING_FIXED, and kENCODING_NONE.

Referenced by anonymous_namespace{ColumnarResults.cpp}::fixed_encoding_nullable_val(), anonymous_namespace{RelAlgExecutor.cpp}::get_logical_type_for_expr(), anonymous_namespace{TypedDataAccessors.h}::NullSentinelSupplier::get_null_sentinel_for_type(), get_nullable_logical_type_info(), get_target_info(), JoinHashTable::getHashJoinArgs(), getLeafColumnRange(), Parser::CaseExpr::normalize(), TableOptimizer::recomputeMetadata(), rows_to_columnar_results(), Fragmenter_Namespace::InsertOrderFragmenter::updateChunkStats(), and Fragmenter_Namespace::InsertOrderFragmenter::updateColumns().

807  {
808  EncodingType encoding = type_info.get_compression();
809  if (encoding == kENCODING_DATE_IN_DAYS ||
810  (encoding == kENCODING_FIXED && type_info.get_type() != kARRAY)) {
811  encoding = kENCODING_NONE;
812  }
813  return SQLTypeInfo(type_info.get_type(),
814  type_info.get_dimension(),
815  type_info.get_scale(),
816  type_info.get_notnull(),
817  encoding,
818  type_info.get_comp_param(),
819  type_info.get_subtype());
820 }
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:258
EncodingType
Definition: encodetypes.h:22
HOST DEVICE int get_scale() const
Definition: sqltypes.h:262
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:257
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:265
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:259
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:266
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:264

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SQLTypeInfo get_nullable_logical_type_info ( const SQLTypeInfo type_info)
inline

Definition at line 828 of file sqltypes.h.

References get_logical_type_info(), and get_nullable_type_info().

Referenced by anonymous_namespace{RelAlgExecutor.cpp}::get_logical_type_for_expr(), and RelAlgTranslator::translateArrayFunction().

828  {
829  SQLTypeInfo nullable_type_info = get_logical_type_info(type_info);
830  return get_nullable_type_info(nullable_type_info);
831 }
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:807
SQLTypeInfo get_nullable_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:822

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SQLTypeInfo get_nullable_type_info ( const SQLTypeInfo type_info)
inline

Definition at line 822 of file sqltypes.h.

References SQLTypeInfo::set_notnull().

Referenced by CodeGenerator::createInValuesBitmap(), Analyzer::Constant::do_cast(), and get_nullable_logical_type_info().

822  {
823  SQLTypeInfo nullable_type_info = type_info;
824  nullable_type_info.set_notnull(false);
825  return nullable_type_info;
826 }
void set_notnull(bool n)
Definition: sqltypes.h:354

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T >
constexpr int64_t inline_int_null_array_value ( )
inline

Definition at line 840 of file sqltypes.h.

840  {
841  return std::is_signed<T>::value ? std::numeric_limits<T>::min() + 1
842  : std::numeric_limits<T>::max() - 1;
843  // TODO: null_array values in signed types would step on max valid value
844  // in fixlen unsigned arrays, the max valid value may need to be lowered.
845 }
template<class T >
constexpr int64_t inline_int_null_value ( )
inline

Definition at line 834 of file sqltypes.h.

834  {
835  return std::is_signed<T>::value ? std::numeric_limits<T>::min()
836  : std::numeric_limits<T>::max();
837 }
DEVICE constexpr bool is_cuda_compiler ( )
inline

Definition at line 120 of file sqltypes.h.

120  {
121 #ifdef __CUDACC__
122  return true;
123 #else
124  return false;
125 #endif
126 }
constexpr auto is_datetime ( SQLTypes  type)

Definition at line 200 of file sqltypes.h.

References kDATE, kTIME, and kTIMESTAMP.

Referenced by SQLTypeInfo::is_time(), DateTimeStringValidate< SQL_TYPE >::operator()(), and RexLiteral::RexLiteral().

200  {
201  return type == kTIME || type == kTIMESTAMP || type == kDATE;
202 }
Definition: sqltypes.h:50
Definition: sqltypes.h:54

+ Here is the caller graph for this function:

template<class T >
constexpr int64_t max_valid_int_value ( )
inline

Definition at line 848 of file sqltypes.h.

848  {
849  return std::is_signed<T>::value ? std::numeric_limits<T>::max()
850  : std::numeric_limits<T>::max() - 1;
851 }
Datum StringToDatum ( std::string_view  s,
SQLTypeInfo ti 
)

Definition at line 122 of file Datum.cpp.

References Datum::bigintval, Datum::boolval, Datum::doubleval, Datum::floatval, SQLTypeInfo::get_dimension(), SQLTypeInfo::get_type(), SQLTypeInfo::get_type_name(), Datum::intval, kARRAY, kBIGINT, kBOOLEAN, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, kLINESTRING, kMULTIPOLYGON, kNUMERIC, kPOINT, kPOLYGON, kSMALLINT, kTIME, kTIMESTAMP, kTINYINT, parse_numeric(), Datum::smallintval, Datum::tinyintval, and to_upper().

Referenced by import_export::TypedImportBuffer::add_value(), Parser::FixedPtLiteral::analyze(), Analyzer::Constant::cast_from_string(), anonymous_namespace{ArrowImporter.h}::ArrowValue< std::string >::operator const bool(), anonymous_namespace{ArrowImporter.h}::ArrowValue< std::string >::operator const DATA_TYPE(), populate_TColumn(), and import_export::StringToArray().

122  {
123  Datum d;
124  try {
125  switch (ti.get_type()) {
126  case kARRAY:
127  break;
128  case kBOOLEAN:
129  if (s == "t" || s == "T" || s == "1" || to_upper(std::string(s)) == "TRUE") {
130  d.boolval = true;
131  } else if (s == "f" || s == "F" || s == "0" ||
132  to_upper(std::string(s)) == "FALSE") {
133  d.boolval = false;
134  } else {
135  throw std::runtime_error("Invalid string for boolean " + std::string(s));
136  }
137  break;
138  case kNUMERIC:
139  case kDECIMAL:
140  d.bigintval = parse_numeric(s, ti);
141  break;
142  case kBIGINT:
143  d.bigintval = std::stoll(std::string(s));
144  break;
145  case kINT:
146  d.intval = std::stoi(std::string(s));
147  break;
148  case kSMALLINT:
149  d.smallintval = std::stoi(std::string(s));
150  break;
151  case kTINYINT:
152  d.tinyintval = std::stoi(std::string(s));
153  break;
154  case kFLOAT:
155  d.floatval = std::stof(std::string(s));
156  break;
157  case kDOUBLE:
158  d.doubleval = std::stod(std::string(s));
159  break;
160  case kTIME:
161  d.bigintval = DateTimeStringValidate<kTIME>()(std::string(s), ti.get_dimension());
162  break;
163  case kTIMESTAMP:
164  d.bigintval =
165  DateTimeStringValidate<kTIMESTAMP>()(std::string(s), ti.get_dimension());
166  break;
167  case kDATE:
168  d.bigintval = DateTimeStringValidate<kDATE>()(std::string(s), ti.get_dimension());
169  break;
170  case kPOINT:
171  case kLINESTRING:
172  case kPOLYGON:
173  case kMULTIPOLYGON:
174  throw std::runtime_error("Internal error: geometry type in StringToDatum.");
175  default:
176  throw std::runtime_error("Internal error: invalid type in StringToDatum.");
177  }
178  } catch (const std::invalid_argument&) {
179  throw std::runtime_error("Invalid conversion from string to " + ti.get_type_name());
180  } catch (const std::out_of_range&) {
181  throw std::runtime_error("Got out of range error during conversion from string to " +
182  ti.get_type_name());
183  }
184  return d;
185 }
int8_t tinyintval
Definition: sqltypes.h:133
Definition: sqltypes.h:50
int64_t parse_numeric(const std::string_view s, SQLTypeInfo &ti)
Definition: Datum.cpp:69
bool boolval
Definition: sqltypes.h:132
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:257
int32_t intval
Definition: sqltypes.h:135
float floatval
Definition: sqltypes.h:137
int64_t bigintval
Definition: sqltypes.h:136
int16_t smallintval
Definition: sqltypes.h:134
std::string to_upper(const std::string &str)
Definition: sqltypes.h:54
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:259
std::string get_type_name() const
Definition: sqltypes.h:360
Definition: sqltypes.h:46
double doubleval
Definition: sqltypes.h:138

+ Here is the call graph for this function:

+ Here is the caller graph for this function: