OmniSciDB  c07336695a
sqltypes.h File Reference

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

#include "ConfigResolve.h"
#include <cassert>
#include <cfloat>
#include <cstdint>
#include <ctime>
#include <limits>
#include <memory>
#include <string>
#include <type_traits>
#include <vector>
#include "SQLTypeUtilities.h"
#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  ExecutorTypePackaging< CORE_TYPE >
 
class  ArrayContextTypeSizer< CORE_TYPE >
 
class  DateTimeFacilities< CORE_TYPE >
 
class  SQLTypeInfoCore< TYPE_FACET_PACK >
 

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_TIME(T)   (((T) == kTIME) || ((T) == kTIMESTAMP) || ((T) == kDATE))
 
#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 TRANSIENT_DICT_ID   0
 
#define TRANSIENT_DICT(ID)   (-(ID))
 
#define REGULAR_DICT(TRANSIENTID)   (-(TRANSIENTID))
 

Typedefs

using ArrayDatum = std::conditional_t< isCudaCC(), DeviceArrayDatum, HostArrayDatum >
 
using SQLTypeInfo = SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities >
 
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, kSQLTYPE_LAST = 26
}
 
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

SQLTypes decimal_to_int_type (const SQLTypeInfo &)
 
Datum StringToDatum (const std::string &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)
 
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 ()
 

Detailed Description

Constants for Builtin SQL Types supported by MapD.

Author
Wei Hong wei@m.nosp@m.ap-d.nosp@m..com Copyright (c) 2014 MapD Technologies, Inc. All rights reserved.

Definition in file sqltypes.h.

Macro Definition Documentation

◆ IS_DECIMAL

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

Definition at line 168 of file sqltypes.h.

◆ IS_GEO

◆ IS_GEO_POLY

#define IS_GEO_POLY (   T)    (((T) == kPOLYGON) || ((T) == kMULTIPOLYGON))

◆ IS_INTEGER

◆ IS_INTERVAL

#define IS_INTERVAL (   T)    ((T) == kINTERVAL_DAY_TIME || (T) == kINTERVAL_YEAR_MONTH)

◆ IS_NUMBER

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

Definition at line 160 of file sqltypes.h.

Referenced by SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities >::is_number(), and anonymous_namespace{EquiJoinCondition.cpp}::make_composite_equals_impl().

◆ IS_STRING

◆ IS_TIME

#define IS_TIME (   T)    (((T) == kTIME) || ((T) == kTIMESTAMP) || ((T) == kDATE))

◆ NULL_ARRAY_BIGINT

◆ NULL_ARRAY_BOOLEAN

#define NULL_ARRAY_BOOLEAN   (INT8_MIN + 1)

Definition at line 179 of file sqltypes.h.

Referenced by FixedLengthArrayNoneEncoder::is_null().

◆ NULL_ARRAY_DOUBLE

◆ NULL_ARRAY_FLOAT

◆ NULL_ARRAY_INT

◆ NULL_ARRAY_SMALLINT

◆ NULL_ARRAY_TINYINT

◆ NULL_BIGINT

◆ NULL_BOOLEAN

◆ NULL_DOUBLE

◆ NULL_FLOAT

◆ NULL_INT

◆ NULL_SMALLINT

◆ NULL_TINYINT

◆ REGULAR_DICT

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

Definition at line 189 of file sqltypes.h.

Referenced by Executor::getStringDictionaryProxy().

◆ TRANSIENT_DICT

◆ TRANSIENT_DICT_ID

Typedef Documentation

◆ ArrayDatum

using ArrayDatum = std::conditional_t<isCudaCC(), DeviceArrayDatum, HostArrayDatum>

Definition at line 119 of file sqltypes.h.

◆ ArrayOffsetT

using ArrayOffsetT = int32_t

Definition at line 874 of file sqltypes.h.

◆ SQLTypeInfo

◆ StringOffsetT

using StringOffsetT = int32_t

Definition at line 873 of file sqltypes.h.

Enumeration Type Documentation

◆ EncodingType

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 144 of file sqltypes.h.

144  {
145  kENCODING_NONE = 0, // no encoding
146  kENCODING_FIXED = 1, // Fixed-bit encoding
147  kENCODING_RL = 2, // Run Length encoding
148  kENCODING_DIFF = 3, // Differential encoding
149  kENCODING_DICT = 4, // Dictionary encoding
150  kENCODING_SPARSE = 5, // Null encoding for sparse columns
151  kENCODING_GEOINT = 6, // Encoding coordinates as intergers
152  kENCODING_DATE_IN_DAYS = 7, // Date encoding in days
153  kENCODING_LAST = 8
154 };

◆ SQLTypes

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 
kSQLTYPE_LAST 

Definition at line 40 of file sqltypes.h.

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

Function Documentation

◆ convert_decimal_value_to_scale()

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

Definition at line 432 of file Datum.cpp.

References SQLTypeInfoCore< TYPE_FACET_PACK >::get_scale().

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

434  {
435  auto converted_decimal_value = decimal_value;
436  if (new_type_info.get_scale() > type_info.get_scale()) {
437  for (int i = 0; i < new_type_info.get_scale() - type_info.get_scale(); i++) {
438  converted_decimal_value *= 10;
439  }
440  } else if (new_type_info.get_scale() < type_info.get_scale()) {
441  for (int i = 0; i < type_info.get_scale() - new_type_info.get_scale(); i++) {
442  if (converted_decimal_value > 0) {
443  converted_decimal_value = (converted_decimal_value + 5) / 10;
444  } else {
445  converted_decimal_value = (converted_decimal_value - 5) / 10;
446  }
447  }
448  }
449  return converted_decimal_value;
450 }
HOST DEVICE int get_scale() const
Definition: sqltypes.h:324
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DatumEqual()

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

Definition at line 301 of file Datum.cpp.

References Datum::bigintval, Datum::boolval, Datum::doubleval, Datum::floatval, SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), SQLTypeInfoCore< TYPE_FACET_PACK >::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==().

301  {
302  switch (ti.get_type()) {
303  case kBOOLEAN:
304  return a.boolval == b.boolval;
305  case kBIGINT:
306  case kNUMERIC:
307  case kDECIMAL:
308  return a.bigintval == b.bigintval;
309  case kINT:
310  return a.intval == b.intval;
311  case kSMALLINT:
312  return a.smallintval == b.smallintval;
313  case kTINYINT:
314  return a.tinyintval == b.tinyintval;
315  case kFLOAT:
316  return a.floatval == b.floatval;
317  case kDOUBLE:
318  return a.doubleval == b.doubleval;
319  case kTIME:
320  case kTIMESTAMP:
321  case kDATE:
322  case kINTERVAL_DAY_TIME:
324  return a.bigintval == b.bigintval;
325  case kTEXT:
326  case kVARCHAR:
327  case kCHAR:
328  if (ti.get_compression() == kENCODING_DICT) {
329  return a.intval == b.intval;
330  }
331  return *a.stringval == *b.stringval;
332  default:
333  return false;
334  }
335  return false;
336 }
Definition: sqltypes.h:51
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:319
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:327
Definition: sqltypes.h:54
Definition: sqltypes.h:55
Definition: sqltypes.h:43
Definition: sqltypes.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DatumToString()

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

Definition at line 341 of file Datum.cpp.

References Datum::bigintval, Datum::boolval, Datum::doubleval, Datum::floatval, SQLTypeInfoCore< TYPE_FACET_PACK >::get_dimension(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_scale(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::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, to_string(), and v().

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

341  {
342  switch (ti.get_type()) {
343  case kBOOLEAN:
344  if (d.boolval) {
345  return "t";
346  }
347  return "f";
348  case kNUMERIC:
349  case kDECIMAL: {
350  char str[ti.get_dimension() + 1];
351  double v = (double)d.bigintval / pow(10, ti.get_scale());
352  sprintf(str, "%*.*f", ti.get_dimension(), ti.get_scale(), v);
353  return std::string(str);
354  }
355  case kINT:
356  return std::to_string(d.intval);
357  case kSMALLINT:
358  return std::to_string(d.smallintval);
359  case kTINYINT:
360  return std::to_string(d.tinyintval);
361  case kBIGINT:
362  return std::to_string(d.bigintval);
363  case kFLOAT:
364  return std::to_string(d.floatval);
365  case kDOUBLE:
366  return std::to_string(d.doubleval);
367  case kTIME: {
368  std::tm tm_struct;
369  gmtime_r(reinterpret_cast<time_t*>(&d.bigintval), &tm_struct);
370  char buf[9];
371  strftime(buf, 9, "%T", &tm_struct);
372  return std::string(buf);
373  }
374  case kTIMESTAMP: {
375  std::tm tm_struct{0};
376  if (ti.get_dimension() > 0) {
377  std::string t = std::to_string(d.bigintval);
378  int cp = t.length() - ti.get_dimension();
379  time_t sec = std::stoll(t.substr(0, cp));
380  t = t.substr(cp);
381  gmtime_r(&sec, &tm_struct);
382  char buf[21];
383  strftime(buf, 21, "%F %T.", &tm_struct);
384  return std::string(buf) += t;
385  } else {
386  time_t sec = static_cast<time_t>(d.bigintval);
387  gmtime_r(&sec, &tm_struct);
388  char buf[20];
389  strftime(buf, 20, "%F %T", &tm_struct);
390  return std::string(buf);
391  }
392  }
393  case kDATE: {
394  std::tm tm_struct;
395  time_t ntimeval = static_cast<time_t>(d.bigintval);
396  gmtime_r(&ntimeval, &tm_struct);
397  char buf[11];
398  strftime(buf, 11, "%F", &tm_struct);
399  return std::string(buf);
400  }
401  case kINTERVAL_DAY_TIME:
402  return std::to_string(d.bigintval) + " ms (day-time interval)";
404  return std::to_string(d.bigintval) + " month(s) (year-month interval)";
405  case kTEXT:
406  case kVARCHAR:
407  case kCHAR:
408  return *d.stringval;
409  default:
410  throw std::runtime_error("Internal error: invalid type " + ti.get_type_name() +
411  " in DatumToString.");
412  }
413  return "";
414 }
int8_t tinyintval
Definition: sqltypes.h:123
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:321
Definition: sqltypes.h:51
bool boolval
Definition: sqltypes.h:122
HOST DEVICE int get_scale() const
Definition: sqltypes.h:324
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:319
int32_t intval
Definition: sqltypes.h:125
std::string to_string(char const *&&v)
std::string get_type_name() const
Definition: sqltypes.h:422
float floatval
Definition: sqltypes.h:127
T v(const TargetValue &r)
int64_t bigintval
Definition: sqltypes.h:126
int16_t smallintval
Definition: sqltypes.h:124
std::string * stringval
Definition: sqltypes.h:131
Definition: sqltypes.h:54
Definition: sqltypes.h:55
Definition: sqltypes.h:43
Definition: sqltypes.h:47
double doubleval
Definition: sqltypes.h:128
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decimal_to_int_type()

SQLTypes decimal_to_int_type ( const SQLTypeInfo )

Definition at line 416 of file Datum.cpp.

References CHECK, SQLTypeInfoCore< TYPE_FACET_PACK >::get_size(), kBIGINT, kINT, kNULLT, kSMALLINT, and kTINYINT.

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

416  {
417  switch (ti.get_size()) {
418  case 1:
419  return kTINYINT;
420  case 2:
421  return kSMALLINT;
422  case 4:
423  return kINT;
424  case 8:
425  return kBIGINT;
426  default:
427  CHECK(false);
428  }
429  return kNULLT;
430 }
#define CHECK(condition)
Definition: Logger.h:187
Definition: sqltypes.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_logical_type_info()

SQLTypeInfo get_logical_type_info ( const SQLTypeInfo type_info)
inline

Definition at line 836 of file sqltypes.h.

References SQLTypeInfoCore< TYPE_FACET_PACK >::get_comp_param(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_dimension(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_notnull(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_scale(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_subtype(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), kARRAY, kENCODING_DATE_IN_DAYS, kENCODING_FIXED, and kENCODING_NONE.

Referenced by anonymous_namespace{RelAlgExecutor.cpp}::cast_to_column_type(), anonymous_namespace{ColumnarResults.cpp}::fixed_encoding_nullable_val(), anonymous_namespace{TypedDataAccessors.h}::NullSentinelSupplier::get_null_sentinel_for_type(), get_target_info(), anonymous_namespace{RelAlgExecutor.cpp}::get_targets_meta(), JoinHashTable::getHashJoinArgs(), getLeafColumnRange(), TableOptimizer::recomputeMetadata(), rows_to_columnar_results(), test_perfect_hash_columnar_conversion(), RelAlgTranslator::translateArrayFunction(), Fragmenter_Namespace::InsertOrderFragmenter::updateChunkStats(), and Fragmenter_Namespace::InsertOrderFragmenter::updateColumns().

836  {
837  EncodingType encoding = type_info.get_compression();
838  if (encoding == kENCODING_DATE_IN_DAYS ||
839  (encoding == kENCODING_FIXED && type_info.get_type() != kARRAY)) {
840  encoding = kENCODING_NONE;
841  }
842  return SQLTypeInfo(type_info.get_type(),
843  type_info.get_dimension(),
844  type_info.get_scale(),
845  type_info.get_notnull(),
846  encoding,
847  type_info.get_comp_param(),
848  type_info.get_subtype());
849 }
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:321
EncodingType
Definition: encodetypes.h:22
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:326
HOST DEVICE int get_scale() const
Definition: sqltypes.h:324
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:319
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:327
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:320
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:819
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:328
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inline_int_null_array_value()

template<class T >
constexpr int64_t inline_int_null_array_value ( )
inline

Definition at line 858 of file sqltypes.h.

858  {
859  return std::is_signed<T>::value ? std::numeric_limits<T>::min() + 1
860  : std::numeric_limits<T>::max() - 1;
861  // TODO: null_array values in signed types would step on max valid value
862  // in fixlen unsigned arrays, the max valid value may need to be lowered.
863 }

◆ inline_int_null_value()

template<class T >
constexpr int64_t inline_int_null_value ( )
inline

Definition at line 852 of file sqltypes.h.

852  {
853  return std::is_signed<T>::value ? std::numeric_limits<T>::min()
854  : std::numeric_limits<T>::max();
855 }

◆ max_valid_int_value()

template<class T >
constexpr int64_t max_valid_int_value ( )
inline

Definition at line 866 of file sqltypes.h.

866  {
867  return std::is_signed<T>::value ? std::numeric_limits<T>::max()
868  : std::numeric_limits<T>::max() - 1;
869 }

◆ StringToDatum()

Datum StringToDatum ( const std::string &  s,
SQLTypeInfo ti 
)

Definition at line 96 of file Datum.cpp.

References Datum::bigintval, Datum::boolval, anonymous_namespace{ImportTest.cpp}::d(), Datum::doubleval, Datum::floatval, SQLTypeInfoCore< TYPE_FACET_PACK >::get_dimension(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type_name(), TimeGM::instance(), Datum::intval, kARRAY, kBIGINT, kBOOLEAN, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, kLINESTRING, kMULTIPOLYGON, kNUMERIC, kPOINT, kPOLYGON, kSMALLINT, kTIME, kTIMESTAMP, kTINYINT, TimeGM::my_timegm(), TimeGM::parse_fractional_seconds(), TimeGM::parse_meridians(), parse_numeric(), Datum::smallintval, Datum::tinyintval, and to_upper().

Referenced by Importer_NS::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 Importer_NS::StringToArray().

96  {
97  Datum d;
98  try {
99  switch (ti.get_type()) {
100  case kARRAY:
101  break;
102  case kBOOLEAN:
103  if (s == "t" || s == "T" || s == "1" || to_upper(s) == "TRUE") {
104  d.boolval = true;
105  } else if (s == "f" || s == "F" || s == "0" || to_upper(s) == "FALSE") {
106  d.boolval = false;
107  } else {
108  throw std::runtime_error("Invalid string for boolean " + s);
109  }
110  break;
111  case kNUMERIC:
112  case kDECIMAL:
113  d.bigintval = parse_numeric(s, ti);
114  break;
115  case kBIGINT:
116  d.bigintval = std::stoll(s);
117  break;
118  case kINT:
119  d.intval = std::stoi(s);
120  break;
121  case kSMALLINT:
122  d.smallintval = std::stoi(s);
123  break;
124  case kTINYINT:
125  d.tinyintval = std::stoi(s);
126  break;
127  case kFLOAT:
128  d.floatval = std::stof(s);
129  break;
130  case kDOUBLE:
131  d.doubleval = std::stod(s);
132  break;
133  case kTIME: {
134  // @TODO handle fractional seconds
135  std::tm tm_struct = {0};
136  if (!strptime(s.c_str(), "%T %z", &tm_struct) &&
137  !strptime(s.c_str(), "%T", &tm_struct) &&
138  !strptime(s.c_str(), "%H%M%S", &tm_struct) &&
139  !strptime(s.c_str(), "%R", &tm_struct)) {
140  throw std::runtime_error("Invalid time string " + s);
141  }
142  tm_struct.tm_mday = 1;
143  tm_struct.tm_mon = 0;
144  tm_struct.tm_year = 70;
145  tm_struct.tm_wday = tm_struct.tm_yday = tm_struct.tm_isdst = tm_struct.tm_gmtoff =
146  0;
147  d.bigintval = static_cast<int64_t>(TimeGM::instance().my_timegm(&tm_struct));
148  break;
149  }
150  case kTIMESTAMP: {
151  std::tm tm_struct = {0};
152  // not sure in advance if it is used so need to zero before processing
153  tm_struct.tm_gmtoff = 0;
154  char* tp;
155  // try ISO8601 date first
156  tp = strptime(s.c_str(), "%Y-%m-%d", &tm_struct);
157  if (!tp) {
158  tp = strptime(s.c_str(), "%m/%d/%Y", &tm_struct); // accept American date
159  }
160  if (!tp) {
161  tp = strptime(s.c_str(), "%d-%b-%y", &tm_struct); // accept 03-Sep-15
162  }
163  if (!tp) {
164  tp = strptime(s.c_str(), "%d/%b/%Y", &tm_struct); // accept 03/Sep/2015
165  }
166  if (!tp) {
167  try {
168  d.bigintval = static_cast<int64_t>(std::stoll(s));
169  break;
170  } catch (const std::invalid_argument& ia) {
171  throw std::runtime_error("Invalid timestamp string " + s);
172  }
173  }
174  if (*tp == 'T' || *tp == ' ' || *tp == ':') {
175  tp++;
176  } else {
177  throw std::runtime_error("Invalid timestamp break string " + s);
178  }
179  // now parse the time
180  char* p = strptime(tp, "%T %z", &tm_struct);
181  if (!p) {
182  p = strptime(tp, "%T", &tm_struct);
183  }
184  if (!p) {
185  p = strptime(tp, "%H%M%S", &tm_struct);
186  }
187  if (!p) {
188  p = strptime(tp, "%R", &tm_struct);
189  }
190  if (!p) {
191  // check for weird customer format
192  // remove decimal seconds from string if there is a period followed by a number
193  char* startptr = nullptr;
194  char* endptr;
195  // find last decimal in string
196  int loop = strlen(tp);
197  while (loop > 0) {
198  if (tp[loop] == '.') {
199  // found last period
200  startptr = &tp[loop];
201  break;
202  }
203  loop--;
204  }
205  if (startptr) {
206  // look for space
207  endptr = strchr(startptr, ' ');
208  if (endptr) {
209  // ok we found a start and and end
210  // remove the decimal portion
211  // will need to capture this for later
212  memmove(startptr, endptr, strlen(endptr) + 1);
213  }
214  }
215  p = strptime(
216  tp, "%I . %M . %S %p", &tm_struct); // customers weird '.' separated date
217  }
218  if (!p) {
219  throw std::runtime_error("Invalid timestamp time string " + s);
220  }
221  tm_struct.tm_wday = tm_struct.tm_yday = tm_struct.tm_isdst = 0;
222  // handle fractional seconds
223  if (ti.get_dimension() > 0) { // check for precision
224  time_t fsc;
225  if (*p == '.') {
226  p++;
227  uint64_t frac_num = 0;
228  int ntotal = 0;
229  sscanf(p, "%" SCNu64 "%n", &frac_num, &ntotal);
230  fsc = TimeGM::instance().parse_fractional_seconds(frac_num, ntotal, ti);
231  } else if (*p == '\0') {
232  fsc = 0;
233  } else { // check for misleading/unclear syntax
234  throw std::runtime_error("Unclear syntax for leading fractional seconds: " +
235  std::string(p));
236  }
237  d.bigintval =
238  static_cast<int64_t>(TimeGM::instance().my_timegm(&tm_struct, fsc, ti));
239  } else { // default timestamp(0) precision
240  d.bigintval = static_cast<int64_t>(TimeGM::instance().my_timegm(&tm_struct));
241  if (*p == '.') {
242  p++;
243  }
244  }
245  if (*p != '\0') {
246  uint32_t hour = 0;
247  sscanf(tp, "%u", &hour);
248  d.bigintval = static_cast<int64_t>(TimeGM::instance().parse_meridians(
249  static_cast<time_t>(d.bigintval), p, hour, ti));
250  break;
251  }
252  break;
253  }
254  case kDATE: {
255  std::tm tm_struct = {0};
256  // not sure in advance if it is used so need to zero before processing
257  tm_struct.tm_gmtoff = 0;
258  char* tp;
259  // try ISO8601 date first
260  tp = strptime(s.c_str(), "%Y-%m-%d", &tm_struct);
261  if (!tp) {
262  tp = strptime(s.c_str(), "%m/%d/%Y", &tm_struct); // accept American date
263  }
264  if (!tp) {
265  tp = strptime(s.c_str(), "%d-%b-%y", &tm_struct); // accept 03-Sep-15
266  }
267  if (!tp) {
268  tp = strptime(s.c_str(), "%d/%b/%Y", &tm_struct); // accept 03/Sep/2015
269  }
270  if (!tp) {
271  try {
272  d.bigintval = static_cast<int64_t>(std::stoll(s));
273  break;
274  } catch (const std::invalid_argument& ia) {
275  throw std::runtime_error("Invalid date string " + s);
276  }
277  }
278  tm_struct.tm_sec = tm_struct.tm_min = tm_struct.tm_hour = 0;
279  tm_struct.tm_wday = tm_struct.tm_yday = tm_struct.tm_isdst = tm_struct.tm_gmtoff =
280  0;
281  d.bigintval = static_cast<int64_t>(TimeGM::instance().my_timegm(&tm_struct));
282  break;
283  }
284  case kPOINT:
285  case kLINESTRING:
286  case kPOLYGON:
287  case kMULTIPOLYGON:
288  throw std::runtime_error("Internal error: geometry type in StringToDatum.");
289  default:
290  throw std::runtime_error("Internal error: invalid type in StringToDatum.");
291  }
292  } catch (const std::invalid_argument&) {
293  throw std::runtime_error("Invalid conversion from string to " + ti.get_type_name());
294  } catch (const std::out_of_range&) {
295  throw std::runtime_error("Got out of range error during conversion from string to " +
296  ti.get_type_name());
297  }
298  return d;
299 }
int8_t tinyintval
Definition: sqltypes.h:123
void d(const SQLTypes expected_type, const std::string &str)
Definition: ImportTest.cpp:268
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:321
Definition: sqltypes.h:51
bool boolval
Definition: sqltypes.h:122
time_t parse_meridians(const time_t &timeval, const char *p, const uint32_t &hour, const SQLTypeInfo &ti)
Definition: timegm.cpp:68
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:319
int32_t intval
Definition: sqltypes.h:125
int64_t parse_numeric(const std::string &s, SQLTypeInfo &ti)
Definition: Datum.cpp:43
std::string get_type_name() const
Definition: sqltypes.h:422
float floatval
Definition: sqltypes.h:127
time_t my_timegm(const struct tm *tm)
Definition: timegm.cpp:111
int64_t bigintval
Definition: sqltypes.h:126
int16_t smallintval
Definition: sqltypes.h:124
time_t parse_fractional_seconds(uint64_t sfrac, const int ntotal, const SQLTypeInfo &ti)
Definition: timegm.cpp:52
std::string to_upper(const std::string &str)
Definition: sqltypes.h:55
Definition: sqltypes.h:47
static TimeGM & instance()
Definition: TimeGM.h:38
double doubleval
Definition: sqltypes.h:128
+ Here is the call graph for this function:
+ Here is the caller graph for this function: