OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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)
 
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 607 of file DdlUtils.cpp.

References omnisci::glob(), and IMPORT.

Referenced by validate_allowed_file_path().

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

Referenced by set_whitelisted_paths().

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

+ 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 
)

Definition at line 509 of file DdlUtils.cpp.

References ColumnDescriptor::columnName, ColumnDescriptor::columnType, 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().

513  {
514  cd.columnName = column_name;
515  validate_and_set_type(cd, column_type);
516  cd.columnType.set_notnull(not_null);
517  validate_and_set_encoding(cd, encoding, column_type);
518  validate_and_set_array_size(cd, column_type);
519  cd.isSystemCol = false;
520  cd.isVirtualCol = false;
521 }
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
void set_notnull(bool n)
Definition: sqltypes.h:411
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:414
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
bool g_use_date_in_days_default_encoding
Definition: DdlUtils.cpp:32
int get_precision() const
Definition: sqltypes.h:317
void set_comp_param(int p)
Definition: sqltypes.h:415
Definition: sqltypes.h:52
bool is_geometry() const
Definition: sqltypes.h:501
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:489
bool is_string_array() const
Definition: sqltypes.h:490
bool is_decimal() const
Definition: sqltypes.h:492
std::string columnName
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:320

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

525  {
526  td.tableName = table_name;
527  td.nColumns = column_count;
528  td.isView = false;
529  td.fragmenter = nullptr;
535 }
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 667 of file DdlUtils.cpp.

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

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

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

+ 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 571 of file DdlUtils.cpp.

References FOREIGN_TABLE, TABLE, and VIEW.

571  {
572  if (table_type == ddl_utils::TableType::TABLE) {
573  return "Table";
574  }
575  if (table_type == ddl_utils::TableType::FOREIGN_TABLE) {
576  return "ForeignTable";
577  }
578  if (table_type == ddl_utils::TableType::VIEW) {
579  return "View";
580  }
581  throw std::runtime_error{"Unexpected table type"};
582 }
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 634 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().

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

+ 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:412
HOST DEVICE int get_size() const
Definition: sqltypes.h:324
void set_fixed_size()
Definition: sqltypes.h:413
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:322
SQLTypeInfo columnType
bool is_string_array() const
Definition: sqltypes.h:490
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:713
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:414
void set_comp_param(int p)
Definition: sqltypes.h:415
bool is_geometry() const
Definition: sqltypes.h:501
SQLTypeInfo columnType
std::string columnName
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:320

+ 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:315
void set_compression(EncodingType c)
Definition: sqltypes.h:414
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
void set_comp_param(int p)
Definition: sqltypes.h:415
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:414
void set_comp_param(int p)
Definition: sqltypes.h:415
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:489
bool is_string_array() const
Definition: sqltypes.h:490
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:414
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:415
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:315
void set_compression(EncodingType c)
Definition: sqltypes.h:414
Definition: sqltypes.h:48
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
int get_precision() const
Definition: sqltypes.h:317
void set_comp_param(int p)
Definition: sqltypes.h:415
Definition: sqltypes.h:52
#define IS_INTEGER(T)
Definition: sqltypes.h:239
bool is_high_precision_timestamp() const
Definition: sqltypes.h:733
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:414
void set_comp_param(int p)
Definition: sqltypes.h:415
bool is_geometry() const
Definition: sqltypes.h:501
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:489
bool is_string_array() const
Definition: sqltypes.h:490
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:414
void set_comp_param(int p)
Definition: sqltypes.h:415
SQLTypeInfo columnType
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:321
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:405
void set_input_srid(int d)
Definition: sqltypes.h:408
void set_scale(int s)
Definition: sqltypes.h:409
void set_output_srid(int s)
Definition: sqltypes.h:410
void set_dimension(int d)
Definition: sqltypes.h:406
SQLTypeInfo columnType
#define IS_GEO(T)
Definition: sqltypes.h:245
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:404

+ 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 590 of file DdlUtils.cpp.

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

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

+ 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 537 of file DdlUtils.cpp.

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

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

+ Here is the caller graph for this function:

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

Definition at line 546 of file DdlUtils.cpp.

References reserved_keywords.

Referenced by CreateForeignTableCommand::setColumnDetails().

546  {
547  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
548  if (reserved_keywords.find(upper_column_name) != reserved_keywords.end()) {
549  throw std::runtime_error("Cannot create column with reserved keyword '" +
550  column_name + "'");
551  }
552 }
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 554 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().

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

+ Here is the caller graph for this function: