OmniSciDB  085a039ca4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ddl_utils::anonymous_namespace{DdlUtils.cpp} Namespace Reference

Functions

void validate_literal (const std::string &val, SQLTypeInfo column_type, const std::string &column_name)
 

Function Documentation

void ddl_utils::anonymous_namespace{DdlUtils.cpp}::validate_literal ( const std::string &  val,
SQLTypeInfo  column_type,
const std::string &  column_name 
)

Definition at line 514 of file DdlUtils.cpp.

References CHECK, convert_decimal_value_to_scale(), Geospatial::GeoTypesFactory::createGeoType(), SQLTypeInfo::get_elem_type(), SQLTypeInfo::get_size(), SQLTypeInfo::get_type(), kARRAY, kBIGINT, kBOOLEAN, kCHAR, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, Geospatial::GeoBase::kLINESTRING, kLINESTRING, Geospatial::GeoBase::kMULTIPOLYGON, kMULTIPOLYGON, kNUMERIC, Geospatial::GeoBase::kPOINT, kPOINT, Geospatial::GeoBase::kPOLYGON, kPOLYGON, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, kVARCHAR, StringDictionary::MAX_STRLEN, split(), StringToDatum(), to_string(), to_upper(), DecimalOverflowValidator::validate(), and DateDaysOverflowValidator::validate().

Referenced by ddl_utils::validate_and_set_default_value().

516  {
517  if (to_upper(val) == "NULL") {
518  return;
519  }
520  switch (column_type.get_type()) {
521  case kBOOLEAN:
522  case kTINYINT:
523  case kSMALLINT:
524  case kINT:
525  case kBIGINT:
526  case kFLOAT:
527  case kDOUBLE:
528  case kTIME:
529  case kTIMESTAMP:
530  StringToDatum(val, column_type);
531  break;
532  case kDATE: {
533  auto d = StringToDatum(val, column_type);
534  DateDaysOverflowValidator validator(column_type);
535  validator.validate(d.bigintval);
536  break;
537  }
538  case kDECIMAL:
539  case kNUMERIC: {
540  SQLTypeInfo ti(kNUMERIC, 0, 0, false);
541  auto d = StringToDatum(val, ti);
542  auto converted_val = convert_decimal_value_to_scale(d.bigintval, ti, column_type);
543  DecimalOverflowValidator validator(column_type);
544  validator.validate(converted_val);
545  break;
546  }
547  case kTEXT:
548  case kVARCHAR:
549  case kCHAR:
550  if (val.length() > StringDictionary::MAX_STRLEN) {
551  throw std::runtime_error("String too long for column " + column_name + " was " +
552  std::to_string(val.length()) + " max is " +
554  }
555  break;
556  case kARRAY: {
557  if (val.front() != '{' || val.back() != '}') {
558  throw std::runtime_error(column_name +
559  ": arrays should start and end with curly braces");
560  }
561  std::vector<std::string> elements = split(val.substr(1, val.length() - 2), ", ");
562  if (column_type.get_size() > 0) {
563  auto sti = column_type.get_elem_type();
564  size_t expected_size = column_type.get_size() / sti.get_size();
565  size_t actual_size = elements.size();
566  if (actual_size != expected_size) {
567  throw std::runtime_error("Fixed length array column " + column_name +
568  " expects " + std::to_string(expected_size) +
569  " values, received " + std::to_string(actual_size));
570  }
571  }
572  SQLTypeInfo element_ti = column_type.get_elem_type();
573  for (const auto& element : elements) {
574  if (to_upper(element) != "NULL") {
575  validate_literal(element, element_ti, column_name);
576  }
577  }
578  break;
579  }
580  case kPOINT:
581  case kLINESTRING:
582  case kPOLYGON:
583  case kMULTIPOLYGON:
584  if (val.empty()) {
585  return;
586  }
587  try {
589  if (!geo) {
590  throw std::runtime_error("Unexpected geo literal '" + val + "' for column " +
591  column_name);
592  }
593  if (!geo->transform(column_type)) {
594  throw std::runtime_error("Cannot transform SRID for literal '" + val +
595  "' for column " + column_name);
596  } else {
597  auto sql_type = column_type.get_type();
598  auto geo_type = geo->getType();
599  if ((geo_type == Geospatial::GeoBase::GeoType::kPOINT && sql_type != kPOINT) ||
601  sql_type != kLINESTRING) ||
603  sql_type != kPOLYGON) ||
605  sql_type != kMULTIPOLYGON)) {
606  throw std::runtime_error("Geo literal '" + val +
607  "' doesn't match the type "
608  "of column column " +
609  column_name);
610  }
611  }
612  } catch (Geospatial::GeoTypesError& e) {
613  throw std::runtime_error("Unexpected geo literal '" + val + "' for column " +
614  column_name + ": " + e.what());
615  }
616  break;
617  default:
618  CHECK(false) << "validate_literal() does not support type "
619  << column_type.get_type();
620  }
621 }
static std::unique_ptr< GeoBase > createGeoType(const std::string &wkt_or_wkb_hex)
Definition: Types.cpp:919
HOST DEVICE int get_size() const
Definition: sqltypes.h:339
void validate_literal(const std::string &val, SQLTypeInfo column_type, const std::string &column_name)
Definition: DdlUtils.cpp:514
Definition: sqltypes.h:49
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
std::string to_string(char const *&&v)
std::vector< std::string > split(std::string_view str, std::string_view delim, std::optional< size_t > maxsplit)
split apart a string into a vector of substrings
Datum StringToDatum(std::string_view s, SQLTypeInfo &ti)
Definition: Datum.cpp:275
std::string to_upper(const std::string &str)
Definition: sqltypes.h:52
Definition: sqltypes.h:53
int64_t convert_decimal_value_to_scale(const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
Definition: Datum.cpp:556
Definition: sqltypes.h:41
#define CHECK(condition)
Definition: Logger.h:223
static constexpr size_t MAX_STRLEN
Definition: sqltypes.h:45
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:865

+ Here is the call graph for this function:

+ Here is the caller graph for this function: