OmniSciDB  21ac014ffc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ddl_utils Namespace Reference

Classes

class  SqlType
 
class  Encoding
 
class  FilePathWhitelist
 
class  FilePathBlacklist
 

Enumerations

enum  DataTransferType { DataTransferType::IMPORT = 1, DataTransferType::EXPORT }
 
enum  TableType { TableType::TABLE = 1, TableType::VIEW, TableType::FOREIGN_TABLE }
 

Functions

void set_default_encoding (ColumnDescriptor &cd)
 
void validate_and_set_fixed_encoding (ColumnDescriptor &cd, int encoding_size, const SqlType *column_type)
 
void validate_and_set_dictionary_encoding (ColumnDescriptor &cd, int encoding_size)
 
void validate_and_set_none_encoding (ColumnDescriptor &cd)
 
void validate_and_set_sparse_encoding (ColumnDescriptor &cd, int encoding_size)
 
void validate_and_set_compressed_encoding (ColumnDescriptor &cd, int encoding_size)
 
void validate_and_set_date_encoding (ColumnDescriptor &cd, int encoding_size)
 
void validate_and_set_encoding (ColumnDescriptor &cd, const Encoding *encoding, const SqlType *column_type)
 
void validate_and_set_type (ColumnDescriptor &cd, SqlType *column_type)
 
void validate_and_set_array_size (ColumnDescriptor &cd, const SqlType *column_type)
 
void set_column_descriptor (const std::string &column_name, ColumnDescriptor &cd, SqlType *column_type, const bool not_null, const Encoding *encoding, const std::string *default_value)
 
void set_default_table_attributes (const std::string &table_name, TableDescriptor &td, const int32_t column_count)
 
void validate_non_duplicate_column (const std::string &column_name, std::unordered_set< std::string > &upper_column_names)
 
void validate_non_reserved_keyword (const std::string &column_name)
 
void validate_table_type (const TableDescriptor *td, const TableType expected_table_type, const std::string &command)
 
std::string table_type_enum_to_string (const TableType table_type)
 
std::string get_malformed_config_error_message (const std::string &config_key)
 
void validate_expanded_file_path (const std::string &file_path, const std::vector< std::string > &whitelisted_root_paths)
 
std::vector< std::string > get_expanded_file_paths (const std::string &file_path, const DataTransferType data_transfer_type)
 
void validate_allowed_file_path (const std::string &file_path, const DataTransferType data_transfer_type, const bool allow_wildcards)
 
void set_whitelisted_paths (const std::string &config_key, const std::string &config_value, std::vector< std::string > &whitelisted_paths)
 

Enumeration Type Documentation

Enumerator
IMPORT 
EXPORT 

Definition at line 80 of file DdlUtils.h.

enum ddl_utils::TableType
strong
Enumerator
TABLE 
VIEW 
FOREIGN_TABLE 

Definition at line 107 of file DdlUtils.h.

Function Documentation

std::vector<std::string> ddl_utils::get_expanded_file_paths ( const std::string &  file_path,
const DataTransferType  data_transfer_type 
)

Definition at line 609 of file DdlUtils.cpp.

References omnisci::glob(), and IMPORT.

Referenced by validate_allowed_file_path().

611  {
612  std::vector<std::string> file_paths;
613  if (data_transfer_type == DataTransferType::IMPORT) {
614  file_paths = omnisci::glob(file_path);
615  if (file_paths.size() == 0) {
616  throw std::runtime_error{"File or directory \"" + file_path + "\" does not exist."};
617  }
618  } else {
619  std::string path;
620  if (!boost::filesystem::exists(file_path)) {
621  // For exports, it is possible to provide a path to a new (nonexistent) file. In
622  // this case, validate using the parent path.
623  path = boost::filesystem::path(file_path).parent_path().string();
624  if (!boost::filesystem::exists(path)) {
625  throw std::runtime_error{"File or directory \"" + file_path +
626  "\" does not exist."};
627  }
628  } else {
629  path = file_path;
630  }
631  file_paths = {path};
632  }
633  return file_paths;
634 }
std::vector< std::string > glob(const std::string &pattern)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string ddl_utils::get_malformed_config_error_message ( const std::string &  config_key)

Definition at line 586 of file DdlUtils.cpp.

Referenced by set_whitelisted_paths().

586  {
587  return "Configuration value for \"" + config_key +
588  "\" is malformed. Value should be a list of paths with format: [ "
589  "\"root-path-1\", \"root-path-2\", ... ]";
590 }

+ Here is the caller graph for this function:

void ddl_utils::set_column_descriptor ( const std::string &  column_name,
ColumnDescriptor cd,
SqlType *  column_type,
const bool  not_null,
const Encoding *  encoding,
const std::string *  default_value 
)

Definition at line 509 of file DdlUtils.cpp.

References ColumnDescriptor::columnName, ColumnDescriptor::columnType, ColumnDescriptor::default_value, ColumnDescriptor::isSystemCol, ColumnDescriptor::isVirtualCol, SQLTypeInfo::set_notnull(), validate_and_set_array_size(), validate_and_set_encoding(), and validate_and_set_type().

Referenced by Parser::DDLStmt::setColumnDescriptor(), and CreateForeignTableCommand::setColumnDetails().

514  {
515  cd.columnName = column_name;
516  validate_and_set_type(cd, column_type);
517  cd.columnType.set_notnull(not_null);
518  validate_and_set_encoding(cd, encoding, column_type);
519  validate_and_set_array_size(cd, column_type);
520  cd.isSystemCol = false;
521  cd.isVirtualCol = false;
522  cd.default_value = default_value ? std::make_optional(*default_value) : std::nullopt;
523 }
void validate_and_set_array_size(ColumnDescriptor &cd, const SqlType *column_type)
Definition: DdlUtils.cpp:484
void validate_and_set_encoding(ColumnDescriptor &cd, const Encoding *encoding, const SqlType *column_type)
Definition: DdlUtils.cpp:429
std::optional< std::string > default_value
void set_notnull(bool n)
Definition: sqltypes.h:420
SQLTypeInfo columnType
std::string columnName
void validate_and_set_type(ColumnDescriptor &cd, SqlType *column_type)
Definition: DdlUtils.cpp:465

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ddl_utils::set_default_encoding ( ColumnDescriptor cd)

Definition at line 210 of file DdlUtils.cpp.

References ColumnDescriptor::columnName, ColumnDescriptor::columnType, g_use_date_in_days_default_encoding, SQLTypeInfo::get_output_srid(), SQLTypeInfo::get_precision(), SQLTypeInfo::get_type(), SQLTypeInfo::is_decimal(), SQLTypeInfo::is_geometry(), SQLTypeInfo::is_string(), SQLTypeInfo::is_string_array(), kDATE, kENCODING_DATE_IN_DAYS, kENCODING_DICT, kENCODING_FIXED, kENCODING_GEOINT, kENCODING_NONE, SQLTypeInfo::set_comp_param(), and SQLTypeInfo::set_compression().

Referenced by validate_and_set_encoding().

210  {
211  // Change default TEXT column behaviour to be DICT encoded
212  if (cd.columnType.is_string() || cd.columnType.is_string_array()) {
213  // default to 32-bits
215  cd.columnType.set_comp_param(32);
216  } else if (cd.columnType.is_decimal() && cd.columnType.get_precision() <= 4) {
218  cd.columnType.set_comp_param(16);
219  } else if (cd.columnType.is_decimal() && cd.columnType.get_precision() <= 9) {
221  cd.columnType.set_comp_param(32);
222  } else if (cd.columnType.is_decimal() && cd.columnType.get_precision() > 18) {
223  throw std::runtime_error(cd.columnName + ": Precision too high, max 18.");
224  } else if (cd.columnType.is_geometry() && cd.columnType.get_output_srid() == 4326) {
225  // default to GEOINT 32-bits
227  cd.columnType.set_comp_param(32);
229  // Days encoding for DATE
232  } else {
235  }
236 }
void set_compression(EncodingType c)
Definition: sqltypes.h:423
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:323
bool g_use_date_in_days_default_encoding
Definition: DdlUtils.cpp:32
int get_precision() const
Definition: sqltypes.h:326
void set_comp_param(int p)
Definition: sqltypes.h:424
Definition: sqltypes.h:52
bool is_geometry() const
Definition: sqltypes.h:510
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:498
bool is_string_array() const
Definition: sqltypes.h:499
bool is_decimal() const
Definition: sqltypes.h:501
std::string columnName
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:329

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ddl_utils::set_default_table_attributes ( const std::string &  table_name,
TableDescriptor td,
const int32_t  column_count 
)

Definition at line 525 of file DdlUtils.cpp.

References DEFAULT_FRAGMENT_ROWS, DEFAULT_MAX_CHUNK_SIZE, DEFAULT_MAX_ROWS, DEFAULT_PAGE_SIZE, TableDescriptor::fragmenter, TableDescriptor::fragPageSize, TableDescriptor::fragType, Fragmenter_Namespace::INSERT_ORDER, TableDescriptor::isView, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRows, TableDescriptor::nColumns, and TableDescriptor::tableName.

Referenced by Parser::CreateTableStmt::executeDryRun(), and CreateForeignTableCommand::setTableDetails().

527  {
528  td.tableName = table_name;
529  td.nColumns = column_count;
530  td.isView = false;
531  td.fragmenter = nullptr;
537 }
std::string tableName
#define DEFAULT_MAX_CHUNK_SIZE
#define DEFAULT_MAX_ROWS
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
#define DEFAULT_PAGE_SIZE
#define DEFAULT_FRAGMENT_ROWS
Fragmenter_Namespace::FragmenterType fragType

+ Here is the caller graph for this function:

void ddl_utils::set_whitelisted_paths ( const std::string &  config_key,
const std::string &  config_value,
std::vector< std::string > &  whitelisted_paths 
)

Definition at line 669 of file DdlUtils.cpp.

References get_malformed_config_error_message(), logger::INFO, LOG, and shared::printContainer().

Referenced by ddl_utils::FilePathWhitelist::initialize().

671  {
672  rapidjson::Document whitelisted_root_paths;
673  whitelisted_root_paths.Parse(config_value);
674  if (!whitelisted_root_paths.IsArray()) {
675  throw std::runtime_error{get_malformed_config_error_message(config_key)};
676  }
677  for (const auto& root_path : whitelisted_root_paths.GetArray()) {
678  if (!root_path.IsString()) {
679  throw std::runtime_error{get_malformed_config_error_message(config_key)};
680  }
681  if (!boost::filesystem::exists(root_path.GetString())) {
682  throw std::runtime_error{"Whitelisted root path \"" +
683  std::string{root_path.GetString()} + "\" does not exist."};
684  }
685  whitelisted_paths.emplace_back(
686  boost::filesystem::canonical(root_path.GetString()).string());
687  }
688  LOG(INFO) << "Parsed " << config_key << ": "
689  << shared::printContainer(whitelisted_paths);
690 }
#define LOG(tag)
Definition: Logger.h:200
std::string get_malformed_config_error_message(const std::string &config_key)
Definition: DdlUtils.cpp:586
PrintContainer< CONTAINER > printContainer(CONTAINER &container)
Definition: misc.h:96

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string ddl_utils::table_type_enum_to_string ( const TableType  table_type)

Definition at line 573 of file DdlUtils.cpp.

References FOREIGN_TABLE, TABLE, and VIEW.

573  {
574  if (table_type == ddl_utils::TableType::TABLE) {
575  return "Table";
576  }
577  if (table_type == ddl_utils::TableType::FOREIGN_TABLE) {
578  return "ForeignTable";
579  }
580  if (table_type == ddl_utils::TableType::VIEW) {
581  return "View";
582  }
583  throw std::runtime_error{"Unexpected table type"};
584 }
void ddl_utils::validate_allowed_file_path ( const std::string &  file_path,
const DataTransferType  data_transfer_type,
const bool  allow_wildcards = false 
)

Validates that the given file path is allowed. Validation entails ensuring that given path is not under a blacklisted root path and path is under a whitelisted path, if whitelisted paths have been configured. Also excludes the use of spaces and punctuation other than: . / _ + - = :

Parameters
file_path- file path to validate
data_transfer_type- enum indicating whether validation is for an import or export use case
allow_wildcards- bool indicating if wildcards are allowed

Definition at line 636 of file DdlUtils.cpp.

References get_expanded_file_paths(), ddl_utils::FilePathBlacklist::isBlacklistedPath(), and ddl_utils::FilePathWhitelist::validateWhitelistedFilePath().

Referenced by TableArchiver::dumpTable(), Parser::CopyTableStmt::execute(), Parser::ExportQueryStmt::execute(), TableArchiver::restoreTable(), anonymous_namespace{TableArchiver.cpp}::simple_file_cat(), anonymous_namespace{DBHandler.cpp}::validate_import_file_path_if_local(), and foreign_storage::AbstractFileStorageDataWrapper::validateFilePath().

638  {
639  // Reject any punctuation characters except for a few safe ones.
640  // Some punctuation characters present a security risk when passed
641  // to subprocesses. Don't change this without a security review.
642  static const std::string safe_punctuation{"./_+-=:~"};
643  for (const auto& ch : file_path) {
644  if (std::ispunct(ch) && safe_punctuation.find(ch) == std::string::npos &&
645  !(allow_wildcards && ch == '*')) {
646  throw std::runtime_error(std::string("Punctuation \"") + ch +
647  "\" is not allowed in file path: " + file_path);
648  }
649  }
650 
651  // Enforce our whitelist and blacklist for file paths.
652  const auto& expanded_file_paths =
653  get_expanded_file_paths(file_path, data_transfer_type);
654  for (const auto& path : expanded_file_paths) {
655  if (FilePathBlacklist::isBlacklistedPath(path)) {
656  const auto& canonical_file_path = boost::filesystem::canonical(file_path);
657  if (canonical_file_path == boost::filesystem::absolute(file_path)) {
658  throw std::runtime_error{"Access to file or directory path \"" + file_path +
659  "\" is not allowed."};
660  }
661  throw std::runtime_error{"Access to file or directory path \"" + file_path +
662  "\" (resolved to \"" + canonical_file_path.string() +
663  "\") is not allowed."};
664  }
665  }
666  FilePathWhitelist::validateWhitelistedFilePath(expanded_file_paths, data_transfer_type);
667 }
std::vector< std::string > get_expanded_file_paths(const std::string &file_path, const DataTransferType data_transfer_type)
Definition: DdlUtils.cpp:609

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ddl_utils::validate_and_set_array_size ( ColumnDescriptor cd,
const SqlType *  column_type 
)

Definition at line 484 of file DdlUtils.cpp.

References ColumnDescriptor::columnName, ColumnDescriptor::columnType, ddl_utils::SqlType::get_array_size(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_elem_type(), ddl_utils::SqlType::get_is_array(), SQLTypeInfo::get_size(), SQLTypeInfo::is_string_array(), kENCODING_DICT, SQLTypeInfo::set_fixed_size(), and SQLTypeInfo::set_size().

Referenced by set_column_descriptor().

484  {
485  if (cd.columnType.is_string_array() &&
487  throw std::runtime_error(
488  cd.columnName +
489  ": Array of strings must be dictionary encoded. Specify ENCODING DICT");
490  }
491 
492  if (column_type->get_is_array()) {
493  int s = -1;
494  auto array_size = column_type->get_array_size();
495  if (array_size > 0) {
496  auto sti = cd.columnType.get_elem_type();
497  s = array_size * sti.get_size();
498  if (s <= 0) {
499  throw std::runtime_error(cd.columnName + ": Unexpected fixed length array size");
500  }
501  }
502  cd.columnType.set_size(s);
503 
504  } else {
506  }
507 }
void set_size(int s)
Definition: sqltypes.h:421
HOST DEVICE int get_size() const
Definition: sqltypes.h:333
void set_fixed_size()
Definition: sqltypes.h:422
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:331
SQLTypeInfo columnType
bool is_string_array() const
Definition: sqltypes.h:499
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:726
std::string columnName

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ddl_utils::validate_and_set_compressed_encoding ( ColumnDescriptor cd,
int  encoding_size 
)

Definition at line 390 of file DdlUtils.cpp.

References ColumnDescriptor::columnName, ColumnDescriptor::columnType, SQLTypeInfo::get_output_srid(), SQLTypeInfo::is_geometry(), kENCODING_GEOINT, SQLTypeInfo::set_comp_param(), and SQLTypeInfo::set_compression().

Referenced by validate_and_set_encoding().

390  {
391  if (!cd.columnType.is_geometry() || cd.columnType.get_output_srid() != 4326) {
392  throw std::runtime_error(
393  cd.columnName + ": COMPRESSED encoding is only supported on WGS84 geo columns.");
394  }
395  int comp_param;
396  if (encoding_size == 0) {
397  comp_param = 32; // default to 32-bits
398  } else {
399  comp_param = encoding_size;
400  }
401  if (comp_param != 32) {
402  throw std::runtime_error(cd.columnName +
403  ": only 32-bit COMPRESSED geo encoding is supported");
404  }
405  // encoding longitude/latitude as integers
407  cd.columnType.set_comp_param(comp_param);
408 }
void set_compression(EncodingType c)
Definition: sqltypes.h:423
void set_comp_param(int p)
Definition: sqltypes.h:424
bool is_geometry() const
Definition: sqltypes.h:510
SQLTypeInfo columnType
std::string columnName
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:329

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ddl_utils::validate_and_set_date_encoding ( ColumnDescriptor cd,
int  encoding_size 
)

Definition at line 410 of file DdlUtils.cpp.

References ColumnDescriptor::columnName, ColumnDescriptor::columnType, SQLTypeInfo::get_subtype(), SQLTypeInfo::get_type(), kARRAY, kDATE, kENCODING_DATE_IN_DAYS, SQLTypeInfo::set_comp_param(), and SQLTypeInfo::set_compression().

Referenced by validate_and_set_encoding().

410  {
411  // days encoding for dates
412  if (cd.columnType.get_type() == kARRAY && cd.columnType.get_subtype() == kDATE) {
413  throw std::runtime_error(cd.columnName +
414  ": Cannot apply days encoding to date array.");
415  }
416  if (cd.columnType.get_type() != kDATE) {
417  throw std::runtime_error(cd.columnName +
418  ": Days encoding is only supported for DATE columns.");
419  }
420  if (encoding_size != 32 && encoding_size != 16) {
421  throw std::runtime_error(cd.columnName +
422  ": Compression parameter for Days encoding on "
423  "DATE must be 16 or 32.");
424  }
426  cd.columnType.set_comp_param((encoding_size == 16) ? 16 : 0);
427 }
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:324
void set_compression(EncodingType c)
Definition: sqltypes.h:423
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:323
void set_comp_param(int p)
Definition: sqltypes.h:424
Definition: sqltypes.h:52
SQLTypeInfo columnType
std::string columnName

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ddl_utils::validate_and_set_dictionary_encoding ( ColumnDescriptor cd,
int  encoding_size 
)

Definition at line 336 of file DdlUtils.cpp.

References ColumnDescriptor::columnName, ColumnDescriptor::columnType, SQLTypeInfo::is_string(), SQLTypeInfo::is_string_array(), kENCODING_DICT, SQLTypeInfo::set_comp_param(), and SQLTypeInfo::set_compression().

Referenced by validate_and_set_encoding().

336  {
337  if (!cd.columnType.is_string() && !cd.columnType.is_string_array()) {
338  throw std::runtime_error(
339  cd.columnName +
340  ": Dictionary encoding is only supported on string or string array columns.");
341  }
342  int comp_param;
343  if (encoding_size == 0) {
344  comp_param = 32; // default to 32-bits
345  } else {
346  comp_param = encoding_size;
347  }
348  if (cd.columnType.is_string_array() && comp_param != 32) {
349  throw std::runtime_error(cd.columnName +
350  ": Compression parameter for string arrays must be 32");
351  }
352  if (comp_param != 8 && comp_param != 16 && comp_param != 32) {
353  throw std::runtime_error(
354  cd.columnName +
355  ": Compression parameter for Dictionary encoding must be 8 or 16 or 32.");
356  }
357  // dictionary encoding
359  cd.columnType.set_comp_param(comp_param);
360 }
void set_compression(EncodingType c)
Definition: sqltypes.h:423
void set_comp_param(int p)
Definition: sqltypes.h:424
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:498
bool is_string_array() const
Definition: sqltypes.h:499
std::string columnName

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ddl_utils::validate_and_set_encoding ( ColumnDescriptor cd,
const Encoding *  encoding,
const SqlType *  column_type 
)

Definition at line 429 of file DdlUtils.cpp.

References ColumnDescriptor::columnName, ColumnDescriptor::columnType, ddl_utils::Encoding::get_encoding_name(), ddl_utils::Encoding::get_encoding_param(), kENCODING_DIFF, kENCODING_RL, SQLTypeInfo::set_comp_param(), SQLTypeInfo::set_compression(), set_default_encoding(), validate_and_set_compressed_encoding(), validate_and_set_date_encoding(), validate_and_set_dictionary_encoding(), validate_and_set_fixed_encoding(), validate_and_set_none_encoding(), and validate_and_set_sparse_encoding().

Referenced by set_column_descriptor().

431  {
432  if (encoding == nullptr) {
434  } else {
435  const std::string& comp = *encoding->get_encoding_name();
436  if (boost::iequals(comp, "fixed")) {
437  validate_and_set_fixed_encoding(cd, encoding->get_encoding_param(), column_type);
438  } else if (boost::iequals(comp, "rl")) {
439  // run length encoding
442  // throw std::runtime_error("RL(Run Length) encoding not supported yet.");
443  } else if (boost::iequals(comp, "diff")) {
444  // differential encoding
447  // throw std::runtime_error("DIFF(differential) encoding not supported yet.");
448  } else if (boost::iequals(comp, "dict")) {
449  validate_and_set_dictionary_encoding(cd, encoding->get_encoding_param());
450  } else if (boost::iequals(comp, "NONE")) {
452  } else if (boost::iequals(comp, "sparse")) {
453  validate_and_set_sparse_encoding(cd, encoding->get_encoding_param());
454  } else if (boost::iequals(comp, "compressed")) {
455  validate_and_set_compressed_encoding(cd, encoding->get_encoding_param());
456  } else if (boost::iequals(comp, "days")) {
457  validate_and_set_date_encoding(cd, encoding->get_encoding_param());
458  } else {
459  throw std::runtime_error(cd.columnName + ": Invalid column compression scheme " +
460  comp);
461  }
462  }
463 }
void set_compression(EncodingType c)
Definition: sqltypes.h:423
void validate_and_set_sparse_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:373
void validate_and_set_dictionary_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:336
void validate_and_set_none_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:362
void set_default_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:210
void set_comp_param(int p)
Definition: sqltypes.h:424
void validate_and_set_compressed_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:390
void validate_and_set_fixed_encoding(ColumnDescriptor &cd, int encoding_size, const SqlType *column_type)
Definition: DdlUtils.cpp:238
void validate_and_set_date_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:410
SQLTypeInfo columnType
std::string columnName

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ddl_utils::validate_and_set_fixed_encoding ( ColumnDescriptor cd,
int  encoding_size,
const SqlType *  column_type 
)

Definition at line 238 of file DdlUtils.cpp.

References ColumnDescriptor::columnName, ColumnDescriptor::columnType, SQLTypeInfo::get_precision(), SQLTypeInfo::get_subtype(), SQLTypeInfo::get_type(), is_datetime(), SQLTypeInfo::is_high_precision_timestamp(), IS_INTEGER, kARRAY, kBIGINT, kDATE, kDECIMAL, kENCODING_DATE_IN_DAYS, kENCODING_FIXED, kINT, kNUMERIC, kSMALLINT, kTIME, kTIMESTAMP, kTINYINT, SQLTypeInfo::set_comp_param(), SQLTypeInfo::set_compression(), ddl_utils::SqlType::to_string(), and run_benchmark_import::type.

Referenced by validate_and_set_encoding().

240  {
241  auto type = cd.columnType.get_type();
242  // fixed-bits encoding
243  if (type == kARRAY) {
244  type = cd.columnType.get_subtype();
245  switch (type) {
246  case kTINYINT:
247  case kSMALLINT:
248  case kINT:
249  case kBIGINT:
250  case kDATE:
251  throw std::runtime_error(cd.columnName + ": Cannot apply FIXED encoding to " +
252  column_type->to_string() + " type array.");
253  break;
254  default:
255  break;
256  }
257  }
258 
259  if (!IS_INTEGER(type) && !is_datetime(type) &&
260  !(type == kDECIMAL || type == kNUMERIC)) {
261  throw std::runtime_error(
262  cd.columnName +
263  ": Fixed encoding is only supported for integer or time columns.");
264  }
265 
266  switch (type) {
267  case kSMALLINT:
268  if (encoding_size != 8) {
269  throw std::runtime_error(
270  cd.columnName +
271  ": Compression parameter for Fixed encoding on SMALLINT must be 8.");
272  }
273  break;
274  case kINT:
275  if (encoding_size != 8 && encoding_size != 16) {
276  throw std::runtime_error(
277  cd.columnName +
278  ": Compression parameter for Fixed encoding on INTEGER must be 8 or 16.");
279  }
280  break;
281  case kBIGINT:
282  if (encoding_size != 8 && encoding_size != 16 && encoding_size != 32) {
283  throw std::runtime_error(cd.columnName +
284  ": Compression parameter for Fixed encoding on "
285  "BIGINT must be 8 or 16 or 32.");
286  }
287  break;
288  case kTIMESTAMP:
289  case kTIME:
290  if (encoding_size != 32) {
291  throw std::runtime_error(cd.columnName +
292  ": Compression parameter for Fixed encoding on "
293  "TIME or TIMESTAMP must be 32.");
294  } else if (cd.columnType.is_high_precision_timestamp()) {
295  throw std::runtime_error("Fixed encoding is not supported for TIMESTAMP(3|6|9).");
296  }
297  break;
298  case kDECIMAL:
299  case kNUMERIC:
300  if (encoding_size != 32 && encoding_size != 16) {
301  throw std::runtime_error(cd.columnName +
302  ": Compression parameter for Fixed encoding on "
303  "DECIMAL must be 16 or 32.");
304  }
305 
306  if (encoding_size == 32 && cd.columnType.get_precision() > 9) {
307  throw std::runtime_error(cd.columnName +
308  ": Precision too high for Fixed(32) encoding, max 9.");
309  }
310 
311  if (encoding_size == 16 && cd.columnType.get_precision() > 4) {
312  throw std::runtime_error(cd.columnName +
313  ": Precision too high for Fixed(16) encoding, max 4.");
314  }
315  break;
316  case kDATE:
317  if (encoding_size != 32 && encoding_size != 16) {
318  throw std::runtime_error(cd.columnName +
319  ": Compression parameter for Fixed encoding on "
320  "DATE must be 16 or 32.");
321  }
322  break;
323  default:
324  throw std::runtime_error(cd.columnName + ": Cannot apply FIXED encoding to " +
325  column_type->to_string());
326  }
327  if (type == kDATE) {
329  cd.columnType.set_comp_param(16);
330  } else {
332  cd.columnType.set_comp_param(encoding_size);
333  }
334 }
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:324
void set_compression(EncodingType c)
Definition: sqltypes.h:423
Definition: sqltypes.h:48
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:323
int get_precision() const
Definition: sqltypes.h:326
void set_comp_param(int p)
Definition: sqltypes.h:424
Definition: sqltypes.h:52
#define IS_INTEGER(T)
Definition: sqltypes.h:239
bool is_high_precision_timestamp() const
Definition: sqltypes.h:746
Definition: sqltypes.h:44
SQLTypeInfo columnType
std::string columnName
constexpr auto is_datetime(SQLTypes type)
Definition: sqltypes.h:257

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ddl_utils::validate_and_set_none_encoding ( ColumnDescriptor cd)

Definition at line 362 of file DdlUtils.cpp.

References ColumnDescriptor::columnName, ColumnDescriptor::columnType, SQLTypeInfo::is_geometry(), SQLTypeInfo::is_string(), SQLTypeInfo::is_string_array(), kENCODING_NONE, SQLTypeInfo::set_comp_param(), and SQLTypeInfo::set_compression().

Referenced by validate_and_set_encoding().

362  {
363  if (!cd.columnType.is_string() && !cd.columnType.is_string_array() &&
364  !cd.columnType.is_geometry()) {
365  throw std::runtime_error(
366  cd.columnName +
367  ": None encoding is only supported on string, string array, or geo columns.");
368  }
371 }
void set_compression(EncodingType c)
Definition: sqltypes.h:423
void set_comp_param(int p)
Definition: sqltypes.h:424
bool is_geometry() const
Definition: sqltypes.h:510
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:498
bool is_string_array() const
Definition: sqltypes.h:499
std::string columnName

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ddl_utils::validate_and_set_sparse_encoding ( ColumnDescriptor cd,
int  encoding_size 
)

Definition at line 373 of file DdlUtils.cpp.

References ColumnDescriptor::columnName, ColumnDescriptor::columnType, SQLTypeInfo::get_notnull(), kENCODING_SPARSE, SQLTypeInfo::set_comp_param(), and SQLTypeInfo::set_compression().

Referenced by validate_and_set_encoding().

373  {
374  // sparse column encoding with mostly NULL values
375  if (cd.columnType.get_notnull()) {
376  throw std::runtime_error(cd.columnName +
377  ": Cannot do sparse column encoding on a NOT NULL column.");
378  }
379  if (encoding_size == 0 || encoding_size % 8 != 0 || encoding_size > 48) {
380  throw std::runtime_error(
381  cd.columnName +
382  "Must specify number of bits as 8, 16, 24, 32 or 48 as the parameter to "
383  "sparse-column encoding.");
384  }
386  cd.columnType.set_comp_param(encoding_size);
387  // throw std::runtime_error("SPARSE encoding not supported yet.");
388 }
void set_compression(EncodingType c)
Definition: sqltypes.h:423
void set_comp_param(int p)
Definition: sqltypes.h:424
SQLTypeInfo columnType
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:330
std::string columnName

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ddl_utils::validate_and_set_type ( ColumnDescriptor cd,
SqlType *  column_type 
)

Definition at line 465 of file DdlUtils.cpp.

References ddl_utils::SqlType::check_type(), ColumnDescriptor::columnType, ddl_utils::SqlType::get_is_array(), ddl_utils::SqlType::get_param1(), ddl_utils::SqlType::get_param2(), ddl_utils::SqlType::get_type(), IS_GEO, kARRAY, SQLTypeInfo::set_dimension(), SQLTypeInfo::set_input_srid(), SQLTypeInfo::set_output_srid(), SQLTypeInfo::set_scale(), SQLTypeInfo::set_subtype(), and SQLTypeInfo::set_type().

Referenced by set_column_descriptor().

465  {
466  column_type->check_type();
467 
468  if (column_type->get_is_array()) {
470  cd.columnType.set_subtype(column_type->get_type());
471  } else {
472  cd.columnType.set_type(column_type->get_type());
473  }
474  if (IS_GEO(column_type->get_type())) {
475  cd.columnType.set_subtype(static_cast<SQLTypes>(column_type->get_param1()));
476  cd.columnType.set_input_srid(column_type->get_param2());
477  cd.columnType.set_output_srid(column_type->get_param2());
478  } else {
479  cd.columnType.set_dimension(column_type->get_param1());
480  cd.columnType.set_scale(column_type->get_param2());
481  }
482 }
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:414
void set_input_srid(int d)
Definition: sqltypes.h:417
void set_scale(int s)
Definition: sqltypes.h:418
void set_output_srid(int s)
Definition: sqltypes.h:419
void set_dimension(int d)
Definition: sqltypes.h:415
SQLTypeInfo columnType
#define IS_GEO(T)
Definition: sqltypes.h:245
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:413

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ddl_utils::validate_expanded_file_path ( const std::string &  file_path,
const std::vector< std::string > &  whitelisted_root_paths 
)

Definition at line 592 of file DdlUtils.cpp.

Referenced by ddl_utils::FilePathWhitelist::validateWhitelistedFilePath().

593  {
594  const auto& canonical_file_path = boost::filesystem::canonical(file_path);
595  for (const auto& root_path : whitelisted_root_paths) {
596  if (boost::istarts_with(canonical_file_path.string(), root_path)) {
597  return;
598  }
599  }
600  if (canonical_file_path == boost::filesystem::absolute(file_path)) {
601  throw std::runtime_error{"File or directory path \"" + file_path +
602  "\" is not whitelisted."};
603  }
604  throw std::runtime_error{"File or directory path \"" + file_path +
605  "\" (resolved to \"" + canonical_file_path.string() +
606  "\") is not whitelisted."};
607 }

+ Here is the caller graph for this function:

void ddl_utils::validate_non_duplicate_column ( const std::string &  column_name,
std::unordered_set< std::string > &  upper_column_names 
)

Definition at line 539 of file DdlUtils.cpp.

Referenced by Parser::CreateTableStmt::executeDryRun(), and CreateForeignTableCommand::setColumnDetails().

540  {
541  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
542  const auto insert_it = upper_column_names.insert(upper_column_name);
543  if (!insert_it.second) {
544  throw std::runtime_error("Column '" + column_name + "' defined more than once");
545  }
546 }

+ Here is the caller graph for this function:

void ddl_utils::validate_non_reserved_keyword ( const std::string &  column_name)

Definition at line 548 of file DdlUtils.cpp.

References reserved_keywords.

Referenced by CreateForeignTableCommand::setColumnDetails().

548  {
549  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
550  if (reserved_keywords.find(upper_column_name) != reserved_keywords.end()) {
551  throw std::runtime_error("Cannot create column with reserved keyword '" +
552  column_name + "'");
553  }
554 }
static std::set< std::string > reserved_keywords

+ Here is the caller graph for this function:

void ddl_utils::validate_table_type ( const TableDescriptor td,
const TableType  expected_table_type,
const std::string &  command 
)

Definition at line 556 of file DdlUtils.cpp.

References StorageType::FOREIGN_TABLE, FOREIGN_TABLE, TableDescriptor::isView, TableDescriptor::storageType, TABLE, TableDescriptor::tableName, and VIEW.

Referenced by Parser::AddColumnStmt::check_executable(), DropForeignTableCommand::execute(), AlterForeignTableCommand::execute(), Parser::DropTableStmt::execute(), Parser::RenameTableStmt::execute(), Parser::RenameColumnStmt::execute(), Parser::DropColumnStmt::execute(), and Parser::DropViewStmt::execute().

558  {
559  if (td->isView) {
560  if (expected_table_type != TableType::VIEW) {
561  throw std::runtime_error(td->tableName + " is a view. Use " + command + " VIEW.");
562  }
563  } else if (td->storageType == StorageType::FOREIGN_TABLE) {
564  if (expected_table_type != TableType::FOREIGN_TABLE) {
565  throw std::runtime_error(td->tableName + " is a foreign table. Use " + command +
566  " FOREIGN TABLE.");
567  }
568  } else if (expected_table_type != TableType::TABLE) {
569  throw std::runtime_error(td->tableName + " is a table. Use " + command + " TABLE.");
570  }
571 }
std::string tableName
std::string storageType
#define VIEW
static constexpr char const * FOREIGN_TABLE

+ Here is the caller graph for this function: