OmniSciDB  c1a53651b2
 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)
 
SQLTypes anonymous_namespace{Datum.cpp}::get_type_for_datum (const SQLTypeInfo &ti)
 
Datum NullDatum (const SQLTypeInfo &ti)
 
bool IsNullDatum (const Datum datum, const SQLTypeInfo &ti)
 
Datum StringToDatum (const 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 578 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().

578  {
579  SQLTypes type;
580  if (ti.is_dict_encoded_string()) {
581  type = string_dict_to_int_type(ti);
582  } else {
583  type = ti.get_type();
584  }
585  switch (type) {
586  case kBOOLEAN:
587  *(int8_t*)buf = d.boolval;
588  return buf + sizeof(int8_t);
589  case kNUMERIC:
590  case kDECIMAL:
591  case kBIGINT:
592  *(int64_t*)buf = d.bigintval;
593  return buf + sizeof(int64_t);
594  case kINT:
595  *(int32_t*)buf = d.intval;
596  return buf + sizeof(int32_t);
597  case kSMALLINT:
598  *(int16_t*)buf = d.smallintval;
599  return buf + sizeof(int16_t);
600  case kTINYINT:
601  *(int8_t*)buf = d.tinyintval;
602  return buf + sizeof(int8_t);
603  case kFLOAT:
604  *(float*)buf = d.floatval;
605  return buf + sizeof(float);
606  case kDOUBLE:
607  *(double*)buf = d.doubleval;
608  return buf + sizeof(double);
609  case kTIME:
610  case kTIMESTAMP:
611  case kDATE:
612  *reinterpret_cast<int64_t*>(buf) = d.bigintval;
613  return buf + sizeof(int64_t);
614  default:
615  UNREACHABLE() << "Unexpected type: " << type;
616  return nullptr;
617  }
618 }
int8_t tinyintval
Definition: Datum.h:69
Definition: sqltypes.h:66
SQLTypes
Definition: sqltypes.h:55
int8_t boolval
Definition: Datum.h:68
#define UNREACHABLE()
Definition: Logger.h:337
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
int32_t intval
Definition: Datum.h:71
float floatval
Definition: Datum.h:73
int64_t bigintval
Definition: Datum.h:72
int16_t smallintval
Definition: Datum.h:70
Definition: sqltypes.h:70
bool is_dict_encoded_string() const
Definition: sqltypes.h:632
Definition: sqltypes.h:62
double doubleval
Definition: Datum.h:74
SQLTypes string_dict_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:563

+ 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 622 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().

624  {
625  int const dscale = new_type_info.get_scale() - type_info.get_scale();
626  return convert_decimal_value_to_scale_internal(decimal_value, dscale);
627 }
HOST DEVICE int get_scale() const
Definition: sqltypes.h:386
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 406 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 IsNullDatum(), ChunkMetadata::operator==(), FixedLengthArrayNoneEncoder::resetChunkStats(), and ArrayNoneEncoder::resetChunkStats().

406  {
407  switch (ti.get_type()) {
408  case kBOOLEAN:
409  return a.boolval == b.boolval;
410  case kBIGINT:
411  case kNUMERIC:
412  case kDECIMAL:
413  return a.bigintval == b.bigintval;
414  case kINT:
415  return a.intval == b.intval;
416  case kSMALLINT:
417  return a.smallintval == b.smallintval;
418  case kTINYINT:
419  return a.tinyintval == b.tinyintval;
420  case kFLOAT:
421  return a.floatval == b.floatval;
422  case kDOUBLE:
423  return a.doubleval == b.doubleval;
424  case kTIME:
425  case kTIMESTAMP:
426  case kDATE:
427  case kINTERVAL_DAY_TIME:
429  return a.bigintval == b.bigintval;
430  case kTEXT:
431  case kVARCHAR:
432  case kCHAR:
433  case kPOINT:
434  case kMULTIPOINT:
435  case kLINESTRING:
436  case kMULTILINESTRING:
437  case kPOLYGON:
438  case kMULTIPOLYGON:
439  if (ti.get_compression() == kENCODING_DICT) {
440  return a.intval == b.intval;
441  }
442  if (a.stringval == nullptr && b.stringval == nullptr) {
443  return true;
444  }
445  if (a.stringval == nullptr || b.stringval == nullptr) {
446  return false;
447  }
448  return *a.stringval == *b.stringval;
449  default:
450  return false;
451  }
452  return false;
453 }
int8_t tinyintval
Definition: Datum.h:69
Definition: sqltypes.h:66
int8_t boolval
Definition: Datum.h:68
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
int32_t intval
Definition: Datum.h:71
float floatval
Definition: Datum.h:73
int64_t bigintval
Definition: Datum.h:72
int16_t smallintval
Definition: Datum.h:70
std::string * stringval
Definition: Datum.h:77
Definition: sqltypes.h:69
Definition: sqltypes.h:70
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:389
Definition: sqltypes.h:58
Definition: sqltypes.h:62
double doubleval
Definition: Datum.h:74

+ 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 458 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().

458  {
459  constexpr size_t buf_size = 64;
460  char buf[buf_size]; // Hold "2000-03-01 12:34:56.123456789" and large years.
461  switch (ti.get_type()) {
462  case kBOOLEAN:
463  if (d.boolval) {
464  return "t";
465  }
466  return "f";
467  case kNUMERIC:
468  case kDECIMAL: {
469  double v = (double)d.bigintval / pow(10, ti.get_scale());
470  int size = snprintf(buf, buf_size, "%*.*f", ti.get_dimension(), ti.get_scale(), v);
471  CHECK_LE(0, size) << v << ' ' << ti.to_string();
472  CHECK_LT(size_t(size), buf_size) << v << ' ' << ti.to_string();
473  return buf;
474  }
475  case kINT:
476  return std::to_string(d.intval);
477  case kSMALLINT:
478  return std::to_string(d.smallintval);
479  case kTINYINT:
480  return std::to_string(d.tinyintval);
481  case kBIGINT:
482  return std::to_string(d.bigintval);
483  case kFLOAT:
484  return std::to_string(d.floatval);
485  case kDOUBLE:
486  return std::to_string(d.doubleval);
487  case kTIME: {
488  size_t const len = shared::formatHMS(buf, buf_size, d.bigintval);
489  CHECK_EQ(8u, len); // 8 == strlen("HH:MM:SS")
490  return buf;
491  }
492  case kTIMESTAMP: {
493  unsigned const dim = ti.get_dimension(); // assumes dim <= 9
494  size_t const len = shared::formatDateTime(buf, buf_size, d.bigintval, dim);
495  CHECK_LE(19u + bool(dim) + dim, len); // 19 = strlen("YYYY-MM-DD HH:MM:SS")
496  return buf;
497  }
498  case kDATE: {
499  size_t const len = shared::formatDate(buf, buf_size, d.bigintval);
500  CHECK_LE(10u, len); // 10 == strlen("YYYY-MM-DD")
501  return buf;
502  }
503  case kINTERVAL_DAY_TIME:
504  return std::to_string(d.bigintval) + " ms (day-time interval)";
506  return std::to_string(d.bigintval) + " month(s) (year-month interval)";
507  case kTEXT:
508  case kVARCHAR:
509  case kCHAR:
510  if (d.stringval == nullptr) {
511  return "NULL";
512  }
513  return *d.stringval;
514  default:
515  throw std::runtime_error("Internal error: invalid type " + ti.get_type_name() +
516  " in DatumToString.");
517  }
518  return "";
519 }
int8_t tinyintval
Definition: Datum.h:69
#define CHECK_EQ(x, y)
Definition: Logger.h:301
Definition: sqltypes.h:66
HOST DEVICE int get_scale() const
Definition: sqltypes.h:386
int8_t boolval
Definition: Datum.h:68
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
int32_t intval
Definition: Datum.h:71
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: Datum.h:73
std::string to_string() const
Definition: sqltypes.h:547
int64_t bigintval
Definition: Datum.h:72
int16_t smallintval
Definition: Datum.h:70
std::string * stringval
Definition: Datum.h:77
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:303
Definition: sqltypes.h:69
Definition: sqltypes.h:70
#define CHECK_LE(x, y)
Definition: Logger.h:304
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:383
std::string get_type_name() const
Definition: sqltypes.h:507
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:58
Definition: sqltypes.h:62
double doubleval
Definition: Datum.h:74

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SQLTypes decimal_to_int_type ( const SQLTypeInfo ti)
double extract_fp_type_from_datum ( const Datum  datum,
const SQLTypeInfo ti 
)

Definition at line 547 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().

547  {
548  const auto type = ti.get_type();
549  switch (type) {
550  case kFLOAT:
551  return datum.floatval;
552  case kDOUBLE:
553  return datum.doubleval;
554  default:
555  abort();
556  }
557 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
float floatval
Definition: Datum.h:73
double doubleval
Definition: Datum.h:74

+ 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 521 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<<().

521  {
522  const auto type = ti.is_decimal() ? decimal_to_int_type(ti) : ti.get_type();
523  switch (type) {
524  case kBOOLEAN:
525  return datum.tinyintval;
526  case kTINYINT:
527  return datum.tinyintval;
528  case kSMALLINT:
529  return datum.smallintval;
530  case kCHAR:
531  case kVARCHAR:
532  case kTEXT:
534  case kINT:
535  return datum.intval;
536  case kBIGINT:
537  return datum.bigintval;
538  case kTIME:
539  case kTIMESTAMP:
540  case kDATE:
541  return datum.bigintval;
542  default:
543  abort();
544  }
545 }
int8_t tinyintval
Definition: Datum.h:69
#define CHECK_EQ(x, y)
Definition: Logger.h:301
Definition: sqltypes.h:66
int32_t intval
Definition: Datum.h:71
int64_t bigintval
Definition: Datum.h:72
int16_t smallintval
Definition: Datum.h:70
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:559
Definition: sqltypes.h:69
Definition: sqltypes.h:70
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:389
Definition: sqltypes.h:58
Definition: sqltypes.h:62
bool is_decimal() const
Definition: sqltypes.h:583

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool IsNullDatum ( const Datum  datum,
const SQLTypeInfo ti 
)

Definition at line 329 of file Datum.cpp.

References DatumEqual(), and NullDatum().

Referenced by anonymous_namespace{ExpressionRewrite.cpp}::ConstantFoldingVisitor::visitStringOper().

329  {
330  const Datum null_datum = NullDatum(ti);
331  return DatumEqual(datum, null_datum, ti);
332 }
bool DatumEqual(const Datum a, const Datum b, const SQLTypeInfo &ti)
Definition: Datum.cpp:406
Datum NullDatum(const SQLTypeInfo &ti)
Definition: Datum.cpp:286
Definition: Datum.h:67

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Datum NullDatum ( const SQLTypeInfo ti)

Definition at line 286 of file Datum.cpp.

References Datum::bigintval, Datum::boolval, Datum::doubleval, Datum::floatval, import_export::anonymous_namespace{Importer.cpp}::get_type_for_datum(), inline_fixed_encoding_null_val(), Datum::intval, kBIGINT, kBOOLEAN, kDATE, kDOUBLE, kFLOAT, kINT, kLINESTRING, kMULTILINESTRING, kMULTIPOINT, kMULTIPOLYGON, kPOINT, kPOLYGON, kSMALLINT, kTIME, kTIMESTAMP, kTINYINT, NULL_DOUBLE, NULL_FLOAT, Datum::smallintval, Datum::tinyintval, and run_benchmark_import::type.

Referenced by IsNullDatum(), import_export::NullArray(), and import_export::StringToArray().

286  {
287  Datum d;
288  const auto type = get_type_for_datum(ti);
289  switch (type) {
290  case kBOOLEAN:
292  break;
293  case kBIGINT:
295  break;
296  case kINT:
298  break;
299  case kSMALLINT:
301  break;
302  case kTINYINT:
304  break;
305  case kFLOAT:
306  d.floatval = NULL_FLOAT;
307  break;
308  case kDOUBLE:
310  break;
311  case kTIME:
312  case kTIMESTAMP:
313  case kDATE:
315  break;
316  case kPOINT:
317  case kMULTIPOINT:
318  case kLINESTRING:
319  case kMULTILINESTRING:
320  case kPOLYGON:
321  case kMULTIPOLYGON:
322  throw std::runtime_error("Internal error: geometry type in NullDatum.");
323  default:
324  throw std::runtime_error("Internal error: invalid type in NullDatum.");
325  }
326  return d;
327 }
int8_t tinyintval
Definition: Datum.h:69
#define NULL_DOUBLE
Definition: sqltypes.h:66
#define NULL_FLOAT
int8_t boolval
Definition: Datum.h:68
int32_t intval
Definition: Datum.h:71
float floatval
Definition: Datum.h:73
int64_t bigintval
Definition: Datum.h:72
int16_t smallintval
Definition: Datum.h:70
Definition: sqltypes.h:70
int64_t inline_fixed_encoding_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:62
SQLTypes get_type_for_datum(const SQLTypeInfo &ti)
Definition: Importer.cpp:259
Definition: Datum.h:67
double doubleval
Definition: Datum.h:74

+ 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:386
void set_scale(int s)
Definition: sqltypes.h:498
int64_t convert_decimal_value_to_scale(const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
Definition: Datum.cpp:622
void set_dimension(int d)
Definition: sqltypes.h:495
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:383
void set_notnull(bool n)
Definition: sqltypes.h:500
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 563 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(), anonymous_namespace{Datum.cpp}::get_type_for_datum(), and foreign_storage::ParquetFixedLengthArrayEncoder::setNullFixedLengthArraySentinel().

563  {
565  switch (ti.get_size()) {
566  case 1:
567  return kTINYINT;
568  case 2:
569  return kSMALLINT;
570  case 4:
571  return kINT;
572  default:
573  UNREACHABLE() << "Unexpected string dictionary encoding size: " << ti.get_size();
574  }
575  return kNULLT;
576 }
HOST DEVICE int get_size() const
Definition: sqltypes.h:393
#define UNREACHABLE()
Definition: Logger.h:337
#define CHECK(condition)
Definition: Logger.h:291
bool is_dict_encoded_string() const
Definition: sqltypes.h:632
Definition: sqltypes.h:62

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 337 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().

337  {
338  Datum d;
339  try {
340  switch (ti.get_type()) {
341  case kARRAY:
342  case kCOLUMN:
343  case kCOLUMN_LIST:
344  break;
345  case kBOOLEAN:
346  if (s == "t" || s == "T" || s == "1" || to_upper(std::string(s)) == "TRUE") {
347  d.boolval = true;
348  } else if (s == "f" || s == "F" || s == "0" ||
349  to_upper(std::string(s)) == "FALSE") {
350  d.boolval = false;
351  } else {
352  throw std::runtime_error("Invalid string for boolean " + std::string(s));
353  }
354  break;
355  case kNUMERIC:
356  case kDECIMAL:
357  d.bigintval = parse_numeric(s, ti);
358  break;
359  case kBIGINT:
360  d.bigintval = parseInteger<int64_t>(s, ti);
361  break;
362  case kINT:
363  d.intval = parseInteger<int32_t>(s, ti);
364  break;
365  case kSMALLINT:
366  d.smallintval = parseInteger<int16_t>(s, ti);
367  break;
368  case kTINYINT:
369  d.tinyintval = parseInteger<int8_t>(s, ti);
370  break;
371  case kFLOAT:
372  d.floatval = std::stof(std::string(s));
373  break;
374  case kDOUBLE:
375  d.doubleval = std::stod(std::string(s));
376  break;
377  case kTIME:
378  d.bigintval = dateTimeParse<kTIME>(s, ti.get_dimension());
379  break;
380  case kTIMESTAMP:
381  d.bigintval = dateTimeParse<kTIMESTAMP>(s, ti.get_dimension());
382  break;
383  case kDATE:
384  d.bigintval = dateTimeParse<kDATE>(s, ti.get_dimension());
385  break;
386  case kPOINT:
387  case kMULTIPOINT:
388  case kLINESTRING:
389  case kMULTILINESTRING:
390  case kPOLYGON:
391  case kMULTIPOLYGON:
392  throw std::runtime_error("Internal error: geometry type in StringToDatum.");
393  default:
394  throw std::runtime_error("Internal error: invalid type in StringToDatum: " +
395  ti.get_type_name());
396  }
397  } catch (const std::invalid_argument&) {
398  throw std::runtime_error("Invalid conversion from string to " + ti.get_type_name());
399  } catch (const std::out_of_range&) {
400  throw std::runtime_error("Got out of range error during conversion from string to " +
401  ti.get_type_name());
402  }
403  return d;
404 }
int8_t tinyintval
Definition: Datum.h:69
Definition: sqltypes.h:66
int64_t parse_numeric(const std::string_view s, SQLTypeInfo &ti)
Definition: Datum.cpp:110
int8_t boolval
Definition: Datum.h:68
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
int32_t intval
Definition: Datum.h:71
float floatval
Definition: Datum.h:73
int64_t bigintval
Definition: Datum.h:72
int16_t smallintval
Definition: Datum.h:70
std::string to_upper(const std::string &str)
Definition: sqltypes.h:70
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:383
std::string get_type_name() const
Definition: sqltypes.h:507
Definition: sqltypes.h:62
Definition: Datum.h:67
double doubleval
Definition: Datum.h:74

+ Here is the call graph for this function:

+ Here is the caller graph for this function: