OmniSciDB  bf83d84833
 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 105 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 586 of file DdlUtils.cpp.

References omnisci::glob(), and IMPORT.

Referenced by validate_allowed_file_path().

588  {
589  std::vector<std::string> file_paths;
590  if (data_transfer_type == DataTransferType::IMPORT) {
591  file_paths = omnisci::glob(file_path);
592  if (file_paths.size() == 0) {
593  throw std::runtime_error{"File or directory \"" + file_path + "\" does not exist."};
594  }
595  } else {
596  std::string path;
597  if (!boost::filesystem::exists(file_path)) {
598  // For exports, it is possible to provide a path to a new (nonexistent) file. In
599  // this case, validate using the parent path.
600  path = boost::filesystem::path(file_path).parent_path().string();
601  if (!boost::filesystem::exists(path)) {
602  throw std::runtime_error{"File or directory \"" + file_path +
603  "\" does not exist."};
604  }
605  } else {
606  path = file_path;
607  }
608  file_paths = {path};
609  }
610  return file_paths;
611 }
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 568 of file DdlUtils.cpp.

Referenced by set_whitelisted_paths().

568  {
569  return "Configuration value for \"" + config_key +
570  "\" is malformed. Value should be a list of paths with format: [ "
571  "\"root-path-1\", \"root-path-2\", ... ]";
572 }

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

497  {
498  cd.columnName = column_name;
499  validate_and_set_type(cd, column_type);
500  cd.columnType.set_notnull(not_null);
501  validate_and_set_encoding(cd, encoding, column_type);
502  validate_and_set_array_size(cd, column_type);
503  cd.isSystemCol = false;
504  cd.isVirtualCol = false;
505 }
void validate_and_set_array_size(ColumnDescriptor &cd, const SqlType *column_type)
Definition: DdlUtils.cpp:468
void validate_and_set_encoding(ColumnDescriptor &cd, const Encoding *encoding, const SqlType *column_type)
Definition: DdlUtils.cpp:413
void set_notnull(bool n)
Definition: sqltypes.h:408
SQLTypeInfo columnType
std::string columnName
void validate_and_set_type(ColumnDescriptor &cd, SqlType *column_type)
Definition: DdlUtils.cpp:449

+ 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:411
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:311
bool g_use_date_in_days_default_encoding
Definition: DdlUtils.cpp:32
int get_precision() const
Definition: sqltypes.h:314
void set_comp_param(int p)
Definition: sqltypes.h:412
Definition: sqltypes.h:52
bool is_geometry() const
Definition: sqltypes.h:490
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:478
bool is_string_array() const
Definition: sqltypes.h:479
bool is_decimal() const
Definition: sqltypes.h:481
std::string columnName
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:317

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

509  {
510  td.tableName = table_name;
511  td.nColumns = column_count;
512  td.isView = false;
513  td.fragmenter = nullptr;
519 }
std::string tableName
#define DEFAULT_MAX_CHUNK_SIZE
#define DEFAULT_PAGE_SIZE
Definition: FileMgr.h:47
#define DEFAULT_MAX_ROWS
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
#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 640 of file DdlUtils.cpp.

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

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

642  {
643  CHECK(whitelisted_paths.empty());
644  rapidjson::Document whitelisted_root_paths;
645  whitelisted_root_paths.Parse(config_value);
646  if (!whitelisted_root_paths.IsArray()) {
647  throw std::runtime_error{get_malformed_config_error_message(config_key)};
648  }
649  for (const auto& root_path : whitelisted_root_paths.GetArray()) {
650  if (!root_path.IsString()) {
651  throw std::runtime_error{get_malformed_config_error_message(config_key)};
652  }
653  if (!boost::filesystem::exists(root_path.GetString())) {
654  throw std::runtime_error{"Whitelisted root path \"" +
655  std::string{root_path.GetString()} + "\" does not exist."};
656  }
657  whitelisted_paths.emplace_back(
658  boost::filesystem::canonical(root_path.GetString()).string());
659  }
660  LOG(INFO) << config_key << " " << shared::printContainer(whitelisted_paths);
661 }
#define LOG(tag)
Definition: Logger.h:188
std::string get_malformed_config_error_message(const std::string &config_key)
Definition: DdlUtils.cpp:568
#define CHECK(condition)
Definition: Logger.h:197
PrintContainer< CONTAINER > printContainer(CONTAINER &container)
Definition: misc.h:64

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

References FOREIGN_TABLE, TABLE, and VIEW.

555  {
556  if (table_type == ddl_utils::TableType::TABLE) {
557  return "Table";
558  }
559  if (table_type == ddl_utils::TableType::FOREIGN_TABLE) {
560  return "ForeignTable";
561  }
562  if (table_type == ddl_utils::TableType::VIEW) {
563  return "View";
564  }
565  throw std::runtime_error{"Unexpected table type"};
566 }
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 613 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(), foreign_storage::ParquetDataWrapper::validateFilePath(), and foreign_storage::CsvDataWrapper::validateFilePath().

615  {
616  // Reject any punctuation characters except for a few safe ones.
617  // Some punctuation characters present a security risk when passed
618  // to subprocesses. Don't change this without a security review.
619  static const std::string safe_punctuation{"./_+-=:~"};
620  for (const auto& ch : file_path) {
621  if (std::ispunct(ch) && safe_punctuation.find(ch) == std::string::npos &&
622  !(allow_wildcards && ch == '*')) {
623  throw std::runtime_error(std::string("Punctuation \"") + ch +
624  "\" is not allowed in file path: " + file_path);
625  }
626  }
627 
628  // Enforce our whitelist and blacklist for file paths.
629  const auto& expanded_file_paths =
630  get_expanded_file_paths(file_path, data_transfer_type);
631  for (const auto& path : expanded_file_paths) {
632  if (FilePathBlacklist::isBlacklistedPath(path)) {
633  throw std::runtime_error{"Access to file or directory path \"" + file_path +
634  "\" is not allowed."};
635  }
636  }
637  FilePathWhitelist::validateWhitelistedFilePath(expanded_file_paths, data_transfer_type);
638 }
std::vector< std::string > get_expanded_file_paths(const std::string &file_path, const DataTransferType data_transfer_type)
Definition: DdlUtils.cpp:586

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

468  {
469  if (cd.columnType.is_string_array() &&
471  throw std::runtime_error(
472  cd.columnName +
473  ": Array of strings must be dictionary encoded. Specify ENCODING DICT");
474  }
475 
476  if (column_type->get_is_array()) {
477  int s = -1;
478  auto array_size = column_type->get_array_size();
479  if (array_size > 0) {
480  auto sti = cd.columnType.get_elem_type();
481  s = array_size * sti.get_size();
482  if (s <= 0) {
483  throw std::runtime_error(cd.columnName + ": Unexpected fixed length array size");
484  }
485  }
486  cd.columnType.set_size(s);
487 
488  } else {
490  }
491 }
void set_size(int s)
Definition: sqltypes.h:409
HOST DEVICE int get_size() const
Definition: sqltypes.h:321
void set_fixed_size()
Definition: sqltypes.h:410
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:319
SQLTypeInfo columnType
bool is_string_array() const
Definition: sqltypes.h:479
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:697
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 378 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().

378  {
379  if (!cd.columnType.is_geometry() || cd.columnType.get_output_srid() != 4326) {
380  throw std::runtime_error(
381  cd.columnName + ": COMPRESSED encoding is only supported on WGS84 geo columns.");
382  }
383  int comp_param;
384  if (encoding_size == 0) {
385  comp_param = 32; // default to 32-bits
386  } else {
387  comp_param = encoding_size;
388  }
389  if (comp_param != 32) {
390  throw std::runtime_error(cd.columnName +
391  ": only 32-bit COMPRESSED geo encoding is supported");
392  }
393  // encoding longitude/latitude as integers
395  cd.columnType.set_comp_param(comp_param);
396 }
void set_compression(EncodingType c)
Definition: sqltypes.h:411
void set_comp_param(int p)
Definition: sqltypes.h:412
bool is_geometry() const
Definition: sqltypes.h:490
SQLTypeInfo columnType
std::string columnName
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:317

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

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

Referenced by validate_and_set_encoding().

398  {
399  // days encoding for dates
400  if (cd.columnType.get_type() != kDATE) {
401  throw std::runtime_error(cd.columnName +
402  ": Days encoding is only supported for DATE columns.");
403  }
404  if (encoding_size != 32 && encoding_size != 16) {
405  throw std::runtime_error(cd.columnName +
406  ": Compression parameter for Days encoding on "
407  "DATE must be 16 or 32.");
408  }
410  cd.columnType.set_comp_param((encoding_size == 16) ? 16 : 0);
411 }
void set_compression(EncodingType c)
Definition: sqltypes.h:411
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:311
void set_comp_param(int p)
Definition: sqltypes.h:412
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 324 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().

324  {
325  if (!cd.columnType.is_string() && !cd.columnType.is_string_array()) {
326  throw std::runtime_error(
327  cd.columnName +
328  ": Dictionary encoding is only supported on string or string array columns.");
329  }
330  int comp_param;
331  if (encoding_size == 0) {
332  comp_param = 32; // default to 32-bits
333  } else {
334  comp_param = encoding_size;
335  }
336  if (cd.columnType.is_string_array() && comp_param != 32) {
337  throw std::runtime_error(cd.columnName +
338  ": Compression parameter for string arrays must be 32");
339  }
340  if (comp_param != 8 && comp_param != 16 && comp_param != 32) {
341  throw std::runtime_error(
342  cd.columnName +
343  ": Compression parameter for Dictionary encoding must be 8 or 16 or 32.");
344  }
345  // dictionary encoding
347  cd.columnType.set_comp_param(comp_param);
348 }
void set_compression(EncodingType c)
Definition: sqltypes.h:411
void set_comp_param(int p)
Definition: sqltypes.h:412
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:478
bool is_string_array() const
Definition: sqltypes.h:479
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 413 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().

415  {
416  if (encoding == nullptr) {
418  } else {
419  const std::string& comp = *encoding->get_encoding_name();
420  if (boost::iequals(comp, "fixed")) {
421  validate_and_set_fixed_encoding(cd, encoding->get_encoding_param(), column_type);
422  } else if (boost::iequals(comp, "rl")) {
423  // run length encoding
426  // throw std::runtime_error("RL(Run Length) encoding not supported yet.");
427  } else if (boost::iequals(comp, "diff")) {
428  // differential encoding
431  // throw std::runtime_error("DIFF(differential) encoding not supported yet.");
432  } else if (boost::iequals(comp, "dict")) {
433  validate_and_set_dictionary_encoding(cd, encoding->get_encoding_param());
434  } else if (boost::iequals(comp, "NONE")) {
436  } else if (boost::iequals(comp, "sparse")) {
437  validate_and_set_sparse_encoding(cd, encoding->get_encoding_param());
438  } else if (boost::iequals(comp, "compressed")) {
439  validate_and_set_compressed_encoding(cd, encoding->get_encoding_param());
440  } else if (boost::iequals(comp, "days")) {
441  validate_and_set_date_encoding(cd, encoding->get_encoding_param());
442  } else {
443  throw std::runtime_error(cd.columnName + ": Invalid column compression scheme " +
444  comp);
445  }
446  }
447 }
void set_compression(EncodingType c)
Definition: sqltypes.h:411
void validate_and_set_sparse_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:361
void validate_and_set_dictionary_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:324
void validate_and_set_none_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:350
void set_default_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:210
void set_comp_param(int p)
Definition: sqltypes.h:412
void validate_and_set_compressed_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:378
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:398
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, 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  }
246 
247  if (!IS_INTEGER(type) && !is_datetime(type) &&
248  !(type == kDECIMAL || type == kNUMERIC)) {
249  throw std::runtime_error(
250  cd.columnName +
251  ": Fixed encoding is only supported for integer or time columns.");
252  }
253 
254  switch (type) {
255  case kSMALLINT:
256  if (encoding_size != 8) {
257  throw std::runtime_error(
258  cd.columnName +
259  ": Compression parameter for Fixed encoding on SMALLINT must be 8.");
260  }
261  break;
262  case kINT:
263  if (encoding_size != 8 && encoding_size != 16) {
264  throw std::runtime_error(
265  cd.columnName +
266  ": Compression parameter for Fixed encoding on INTEGER must be 8 or 16.");
267  }
268  break;
269  case kBIGINT:
270  if (encoding_size != 8 && encoding_size != 16 && encoding_size != 32) {
271  throw std::runtime_error(cd.columnName +
272  ": Compression parameter for Fixed encoding on "
273  "BIGINT must be 8 or 16 or 32.");
274  }
275  break;
276  case kTIMESTAMP:
277  case kTIME:
278  if (encoding_size != 32) {
279  throw std::runtime_error(cd.columnName +
280  ": Compression parameter for Fixed encoding on "
281  "TIME or TIMESTAMP must be 32.");
282  } else if (cd.columnType.is_high_precision_timestamp()) {
283  throw std::runtime_error("Fixed encoding is not supported for TIMESTAMP(3|6|9).");
284  }
285  break;
286  case kDECIMAL:
287  case kNUMERIC:
288  if (encoding_size != 32 && encoding_size != 16) {
289  throw std::runtime_error(cd.columnName +
290  ": Compression parameter for Fixed encoding on "
291  "DECIMAL must be 16 or 32.");
292  }
293 
294  if (encoding_size == 32 && cd.columnType.get_precision() > 9) {
295  throw std::runtime_error(cd.columnName +
296  ": Precision too high for Fixed(32) encoding, max 9.");
297  }
298 
299  if (encoding_size == 16 && cd.columnType.get_precision() > 4) {
300  throw std::runtime_error(cd.columnName +
301  ": Precision too high for Fixed(16) encoding, max 4.");
302  }
303  break;
304  case kDATE:
305  if (encoding_size != 32 && encoding_size != 16) {
306  throw std::runtime_error(cd.columnName +
307  ": Compression parameter for Fixed encoding on "
308  "DATE must be 16 or 32.");
309  }
310  break;
311  default:
312  throw std::runtime_error(cd.columnName + ": Cannot apply FIXED encoding to " +
313  column_type->to_string());
314  }
315  if (type == kDATE) {
317  cd.columnType.set_comp_param(16);
318  } else {
320  cd.columnType.set_comp_param(encoding_size);
321  }
322 }
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:312
void set_compression(EncodingType c)
Definition: sqltypes.h:411
Definition: sqltypes.h:48
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:311
int get_precision() const
Definition: sqltypes.h:314
void set_comp_param(int p)
Definition: sqltypes.h:412
Definition: sqltypes.h:52
#define IS_INTEGER(T)
Definition: sqltypes.h:236
bool is_high_precision_timestamp() const
Definition: sqltypes.h:717
Definition: sqltypes.h:44
SQLTypeInfo columnType
std::string columnName
constexpr auto is_datetime(SQLTypes type)
Definition: sqltypes.h:254

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

350  {
351  if (!cd.columnType.is_string() && !cd.columnType.is_string_array() &&
352  !cd.columnType.is_geometry()) {
353  throw std::runtime_error(
354  cd.columnName +
355  ": None encoding is only supported on string, string array, or geo columns.");
356  }
359 }
void set_compression(EncodingType c)
Definition: sqltypes.h:411
void set_comp_param(int p)
Definition: sqltypes.h:412
bool is_geometry() const
Definition: sqltypes.h:490
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:478
bool is_string_array() const
Definition: sqltypes.h:479
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 361 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().

361  {
362  // sparse column encoding with mostly NULL values
363  if (cd.columnType.get_notnull()) {
364  throw std::runtime_error(cd.columnName +
365  ": Cannot do sparse column encoding on a NOT NULL column.");
366  }
367  if (encoding_size == 0 || encoding_size % 8 != 0 || encoding_size > 48) {
368  throw std::runtime_error(
369  cd.columnName +
370  "Must specify number of bits as 8, 16, 24, 32 or 48 as the parameter to "
371  "sparse-column encoding.");
372  }
374  cd.columnType.set_comp_param(encoding_size);
375  // throw std::runtime_error("SPARSE encoding not supported yet.");
376 }
void set_compression(EncodingType c)
Definition: sqltypes.h:411
void set_comp_param(int p)
Definition: sqltypes.h:412
SQLTypeInfo columnType
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:318
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 449 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().

449  {
450  column_type->check_type();
451 
452  if (column_type->get_is_array()) {
454  cd.columnType.set_subtype(column_type->get_type());
455  } else {
456  cd.columnType.set_type(column_type->get_type());
457  }
458  if (IS_GEO(column_type->get_type())) {
459  cd.columnType.set_subtype(static_cast<SQLTypes>(column_type->get_param1()));
460  cd.columnType.set_input_srid(column_type->get_param2());
461  cd.columnType.set_output_srid(column_type->get_param2());
462  } else {
463  cd.columnType.set_dimension(column_type->get_param1());
464  cd.columnType.set_scale(column_type->get_param2());
465  }
466 }
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:402
void set_input_srid(int d)
Definition: sqltypes.h:405
void set_scale(int s)
Definition: sqltypes.h:406
void set_output_srid(int s)
Definition: sqltypes.h:407
void set_dimension(int d)
Definition: sqltypes.h:403
SQLTypeInfo columnType
#define IS_GEO(T)
Definition: sqltypes.h:242
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:401

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

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

575  {
576  boost::filesystem::path canonical_file_path = boost::filesystem::canonical(file_path);
577  for (const auto& root_path : whitelisted_root_paths) {
578  if (boost::istarts_with(canonical_file_path.string(), root_path)) {
579  return;
580  }
581  }
582  throw std::runtime_error{"File or directory path \"" + file_path +
583  "\" is not whitelisted."};
584 }

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

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

522  {
523  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
524  const auto insert_it = upper_column_names.insert(upper_column_name);
525  if (!insert_it.second) {
526  throw std::runtime_error("Column '" + column_name + "' defined more than once");
527  }
528 }

+ Here is the caller graph for this function:

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

Definition at line 530 of file DdlUtils.cpp.

References reserved_keywords.

Referenced by CreateForeignTableCommand::setColumnDetails().

530  {
531  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
532  if (reserved_keywords.find(upper_column_name) != reserved_keywords.end()) {
533  throw std::runtime_error("Cannot create column with reserved keyword '" +
534  column_name + "'");
535  }
536 }
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 538 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().

540  {
541  if (td->isView) {
542  if (expected_table_type != TableType::VIEW) {
543  throw std::runtime_error(td->tableName + " is a view. Use " + command + " VIEW.");
544  }
545  } else if (td->storageType == StorageType::FOREIGN_TABLE) {
546  if (expected_table_type != TableType::FOREIGN_TABLE) {
547  throw std::runtime_error(td->tableName + " is a foreign table. Use " + command +
548  " FOREIGN TABLE.");
549  }
550  } else if (expected_table_type != TableType::TABLE) {
551  throw std::runtime_error(td->tableName + " is a table. Use " + command + " TABLE.");
552  }
553 }
std::string tableName
std::string storageType
static constexpr char const * FOREIGN_TABLE

+ Here is the caller graph for this function: