OmniSciDB  a5dc49c757
 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 580 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().

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

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

626  {
627  int const dscale = new_type_info.get_scale() - type_info.get_scale();
628  return convert_decimal_value_to_scale_internal(decimal_value, dscale);
629 }
HOST DEVICE int get_scale() const
Definition: sqltypes.h:396
int64_t convert_decimal_value_to_scale_internal(const int64_t decimal_value, int const dscale)
Definition: Datum.cpp:81

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

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

+ 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 460 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 anonymous_namespace{TableFunctionExecutionContext.cpp}::append_literal_buffer(), 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(), Timestamp::toString(), Fragmenter_Namespace::InsertOrderFragmenter::updateChunkStats(), and ScalarExprToSql::visitConstant().

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

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

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

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

523  {
524  const auto type = ti.is_decimal() ? decimal_to_int_type(ti) : ti.get_type();
525  switch (type) {
526  case kBOOLEAN:
527  return datum.tinyintval;
528  case kTINYINT:
529  return datum.tinyintval;
530  case kSMALLINT:
531  return datum.smallintval;
532  case kCHAR:
533  case kVARCHAR:
534  case kTEXT:
536  case kINT:
537  return datum.intval;
538  case kBIGINT:
539  return datum.bigintval;
540  case kTIME:
541  case kTIMESTAMP:
542  case kDATE:
543  return datum.bigintval;
544  default:
545  abort();
546  }
547 }
int8_t tinyintval
Definition: Datum.h:73
#define CHECK_EQ(x, y)
Definition: Logger.h:301
Definition: sqltypes.h:76
int32_t intval
Definition: Datum.h:75
int64_t bigintval
Definition: Datum.h:76
int16_t smallintval
Definition: Datum.h:74
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:561
Definition: sqltypes.h:79
Definition: sqltypes.h:80
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
Definition: sqltypes.h:68
Definition: sqltypes.h:72
bool is_decimal() const
Definition: sqltypes.h:570

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

References DatumEqual(), and NullDatum().

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

331  {
332  const Datum null_datum = NullDatum(ti);
333  return DatumEqual(datum, null_datum, ti);
334 }
bool DatumEqual(const Datum a, const Datum b, const SQLTypeInfo &ti)
Definition: Datum.cpp:408
Datum NullDatum(const SQLTypeInfo &ti)
Definition: Datum.cpp:288
Definition: Datum.h:71

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Datum NullDatum ( const SQLTypeInfo ti)

Definition at line 288 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 StringOps_Namespace::compute_jaro_winkler_score(), IsNullDatum(), import_export::NullArray(), and import_export::StringToArray().

288  {
289  Datum d;
290  const auto type = get_type_for_datum(ti);
291  switch (type) {
292  case kBOOLEAN:
294  break;
295  case kBIGINT:
297  break;
298  case kINT:
300  break;
301  case kSMALLINT:
303  break;
304  case kTINYINT:
306  break;
307  case kFLOAT:
308  d.floatval = NULL_FLOAT;
309  break;
310  case kDOUBLE:
312  break;
313  case kTIME:
314  case kTIMESTAMP:
315  case kDATE:
317  break;
318  case kPOINT:
319  case kMULTIPOINT:
320  case kLINESTRING:
321  case kMULTILINESTRING:
322  case kPOLYGON:
323  case kMULTIPOLYGON:
324  throw std::runtime_error("Internal error: geometry type in NullDatum.");
325  default:
326  throw std::runtime_error("Internal error: invalid type in NullDatum.");
327  }
328  return d;
329 }
int8_t tinyintval
Definition: Datum.h:73
#define NULL_DOUBLE
Definition: sqltypes.h:76
#define NULL_FLOAT
int8_t boolval
Definition: Datum.h:72
int32_t intval
Definition: Datum.h:75
float floatval
Definition: Datum.h:77
int64_t bigintval
Definition: Datum.h:76
int16_t smallintval
Definition: Datum.h:74
Definition: sqltypes.h:80
int64_t inline_fixed_encoding_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:72
SQLTypes get_type_for_datum(const SQLTypeInfo &ti)
Definition: Importer.cpp:260
Definition: Datum.h:71
double doubleval
Definition: Datum.h:78

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

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

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

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

+ 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 339 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(), data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::convert(), anonymous_namespace{ArrowImporter.h}::ArrowValue< std::string >::operator DATA_TYPE(), populate_TColumn(), import_export::StringToArray(), and ddl_utils::anonymous_namespace{DdlUtils.cpp}::validate_literal().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function: