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

Namespaces

 anonymous_namespace{DdlUtils.cpp}
 

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 validate_and_set_default_value (ColumnDescriptor &cd, const std::string *default_value, bool not_null)
 
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 761 of file DdlUtils.cpp.

References IMPORT, and shared::local_glob_filter_sort_files().

Referenced by validate_allowed_file_path().

763  {
764  std::vector<std::string> file_paths;
765  if (data_transfer_type == DataTransferType::IMPORT) {
766  file_paths = shared::local_glob_filter_sort_files(file_path, {});
767  } else {
768  std::string path;
769  if (!boost::filesystem::exists(file_path)) {
770  // For exports, it is possible to provide a path to a new (nonexistent) file. In
771  // this case, validate using the parent path.
772  path = boost::filesystem::path(file_path).parent_path().string();
773  if (!boost::filesystem::exists(path)) {
774  throw std::runtime_error{"File or directory \"" + file_path +
775  "\" does not exist."};
776  }
777  } else {
778  path = file_path;
779  }
780  file_paths = {path};
781  }
782  return file_paths;
783 }
std::vector< std::string > local_glob_filter_sort_files(const std::string &file_path, const FilePathOptions &options, const bool recurse)

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

Referenced by set_whitelisted_paths().

738  {
739  return "Configuration value for \"" + config_key +
740  "\" is malformed. Value should be a list of paths with format: [ "
741  "\"root-path-1\", \"root-path-2\", ... ]";
742 }

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

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

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

666  {
667  cd.columnName = column_name;
668  validate_and_set_type(cd, column_type);
669  cd.columnType.set_notnull(not_null);
670  validate_and_set_encoding(cd, encoding, column_type);
671  validate_and_set_array_size(cd, column_type);
672  cd.isSystemCol = false;
673  cd.isVirtualCol = false;
674  validate_and_set_default_value(cd, default_value, not_null);
675 }
void validate_and_set_array_size(ColumnDescriptor &cd, const SqlType *column_type)
Definition: DdlUtils.cpp:496
void validate_and_set_encoding(ColumnDescriptor &cd, const Encoding *encoding, const SqlType *column_type)
Definition: DdlUtils.cpp:437
void set_notnull(bool n)
Definition: sqltypes.h:500
void validate_and_set_default_value(ColumnDescriptor &cd, const std::string *default_value, bool not_null)
Definition: DdlUtils.cpp:640
SQLTypeInfo columnType
std::string columnName
void validate_and_set_type(ColumnDescriptor &cd, SqlType *column_type)
Definition: DdlUtils.cpp:473

+ 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 216 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, sql_constants::kMaxNumericPrecision, SQLTypeInfo::set_comp_param(), SQLTypeInfo::set_compression(), and to_string().

Referenced by validate_and_set_encoding().

216  {
217  // Change default TEXT column behaviour to be DICT encoded
218  if (cd.columnType.is_string() || cd.columnType.is_string_array()) {
219  // default to 32-bits
221  cd.columnType.set_comp_param(32);
222  } else if (cd.columnType.is_decimal() && cd.columnType.get_precision() <= 4) {
224  cd.columnType.set_comp_param(16);
225  } else if (cd.columnType.is_decimal() && cd.columnType.get_precision() <= 9) {
227  cd.columnType.set_comp_param(32);
228  } else if (cd.columnType.is_decimal() &&
230  throw std::runtime_error(cd.columnName + ": Precision too high, max " +
232  } else if (cd.columnType.is_geometry() && cd.columnType.get_output_srid() == 4326) {
233  // default to GEOINT 32-bits
235  cd.columnType.set_comp_param(32);
237  // Days encoding for DATE
240  } else {
243  }
244 }
void set_compression(EncodingType c)
Definition: sqltypes.h:504
static constexpr int32_t kMaxNumericPrecision
Definition: sqltypes.h:48
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
std::string to_string(char const *&&v)
bool g_use_date_in_days_default_encoding
Definition: DdlUtils.cpp:35
int get_precision() const
Definition: sqltypes.h:384
void set_comp_param(int p)
Definition: sqltypes.h:505
Definition: sqltypes.h:70
bool is_geometry() const
Definition: sqltypes.h:592
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:580
bool is_string_array() const
Definition: sqltypes.h:581
bool is_decimal() const
Definition: sqltypes.h:583
std::string columnName
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:387

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

679  {
680  td.tableName = table_name;
681  td.nColumns = column_count;
682  td.isView = false;
683  td.fragmenter = nullptr;
689 }
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 818 of file DdlUtils.cpp.

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

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

820  {
821  rapidjson::Document whitelisted_root_paths;
822  whitelisted_root_paths.Parse(config_value);
823  if (!whitelisted_root_paths.IsArray()) {
824  throw std::runtime_error{get_malformed_config_error_message(config_key)};
825  }
826  for (const auto& root_path : whitelisted_root_paths.GetArray()) {
827  if (!root_path.IsString()) {
828  throw std::runtime_error{get_malformed_config_error_message(config_key)};
829  }
830  if (!boost::filesystem::exists(root_path.GetString())) {
831  throw std::runtime_error{"Whitelisted root path \"" +
832  std::string{root_path.GetString()} + "\" does not exist."};
833  }
834  whitelisted_paths.emplace_back(
835  boost::filesystem::canonical(root_path.GetString()).string());
836  }
837  LOG(INFO) << "Parsed " << config_key << ": "
838  << shared::printContainer(whitelisted_paths);
839 }
#define LOG(tag)
Definition: Logger.h:285
std::string get_malformed_config_error_message(const std::string &config_key)
Definition: DdlUtils.cpp:738
PrintContainer< CONTAINER > printContainer(CONTAINER &container)
Definition: misc.h:107

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

References FOREIGN_TABLE, TABLE, and VIEW.

725  {
726  if (table_type == ddl_utils::TableType::TABLE) {
727  return "Table";
728  }
729  if (table_type == ddl_utils::TableType::FOREIGN_TABLE) {
730  return "ForeignTable";
731  }
732  if (table_type == ddl_utils::TableType::VIEW) {
733  return "View";
734  }
735  throw std::runtime_error{"Unexpected table type"};
736 }
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 785 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().

787  {
788  // Reject any punctuation characters except for a few safe ones.
789  // Some punctuation characters present a security risk when passed
790  // to subprocesses. Don't change this without a security review.
791  static const std::string safe_punctuation{"./_+-=:~"};
792  for (const auto& ch : file_path) {
793  if (std::ispunct(ch) && safe_punctuation.find(ch) == std::string::npos &&
794  !(allow_wildcards && ch == '*')) {
795  throw std::runtime_error(std::string("Punctuation \"") + ch +
796  "\" is not allowed in file path: " + file_path);
797  }
798  }
799 
800  // Enforce our whitelist and blacklist for file paths.
801  const auto& expanded_file_paths =
802  get_expanded_file_paths(file_path, data_transfer_type);
803  for (const auto& path : expanded_file_paths) {
804  if (FilePathBlacklist::isBlacklistedPath(path)) {
805  const auto& canonical_file_path = boost::filesystem::canonical(file_path);
806  if (canonical_file_path == boost::filesystem::absolute(file_path)) {
807  throw std::runtime_error{"Access to file or directory path \"" + file_path +
808  "\" is not allowed."};
809  }
810  throw std::runtime_error{"Access to file or directory path \"" + file_path +
811  "\" (resolved to \"" + canonical_file_path.string() +
812  "\") is not allowed."};
813  }
814  }
815  FilePathWhitelist::validateWhitelistedFilePath(expanded_file_paths, data_transfer_type);
816 }
std::vector< std::string > get_expanded_file_paths(const std::string &file_path, const DataTransferType data_transfer_type)
Definition: DdlUtils.cpp:761

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

496  {
497  if (cd.columnType.is_string_array() &&
499  throw std::runtime_error(
500  cd.columnName +
501  ": Array of strings must be dictionary encoded. Specify ENCODING DICT");
502  }
503 
504  if (column_type->get_is_array()) {
505  int s = -1;
506  auto array_size = column_type->get_array_size();
507  if (array_size > 0) {
508  auto sti = cd.columnType.get_elem_type();
509  s = array_size * sti.get_size();
510  if (s <= 0) {
511  throw std::runtime_error(cd.columnName + ": Unexpected fixed length array size");
512  }
513  }
514  cd.columnType.set_size(s);
515 
516  } else {
518  }
519 }
void set_size(int s)
Definition: sqltypes.h:501
HOST DEVICE int get_size() const
Definition: sqltypes.h:393
void set_fixed_size()
Definition: sqltypes.h:502
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:389
SQLTypeInfo columnType
bool is_string_array() const
Definition: sqltypes.h:581
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:963
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 398 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().

398  {
399  if (!cd.columnType.is_geometry() || cd.columnType.get_output_srid() != 4326) {
400  throw std::runtime_error(
401  cd.columnName + ": COMPRESSED encoding is only supported on WGS84 geo columns.");
402  }
403  int comp_param;
404  if (encoding_size == 0) {
405  comp_param = 32; // default to 32-bits
406  } else {
407  comp_param = encoding_size;
408  }
409  if (comp_param != 32) {
410  throw std::runtime_error(cd.columnName +
411  ": only 32-bit COMPRESSED geo encoding is supported");
412  }
413  // encoding longitude/latitude as integers
415  cd.columnType.set_comp_param(comp_param);
416 }
void set_compression(EncodingType c)
Definition: sqltypes.h:504
void set_comp_param(int p)
Definition: sqltypes.h:505
bool is_geometry() const
Definition: sqltypes.h:592
SQLTypeInfo columnType
std::string columnName
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:387

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

418  {
419  // days encoding for dates
420  if (cd.columnType.get_type() == kARRAY && cd.columnType.get_subtype() == kDATE) {
421  throw std::runtime_error(cd.columnName +
422  ": Cannot apply days encoding to date array.");
423  }
424  if (cd.columnType.get_type() != kDATE) {
425  throw std::runtime_error(cd.columnName +
426  ": Days encoding is only supported for DATE columns.");
427  }
428  if (encoding_size != 32 && encoding_size != 16) {
429  throw std::runtime_error(cd.columnName +
430  ": Compression parameter for Days encoding on "
431  "DATE must be 16 or 32.");
432  }
434  cd.columnType.set_comp_param((encoding_size == 16) ? 16 : 0);
435 }
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:382
void set_compression(EncodingType c)
Definition: sqltypes.h:504
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
void set_comp_param(int p)
Definition: sqltypes.h:505
Definition: sqltypes.h:70
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_default_value ( ColumnDescriptor cd,
const std::string *  default_value,
bool  not_null 
)

Definition at line 640 of file DdlUtils.cpp.

References ColumnDescriptor::columnName, ColumnDescriptor::columnType, ColumnDescriptor::default_value, SQLTypeInfo::is_geometry(), to_upper(), and ddl_utils::anonymous_namespace{DdlUtils.cpp}::validate_literal().

Referenced by set_column_descriptor().

642  {
643  bool is_null_literal =
644  default_value && ((to_upper(*default_value) == "NULL") ||
645  (cd.columnType.is_geometry() && default_value->empty()));
646  if (not_null && (is_null_literal)) {
647  throw std::runtime_error(cd.columnName +
648  ": cannot set default value to NULL for "
649  "NOT NULL column");
650  }
651  if (!default_value || is_null_literal) {
652  cd.default_value = std::nullopt;
653  return;
654  }
655  const auto& column_type = cd.columnType;
656  const auto& val = *default_value;
657  validate_literal(val, column_type, cd.columnName);
658  cd.default_value = std::make_optional(*default_value);
659 }
void validate_literal(const std::string &val, SQLTypeInfo column_type, const std::string &column_name)
Definition: DdlUtils.cpp:523
std::string to_upper(const std::string &str)
std::optional< std::string > default_value
bool is_geometry() const
Definition: sqltypes.h:592
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 344 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().

344  {
345  if (!cd.columnType.is_string() && !cd.columnType.is_string_array()) {
346  throw std::runtime_error(
347  cd.columnName +
348  ": Dictionary encoding is only supported on string or string array columns.");
349  }
350  int comp_param;
351  if (encoding_size == 0) {
352  comp_param = 32; // default to 32-bits
353  } else {
354  comp_param = encoding_size;
355  }
356  if (cd.columnType.is_string_array() && comp_param != 32) {
357  throw std::runtime_error(cd.columnName +
358  ": Compression parameter for string arrays must be 32");
359  }
360  if (comp_param != 8 && comp_param != 16 && comp_param != 32) {
361  throw std::runtime_error(
362  cd.columnName +
363  ": Compression parameter for Dictionary encoding must be 8 or 16 or 32.");
364  }
365  // dictionary encoding
367  cd.columnType.set_comp_param(comp_param);
368 }
void set_compression(EncodingType c)
Definition: sqltypes.h:504
void set_comp_param(int p)
Definition: sqltypes.h:505
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:580
bool is_string_array() const
Definition: sqltypes.h:581
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 437 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().

439  {
440  if (encoding == nullptr) {
442  } else {
443  const std::string& comp = *encoding->get_encoding_name();
444  if (boost::iequals(comp, "fixed")) {
445  validate_and_set_fixed_encoding(cd, encoding->get_encoding_param(), column_type);
446  } else if (boost::iequals(comp, "rl")) {
447  // run length encoding
450  // throw std::runtime_error("RL(Run Length) encoding not supported yet.");
451  } else if (boost::iequals(comp, "diff")) {
452  // differential encoding
455  // throw std::runtime_error("DIFF(differential) encoding not supported yet.");
456  } else if (boost::iequals(comp, "dict")) {
457  validate_and_set_dictionary_encoding(cd, encoding->get_encoding_param());
458  } else if (boost::iequals(comp, "NONE")) {
460  } else if (boost::iequals(comp, "sparse")) {
461  validate_and_set_sparse_encoding(cd, encoding->get_encoding_param());
462  } else if (boost::iequals(comp, "compressed")) {
463  validate_and_set_compressed_encoding(cd, encoding->get_encoding_param());
464  } else if (boost::iequals(comp, "days")) {
465  validate_and_set_date_encoding(cd, encoding->get_encoding_param());
466  } else {
467  throw std::runtime_error(cd.columnName + ": Invalid column compression scheme " +
468  comp);
469  }
470  }
471 }
void set_compression(EncodingType c)
Definition: sqltypes.h:504
void validate_and_set_sparse_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:381
void validate_and_set_dictionary_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:344
void validate_and_set_none_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:370
void set_default_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:216
void set_comp_param(int p)
Definition: sqltypes.h:505
void validate_and_set_compressed_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:398
void validate_and_set_fixed_encoding(ColumnDescriptor &cd, int encoding_size, const SqlType *column_type)
Definition: DdlUtils.cpp:246
void validate_and_set_date_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:418
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 246 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().

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

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

370  {
371  if (!cd.columnType.is_string() && !cd.columnType.is_string_array() &&
372  !cd.columnType.is_geometry()) {
373  throw std::runtime_error(
374  cd.columnName +
375  ": None encoding is only supported on string, string array, or geo columns.");
376  }
379 }
void set_compression(EncodingType c)
Definition: sqltypes.h:504
void set_comp_param(int p)
Definition: sqltypes.h:505
bool is_geometry() const
Definition: sqltypes.h:592
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:580
bool is_string_array() const
Definition: sqltypes.h:581
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 381 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().

381  {
382  // sparse column encoding with mostly NULL values
383  if (cd.columnType.get_notnull()) {
384  throw std::runtime_error(cd.columnName +
385  ": Cannot do sparse column encoding on a NOT NULL column.");
386  }
387  if (encoding_size == 0 || encoding_size % 8 != 0 || encoding_size > 48) {
388  throw std::runtime_error(
389  cd.columnName +
390  "Must specify number of bits as 8, 16, 24, 32 or 48 as the parameter to "
391  "sparse-column encoding.");
392  }
394  cd.columnType.set_comp_param(encoding_size);
395  // throw std::runtime_error("SPARSE encoding not supported yet.");
396 }
void set_compression(EncodingType c)
Definition: sqltypes.h:504
void set_comp_param(int p)
Definition: sqltypes.h:505
SQLTypeInfo columnType
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:388
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 473 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, kGEOMETRY, 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().

473  {
474  column_type->check_type();
475 
476  if (column_type->get_type() == kGEOMETRY) {
477  throw std::runtime_error("Unsupported type \"GEOMETRY\" specified.");
478  }
479 
480  if (column_type->get_is_array()) {
482  cd.columnType.set_subtype(column_type->get_type());
483  } else {
484  cd.columnType.set_type(column_type->get_type());
485  }
486  if (IS_GEO(column_type->get_type())) {
487  cd.columnType.set_subtype(static_cast<SQLTypes>(column_type->get_param1()));
488  cd.columnType.set_input_srid(column_type->get_param2());
489  cd.columnType.set_output_srid(column_type->get_param2());
490  } else {
491  cd.columnType.set_dimension(column_type->get_param1());
492  cd.columnType.set_scale(column_type->get_param2());
493  }
494 }
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:494
void set_input_srid(int d)
Definition: sqltypes.h:497
void set_scale(int s)
Definition: sqltypes.h:498
void set_output_srid(int s)
Definition: sqltypes.h:499
void set_dimension(int d)
Definition: sqltypes.h:495
SQLTypeInfo columnType
#define IS_GEO(T)
Definition: sqltypes.h:300
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:493

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

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

745  {
746  const auto& canonical_file_path = boost::filesystem::canonical(file_path);
747  for (const auto& root_path : whitelisted_root_paths) {
748  if (boost::istarts_with(canonical_file_path.string(), root_path)) {
749  return;
750  }
751  }
752  if (canonical_file_path == boost::filesystem::absolute(file_path)) {
753  throw std::runtime_error{"File or directory path \"" + file_path +
754  "\" is not whitelisted."};
755  }
756  throw std::runtime_error{"File or directory path \"" + file_path +
757  "\" (resolved to \"" + canonical_file_path.string() +
758  "\") is not whitelisted."};
759 }

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

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

692  {
693  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
694  const auto insert_it = upper_column_names.insert(upper_column_name);
695  if (!insert_it.second) {
696  throw std::runtime_error("Column '" + column_name + "' defined more than once");
697  }
698 }

+ Here is the caller graph for this function:

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

Definition at line 700 of file DdlUtils.cpp.

References reserved_keywords.

Referenced by CreateForeignTableCommand::setColumnDetails().

700  {
701  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
702  if (reserved_keywords.find(upper_column_name) != reserved_keywords.end()) {
703  throw std::runtime_error("Cannot create column with reserved keyword '" +
704  column_name + "'");
705  }
706 }
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 708 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::RenameColumnStmt::execute(), Parser::DropColumnStmt::execute(), and Parser::DropViewStmt::execute().

710  {
711  if (td->isView) {
712  if (expected_table_type != TableType::VIEW) {
713  throw std::runtime_error(td->tableName + " is a view. Use " + command + " VIEW.");
714  }
715  } else if (td->storageType == StorageType::FOREIGN_TABLE) {
716  if (expected_table_type != TableType::FOREIGN_TABLE) {
717  throw std::runtime_error(td->tableName + " is a foreign table. Use " + command +
718  " FOREIGN TABLE.");
719  }
720  } else if (expected_table_type != TableType::TABLE) {
721  throw std::runtime_error(td->tableName + " is a table. Use " + command + " TABLE.");
722  }
723 }
std::string tableName
std::string storageType
static constexpr char const * FOREIGN_TABLE

+ Here is the caller graph for this function: