OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Datum.cpp File Reference
#include <algorithm>
#include <cassert>
#include <cctype>
#include <charconv>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <limits>
#include <stdexcept>
#include <string>
#include "DateConverters.h"
#include "DateTimeParser.h"
#include "Logger/Logger.h"
#include "QueryEngine/DateTimeUtils.h"
#include "StringTransform.h"
#include "misc.h"
#include "sqltypes.h"
+ Include dependency graph for Datum.cpp:

Go to the source code of this file.

Namespaces

 anonymous_namespace{Datum.cpp}
 

Functions

int64_t anonymous_namespace{Datum.cpp}::convert_decimal_value_to_scale_internal (const int64_t decimal_value, int const dscale)
 
int64_t parse_numeric (const std::string_view s, SQLTypeInfo &ti)
 
template<typename T >
anonymous_namespace{Datum.cpp}::minValue (unsigned const fieldsize)
 
template<typename T >
anonymous_namespace{Datum.cpp}::maxValue (unsigned const fieldsize)
 
std::string anonymous_namespace{Datum.cpp}::toString (SQLTypeInfo const &ti, unsigned const fieldsize)
 
template<typename T , typename U = long double>
anonymous_namespace{Datum.cpp}::parseFloatAsInteger (std::string_view s, SQLTypeInfo const &ti)
 
bool anonymous_namespace{Datum.cpp}::hasCommonSuffix (char const *const ptr, char const *const end)
 
template<typename T >
anonymous_namespace{Datum.cpp}::parseInteger (std::string_view s, SQLTypeInfo const &ti)
 
Datum StringToDatum (std::string_view s, SQLTypeInfo &ti)
 
bool DatumEqual (const Datum a, const Datum b, const SQLTypeInfo &ti)
 
std::string DatumToString (Datum d, const SQLTypeInfo &ti)
 
int64_t extract_int_type_from_datum (const Datum datum, const SQLTypeInfo &ti)
 
double extract_fp_type_from_datum (const Datum datum, const SQLTypeInfo &ti)
 
SQLTypes decimal_to_int_type (const SQLTypeInfo &ti)
 
SQLTypes string_dict_to_int_type (const SQLTypeInfo &ti)
 
int8_t * append_datum (int8_t *buf, const Datum &d, const SQLTypeInfo &ti)
 
int64_t convert_decimal_value_to_scale (const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
 

Function Documentation

int8_t* append_datum ( int8_t *  buf,
const Datum d,
const SQLTypeInfo ti 
)

Definition at line 518 of file Datum.cpp.

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

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

518  {
519  SQLTypes type;
520  if (ti.is_dict_encoded_string()) {
521  type = string_dict_to_int_type(ti);
522  } else {
523  type = ti.get_type();
524  }
525  switch (type) {
526  case kBOOLEAN:
527  *(int8_t*)buf = d.boolval;
528  return buf + sizeof(int8_t);
529  case kNUMERIC:
530  case kDECIMAL:
531  case kBIGINT:
532  *(int64_t*)buf = d.bigintval;
533  return buf + sizeof(int64_t);
534  case kINT:
535  *(int32_t*)buf = d.intval;
536  return buf + sizeof(int32_t);
537  case kSMALLINT:
538  *(int16_t*)buf = d.smallintval;
539  return buf + sizeof(int16_t);
540  case kTINYINT:
541  *(int8_t*)buf = d.tinyintval;
542  return buf + sizeof(int8_t);
543  case kFLOAT:
544  *(float*)buf = d.floatval;
545  return buf + sizeof(float);
546  case kDOUBLE:
547  *(double*)buf = d.doubleval;
548  return buf + sizeof(double);
549  case kTIME:
550  case kTIMESTAMP:
551  case kDATE:
552  *reinterpret_cast<int64_t*>(buf) = d.bigintval;
553  return buf + sizeof(int64_t);
554  default:
555  UNREACHABLE() << "Unexpected type: " << type;
556  return nullptr;
557  }
558 }
int8_t tinyintval
Definition: sqltypes.h:232
Definition: sqltypes.h:63
SQLTypes
Definition: sqltypes.h:52
int8_t boolval
Definition: sqltypes.h:231
#define UNREACHABLE()
Definition: Logger.h:266
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:404
int32_t intval
Definition: sqltypes.h:234
float floatval
Definition: sqltypes.h:236
int64_t bigintval
Definition: sqltypes.h:235
int16_t smallintval
Definition: sqltypes.h:233
Definition: sqltypes.h:67
bool is_dict_encoded_string() const
Definition: sqltypes.h:652
Definition: sqltypes.h:59
double doubleval
Definition: sqltypes.h:237
SQLTypes string_dict_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:503

+ 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 562 of file Datum.cpp.

References anonymous_namespace{Datum.cpp}::convert_decimal_value_to_scale_internal(), and SQLTypeInfo::get_scale().

Referenced by import_export::TypedImportBuffer::addDefaultValues(), Analyzer::Constant::cast_number(), anonymous_namespace{ArrowImporter.h}::ArrowValue< arrow::Decimal128 >::operator DATA_TYPE(), parse_numeric(), anonymous_namespace{TypedDataAccessors.h}::put_scalar(), and ddl_utils::anonymous_namespace{DdlUtils.cpp}::validate_literal().

564  {
565  int const dscale = new_type_info.get_scale() - type_info.get_scale();
566  return convert_decimal_value_to_scale_internal(decimal_value, dscale);
567 }
HOST DEVICE int get_scale() const
Definition: sqltypes.h:409
int64_t convert_decimal_value_to_scale_internal(const int64_t decimal_value, int const dscale)
Definition: Datum.cpp:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 346 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, kLINESTRING, kMULTILINESTRING, kMULTIPOINT, kMULTIPOLYGON, kNUMERIC, kPOINT, kPOLYGON, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, kVARCHAR, Datum::smallintval, Datum::stringval, and Datum::tinyintval.

Referenced by ChunkMetadata::operator==(), FixedLengthArrayNoneEncoder::resetChunkStats(), and ArrayNoneEncoder::resetChunkStats().

346  {
347  switch (ti.get_type()) {
348  case kBOOLEAN:
349  return a.boolval == b.boolval;
350  case kBIGINT:
351  case kNUMERIC:
352  case kDECIMAL:
353  return a.bigintval == b.bigintval;
354  case kINT:
355  return a.intval == b.intval;
356  case kSMALLINT:
357  return a.smallintval == b.smallintval;
358  case kTINYINT:
359  return a.tinyintval == b.tinyintval;
360  case kFLOAT:
361  return a.floatval == b.floatval;
362  case kDOUBLE:
363  return a.doubleval == b.doubleval;
364  case kTIME:
365  case kTIMESTAMP:
366  case kDATE:
367  case kINTERVAL_DAY_TIME:
369  return a.bigintval == b.bigintval;
370  case kTEXT:
371  case kVARCHAR:
372  case kCHAR:
373  case kPOINT:
374  case kMULTIPOINT:
375  case kLINESTRING:
376  case kMULTILINESTRING:
377  case kPOLYGON:
378  case kMULTIPOLYGON:
379  if (ti.get_compression() == kENCODING_DICT) {
380  return a.intval == b.intval;
381  }
382  if (a.stringval == nullptr && b.stringval == nullptr) {
383  return true;
384  }
385  if (a.stringval == nullptr || b.stringval == nullptr) {
386  return false;
387  }
388  return *a.stringval == *b.stringval;
389  default:
390  return false;
391  }
392  return false;
393 }
int8_t tinyintval
Definition: sqltypes.h:232
Definition: sqltypes.h:63
int8_t boolval
Definition: sqltypes.h:231
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:404
int32_t intval
Definition: sqltypes.h:234
float floatval
Definition: sqltypes.h:236
int64_t bigintval
Definition: sqltypes.h:235
int16_t smallintval
Definition: sqltypes.h:233
std::string * stringval
Definition: sqltypes.h:240
Definition: sqltypes.h:66
Definition: sqltypes.h:67
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:412
Definition: sqltypes.h:55
Definition: sqltypes.h:59
double doubleval
Definition: sqltypes.h:237

+ 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 398 of file Datum.cpp.

References Datum::bigintval, Datum::boolval, CHECK_EQ, CHECK_LE, CHECK_LT, Datum::doubleval, Datum::floatval, shared::formatDate(), shared::formatDateTime(), shared::formatHMS(), 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, to_string(), and SQLTypeInfo::to_string().

Referenced by Analyzer::Constant::cast_to_string(), foreign_storage::datetime_to_string(), foreign_storage::TypedParquetInPlaceEncoder< V, V >::integralTypeToString(), anonymous_namespace{ArrowImporter.h}::ArrowValue< int64_t >::operator DATA_TYPE(), operator<<(), import_export::anonymous_namespace{QueryExporterCSV.cpp}::target_value_to_string(), Analyzer::Constant::toString(), Fragmenter_Namespace::InsertOrderFragmenter::updateChunkStats(), and ScalarExprToSql::visitConstant().

398  {
399  constexpr size_t buf_size = 64;
400  char buf[buf_size]; // Hold "2000-03-01 12:34:56.123456789" and large years.
401  switch (ti.get_type()) {
402  case kBOOLEAN:
403  if (d.boolval) {
404  return "t";
405  }
406  return "f";
407  case kNUMERIC:
408  case kDECIMAL: {
409  double v = (double)d.bigintval / pow(10, ti.get_scale());
410  int size = snprintf(buf, buf_size, "%*.*f", ti.get_dimension(), ti.get_scale(), v);
411  CHECK_LE(0, size) << v << ' ' << ti.to_string();
412  CHECK_LT(size_t(size), buf_size) << v << ' ' << ti.to_string();
413  return buf;
414  }
415  case kINT:
416  return std::to_string(d.intval);
417  case kSMALLINT:
418  return std::to_string(d.smallintval);
419  case kTINYINT:
420  return std::to_string(d.tinyintval);
421  case kBIGINT:
422  return std::to_string(d.bigintval);
423  case kFLOAT:
424  return std::to_string(d.floatval);
425  case kDOUBLE:
426  return std::to_string(d.doubleval);
427  case kTIME: {
428  size_t const len = shared::formatHMS(buf, buf_size, d.bigintval);
429  CHECK_EQ(8u, len); // 8 == strlen("HH:MM:SS")
430  return buf;
431  }
432  case kTIMESTAMP: {
433  unsigned const dim = ti.get_dimension(); // assumes dim <= 9
434  size_t const len = shared::formatDateTime(buf, buf_size, d.bigintval, dim);
435  CHECK_LE(19u + bool(dim) + dim, len); // 19 = strlen("YYYY-MM-DD HH:MM:SS")
436  return buf;
437  }
438  case kDATE: {
439  size_t const len = shared::formatDate(buf, buf_size, d.bigintval);
440  CHECK_LE(10u, len); // 10 == strlen("YYYY-MM-DD")
441  return buf;
442  }
443  case kINTERVAL_DAY_TIME:
444  return std::to_string(d.bigintval) + " ms (day-time interval)";
446  return std::to_string(d.bigintval) + " month(s) (year-month interval)";
447  case kTEXT:
448  case kVARCHAR:
449  case kCHAR:
450  if (d.stringval == nullptr) {
451  return "NULL";
452  }
453  return *d.stringval;
454  default:
455  throw std::runtime_error("Internal error: invalid type " + ti.get_type_name() +
456  " in DatumToString.");
457  }
458  return "";
459 }
int8_t tinyintval
Definition: sqltypes.h:232
#define CHECK_EQ(x, y)
Definition: Logger.h:230
Definition: sqltypes.h:63
HOST DEVICE int get_scale() const
Definition: sqltypes.h:409
int8_t boolval
Definition: sqltypes.h:231
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:404
int32_t intval
Definition: sqltypes.h:234
std::string to_string(char const *&&v)
size_t formatHMS(char *buf, size_t const max, int64_t const unixtime)
Definition: misc.cpp:96
float floatval
Definition: sqltypes.h:236
std::string to_string() const
Definition: sqltypes.h:568
int64_t bigintval
Definition: sqltypes.h:235
int16_t smallintval
Definition: sqltypes.h:233
std::string * stringval
Definition: sqltypes.h:240
size_t formatDate(char *buf, size_t const max, int64_t const unixtime)
Definition: misc.cpp:27
#define CHECK_LT(x, y)
Definition: Logger.h:232
Definition: sqltypes.h:66
Definition: sqltypes.h:67
#define CHECK_LE(x, y)
Definition: Logger.h:233
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:406
std::string get_type_name() const
Definition: sqltypes.h:528
size_t formatDateTime(char *buf, size_t const max, int64_t const timestamp, int const dimension, bool use_iso_format)
Definition: misc.cpp:45
Definition: sqltypes.h:55
Definition: sqltypes.h:59
double doubleval
Definition: sqltypes.h:237

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double extract_fp_type_from_datum ( const Datum  datum,
const SQLTypeInfo ti 
)

Definition at line 487 of file Datum.cpp.

References Datum::doubleval, Datum::floatval, SQLTypeInfo::get_type(), kDOUBLE, kFLOAT, and run_benchmark_import::type.

Referenced by extract_max_stat_fp_type(), and extract_min_stat_fp_type().

487  {
488  const auto type = ti.get_type();
489  switch (type) {
490  case kFLOAT:
491  return datum.floatval;
492  case kDOUBLE:
493  return datum.doubleval;
494  default:
495  abort();
496  }
497 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:404
float floatval
Definition: sqltypes.h:236
double doubleval
Definition: sqltypes.h:237

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int64_t extract_int_type_from_datum ( const Datum  datum,
const SQLTypeInfo ti 
)

Definition at line 461 of file Datum.cpp.

References Datum::bigintval, CHECK_EQ, decimal_to_int_type(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_type(), Datum::intval, SQLTypeInfo::is_decimal(), kBIGINT, kBOOLEAN, kCHAR, kDATE, kENCODING_DICT, kINT, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, kVARCHAR, Datum::smallintval, Datum::tinyintval, and run_benchmark_import::type.

Referenced by extract_max_stat_int_type(), extract_min_stat_int_type(), StringOps_Namespace::StringOpInfo::getIntLiteral(), ChunkMetadata::isPlaceholder(), and StringOps_Namespace::operator<<().

461  {
462  const auto type = ti.is_decimal() ? decimal_to_int_type(ti) : ti.get_type();
463  switch (type) {
464  case kBOOLEAN:
465  return datum.tinyintval;
466  case kTINYINT:
467  return datum.tinyintval;
468  case kSMALLINT:
469  return datum.smallintval;
470  case kCHAR:
471  case kVARCHAR:
472  case kTEXT:
474  case kINT:
475  return datum.intval;
476  case kBIGINT:
477  return datum.bigintval;
478  case kTIME:
479  case kTIMESTAMP:
480  case kDATE:
481  return datum.bigintval;
482  default:
483  abort();
484  }
485 }
int8_t tinyintval
Definition: sqltypes.h:232
#define CHECK_EQ(x, y)
Definition: Logger.h:230
Definition: sqltypes.h:63
int32_t intval
Definition: sqltypes.h:234
int64_t bigintval
Definition: sqltypes.h:235
int16_t smallintval
Definition: sqltypes.h:233
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:499
Definition: sqltypes.h:66
Definition: sqltypes.h:67
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:412
Definition: sqltypes.h:55
Definition: sqltypes.h:59
bool is_decimal() const
Definition: sqltypes.h:603

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int64_t parse_numeric ( const std::string_view  s,
SQLTypeInfo ti 
)

Definition at line 110 of file Datum.cpp.

References convert_decimal_value_to_scale(), anonymous_namespace{Datum.cpp}::convert_decimal_value_to_scale_internal(), SQLTypeInfo::get_dimension(), SQLTypeInfo::get_scale(), kNUMERIC, run_benchmark_import::result, SQLTypeInfo::set_dimension(), SQLTypeInfo::set_notnull(), and SQLTypeInfo::set_scale().

Referenced by StringToDatum().

110  {
111  // if we are given a dimension, first parse to the maximum precision of the string
112  // and then convert to the correct size
113  if (ti.get_dimension() != 0) {
114  SQLTypeInfo ti_string(kNUMERIC, 0, 0, false);
115  return convert_decimal_value_to_scale(parse_numeric(s, ti_string), ti_string, ti);
116  }
117  size_t dot = s.find_first_of('.', 0);
118  std::string before_dot;
119  std::string after_dot;
120  if (dot != std::string::npos) {
121  // make .99 as 0.99, or std::stoll below throws exception 'std::invalid_argument'
122  before_dot = (0 == dot) ? "0" : s.substr(0, dot);
123  after_dot = s.substr(dot + 1);
124  } else {
125  before_dot = s;
126  after_dot = "0";
127  }
128  const bool is_negative = before_dot.find_first_of('-', 0) != std::string::npos;
129  const int64_t sign = is_negative ? -1 : 1;
130  int64_t result;
131  result = std::abs(std::stoll(before_dot));
132  int64_t fraction = 0;
133  const size_t before_dot_digits = before_dot.length() - (is_negative ? 1 : 0);
134 
135  constexpr int max_digits = std::numeric_limits<int64_t>::digits10;
136  if (!after_dot.empty()) {
137  int64_t next_digit = 0;
138  // After dot will be used to scale integer part so make sure it wont overflow
139  if (after_dot.size() + before_dot_digits > max_digits) {
140  if (before_dot_digits >= max_digits) {
141  after_dot = "0";
142  } else {
143  next_digit = std::stoll(after_dot.substr(max_digits - before_dot_digits, 1));
144  after_dot = after_dot.substr(0, max_digits - before_dot_digits);
145  }
146  }
147  fraction = std::stoll(after_dot);
148  fraction += next_digit >= 5 ? 1 : 0;
149  }
150 
151  // set the type info based on the literal string
152  ti.set_scale(static_cast<int>(after_dot.length()));
153  ti.set_dimension(static_cast<int>(before_dot_digits + ti.get_scale()));
154  ti.set_notnull(false);
155  if (ti.get_scale()) {
156  result = convert_decimal_value_to_scale_internal(result, ti.get_scale());
157  }
158  result += fraction;
159 
160  return result * sign;
161 }
int64_t parse_numeric(const std::string_view s, SQLTypeInfo &ti)
Definition: Datum.cpp:110
HOST DEVICE int get_scale() const
Definition: sqltypes.h:409
void set_scale(int s)
Definition: sqltypes.h:519
int64_t convert_decimal_value_to_scale(const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
Definition: Datum.cpp:562
void set_dimension(int d)
Definition: sqltypes.h:516
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:406
void set_notnull(bool n)
Definition: sqltypes.h:521
int64_t convert_decimal_value_to_scale_internal(const int64_t decimal_value, int const dscale)
Definition: Datum.cpp:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SQLTypes string_dict_to_int_type ( const SQLTypeInfo ti)

Definition at line 503 of file Datum.cpp.

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

Referenced by append_datum(), import_export::anonymous_namespace{Importer.cpp}::get_type_for_datum(), and foreign_storage::ParquetFixedLengthArrayEncoder::setNullFixedLengthArraySentinel().

503  {
505  switch (ti.get_size()) {
506  case 1:
507  return kTINYINT;
508  case 2:
509  return kSMALLINT;
510  case 4:
511  return kINT;
512  default:
513  UNREACHABLE() << "Unexpected string dictionary encoding size: " << ti.get_size();
514  }
515  return kNULLT;
516 }
HOST DEVICE int get_size() const
Definition: sqltypes.h:414
#define UNREACHABLE()
Definition: Logger.h:266
#define CHECK(condition)
Definition: Logger.h:222
bool is_dict_encoded_string() const
Definition: sqltypes.h:652
Definition: sqltypes.h:59

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Datum StringToDatum ( std::string_view  s,
SQLTypeInfo ti 
)

Definition at line 277 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, kCOLUMN, kCOLUMN_LIST, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, kLINESTRING, kMULTILINESTRING, kMULTIPOINT, kMULTIPOLYGON, kNUMERIC, kPOINT, kPOLYGON, kSMALLINT, kTIME, kTIMESTAMP, kTINYINT, parse_numeric(), Datum::smallintval, Datum::tinyintval, and to_upper().

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

277  {
278  Datum d;
279  try {
280  switch (ti.get_type()) {
281  case kARRAY:
282  case kCOLUMN:
283  case kCOLUMN_LIST:
284  break;
285  case kBOOLEAN:
286  if (s == "t" || s == "T" || s == "1" || to_upper(std::string(s)) == "TRUE") {
287  d.boolval = true;
288  } else if (s == "f" || s == "F" || s == "0" ||
289  to_upper(std::string(s)) == "FALSE") {
290  d.boolval = false;
291  } else {
292  throw std::runtime_error("Invalid string for boolean " + std::string(s));
293  }
294  break;
295  case kNUMERIC:
296  case kDECIMAL:
297  d.bigintval = parse_numeric(s, ti);
298  break;
299  case kBIGINT:
300  d.bigintval = parseInteger<int64_t>(s, ti);
301  break;
302  case kINT:
303  d.intval = parseInteger<int32_t>(s, ti);
304  break;
305  case kSMALLINT:
306  d.smallintval = parseInteger<int16_t>(s, ti);
307  break;
308  case kTINYINT:
309  d.tinyintval = parseInteger<int8_t>(s, ti);
310  break;
311  case kFLOAT:
312  d.floatval = std::stof(std::string(s));
313  break;
314  case kDOUBLE:
315  d.doubleval = std::stod(std::string(s));
316  break;
317  case kTIME:
318  d.bigintval = dateTimeParse<kTIME>(s, ti.get_dimension());
319  break;
320  case kTIMESTAMP:
321  d.bigintval = dateTimeParse<kTIMESTAMP>(s, ti.get_dimension());
322  break;
323  case kDATE:
324  d.bigintval = dateTimeParse<kDATE>(s, ti.get_dimension());
325  break;
326  case kPOINT:
327  case kMULTIPOINT:
328  case kLINESTRING:
329  case kMULTILINESTRING:
330  case kPOLYGON:
331  case kMULTIPOLYGON:
332  throw std::runtime_error("Internal error: geometry type in StringToDatum.");
333  default:
334  throw std::runtime_error("Internal error: invalid type in StringToDatum: " +
335  ti.get_type_name());
336  }
337  } catch (const std::invalid_argument&) {
338  throw std::runtime_error("Invalid conversion from string to " + ti.get_type_name());
339  } catch (const std::out_of_range&) {
340  throw std::runtime_error("Got out of range error during conversion from string to " +
341  ti.get_type_name());
342  }
343  return d;
344 }
int8_t tinyintval
Definition: sqltypes.h:232
Definition: sqltypes.h:63
int64_t parse_numeric(const std::string_view s, SQLTypeInfo &ti)
Definition: Datum.cpp:110
int8_t boolval
Definition: sqltypes.h:231
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:404
int32_t intval
Definition: sqltypes.h:234
float floatval
Definition: sqltypes.h:236
int64_t bigintval
Definition: sqltypes.h:235
int16_t smallintval
Definition: sqltypes.h:233
std::string to_upper(const std::string &str)
Definition: sqltypes.h:67
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:406
std::string get_type_name() const
Definition: sqltypes.h:528
Definition: sqltypes.h:59
double doubleval
Definition: sqltypes.h:237

+ Here is the call graph for this function:

+ Here is the caller graph for this function: