OmniSciDB  6686921089
 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 745 of file DdlUtils.cpp.

References IMPORT, and shared::local_glob_filter_sort_files().

Referenced by validate_allowed_file_path().

747  {
748  std::vector<std::string> file_paths;
749  if (data_transfer_type == DataTransferType::IMPORT) {
751  file_path, std::nullopt, std::nullopt, std::nullopt);
752  } else {
753  std::string path;
754  if (!boost::filesystem::exists(file_path)) {
755  // For exports, it is possible to provide a path to a new (nonexistent) file. In
756  // this case, validate using the parent path.
757  path = boost::filesystem::path(file_path).parent_path().string();
758  if (!boost::filesystem::exists(path)) {
759  throw std::runtime_error{"File or directory \"" + file_path +
760  "\" does not exist."};
761  }
762  } else {
763  path = file_path;
764  }
765  file_paths = {path};
766  }
767  return file_paths;
768 }
std::vector< std::string > local_glob_filter_sort_files(const std::string &file_path, const std::optional< std::string > &filter_regex, const std::optional< std::string > &sort_by, const std::optional< std::string > &sort_regex)

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

Referenced by set_whitelisted_paths().

722  {
723  return "Configuration value for \"" + config_key +
724  "\" is malformed. Value should be a list of paths with format: [ "
725  "\"root-path-1\", \"root-path-2\", ... ]";
726 }

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

650  {
651  cd.columnName = column_name;
652  validate_and_set_type(cd, column_type);
653  cd.columnType.set_notnull(not_null);
654  validate_and_set_encoding(cd, encoding, column_type);
655  validate_and_set_array_size(cd, column_type);
656  cd.isSystemCol = false;
657  cd.isVirtualCol = false;
658  validate_and_set_default_value(cd, default_value, not_null);
659 }
void validate_and_set_array_size(ColumnDescriptor &cd, const SqlType *column_type)
Definition: DdlUtils.cpp:486
void validate_and_set_encoding(ColumnDescriptor &cd, const Encoding *encoding, const SqlType *column_type)
Definition: DdlUtils.cpp:431
void set_notnull(bool n)
Definition: sqltypes.h:426
void validate_and_set_default_value(ColumnDescriptor &cd, const std::string *default_value, bool not_null)
Definition: DdlUtils.cpp:624
SQLTypeInfo columnType
std::string columnName
void validate_and_set_type(ColumnDescriptor &cd, SqlType *column_type)
Definition: DdlUtils.cpp:467

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

212  {
213  // Change default TEXT column behaviour to be DICT encoded
214  if (cd.columnType.is_string() || cd.columnType.is_string_array()) {
215  // default to 32-bits
217  cd.columnType.set_comp_param(32);
218  } else if (cd.columnType.is_decimal() && cd.columnType.get_precision() <= 4) {
220  cd.columnType.set_comp_param(16);
221  } else if (cd.columnType.is_decimal() && cd.columnType.get_precision() <= 9) {
223  cd.columnType.set_comp_param(32);
224  } else if (cd.columnType.is_decimal() && cd.columnType.get_precision() > 18) {
225  throw std::runtime_error(cd.columnName + ": Precision too high, max 18.");
226  } else if (cd.columnType.is_geometry() && cd.columnType.get_output_srid() == 4326) {
227  // default to GEOINT 32-bits
229  cd.columnType.set_comp_param(32);
231  // Days encoding for DATE
234  } else {
237  }
238 }
void set_compression(EncodingType c)
Definition: sqltypes.h:429
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
bool g_use_date_in_days_default_encoding
Definition: DdlUtils.cpp:34
int get_precision() const
Definition: sqltypes.h:332
void set_comp_param(int p)
Definition: sqltypes.h:430
Definition: sqltypes.h:53
bool is_geometry() const
Definition: sqltypes.h:521
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:509
bool is_string_array() const
Definition: sqltypes.h:510
bool is_decimal() const
Definition: sqltypes.h:512
std::string columnName
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:335

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

663  {
664  td.tableName = table_name;
665  td.nColumns = column_count;
666  td.isView = false;
667  td.fragmenter = nullptr;
673 }
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 803 of file DdlUtils.cpp.

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

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

805  {
806  rapidjson::Document whitelisted_root_paths;
807  whitelisted_root_paths.Parse(config_value);
808  if (!whitelisted_root_paths.IsArray()) {
809  throw std::runtime_error{get_malformed_config_error_message(config_key)};
810  }
811  for (const auto& root_path : whitelisted_root_paths.GetArray()) {
812  if (!root_path.IsString()) {
813  throw std::runtime_error{get_malformed_config_error_message(config_key)};
814  }
815  if (!boost::filesystem::exists(root_path.GetString())) {
816  throw std::runtime_error{"Whitelisted root path \"" +
817  std::string{root_path.GetString()} + "\" does not exist."};
818  }
819  whitelisted_paths.emplace_back(
820  boost::filesystem::canonical(root_path.GetString()).string());
821  }
822  LOG(INFO) << "Parsed " << config_key << ": "
823  << shared::printContainer(whitelisted_paths);
824 }
#define LOG(tag)
Definition: Logger.h:203
std::string get_malformed_config_error_message(const std::string &config_key)
Definition: DdlUtils.cpp:722
PrintContainer< CONTAINER > printContainer(CONTAINER &container)
Definition: misc.h:105

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

References FOREIGN_TABLE, TABLE, and VIEW.

709  {
710  if (table_type == ddl_utils::TableType::TABLE) {
711  return "Table";
712  }
713  if (table_type == ddl_utils::TableType::FOREIGN_TABLE) {
714  return "ForeignTable";
715  }
716  if (table_type == ddl_utils::TableType::VIEW) {
717  return "View";
718  }
719  throw std::runtime_error{"Unexpected table type"};
720 }
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 770 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().

772  {
773  // Reject any punctuation characters except for a few safe ones.
774  // Some punctuation characters present a security risk when passed
775  // to subprocesses. Don't change this without a security review.
776  static const std::string safe_punctuation{"./_+-=:~"};
777  for (const auto& ch : file_path) {
778  if (std::ispunct(ch) && safe_punctuation.find(ch) == std::string::npos &&
779  !(allow_wildcards && ch == '*')) {
780  throw std::runtime_error(std::string("Punctuation \"") + ch +
781  "\" is not allowed in file path: " + file_path);
782  }
783  }
784 
785  // Enforce our whitelist and blacklist for file paths.
786  const auto& expanded_file_paths =
787  get_expanded_file_paths(file_path, data_transfer_type);
788  for (const auto& path : expanded_file_paths) {
789  if (FilePathBlacklist::isBlacklistedPath(path)) {
790  const auto& canonical_file_path = boost::filesystem::canonical(file_path);
791  if (canonical_file_path == boost::filesystem::absolute(file_path)) {
792  throw std::runtime_error{"Access to file or directory path \"" + file_path +
793  "\" is not allowed."};
794  }
795  throw std::runtime_error{"Access to file or directory path \"" + file_path +
796  "\" (resolved to \"" + canonical_file_path.string() +
797  "\") is not allowed."};
798  }
799  }
800  FilePathWhitelist::validateWhitelistedFilePath(expanded_file_paths, data_transfer_type);
801 }
std::vector< std::string > get_expanded_file_paths(const std::string &file_path, const DataTransferType data_transfer_type)
Definition: DdlUtils.cpp:745

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

486  {
487  if (cd.columnType.is_string_array() &&
489  throw std::runtime_error(
490  cd.columnName +
491  ": Array of strings must be dictionary encoded. Specify ENCODING DICT");
492  }
493 
494  if (column_type->get_is_array()) {
495  int s = -1;
496  auto array_size = column_type->get_array_size();
497  if (array_size > 0) {
498  auto sti = cd.columnType.get_elem_type();
499  s = array_size * sti.get_size();
500  if (s <= 0) {
501  throw std::runtime_error(cd.columnName + ": Unexpected fixed length array size");
502  }
503  }
504  cd.columnType.set_size(s);
505 
506  } else {
508  }
509 }
void set_size(int s)
Definition: sqltypes.h:427
HOST DEVICE int get_size() const
Definition: sqltypes.h:339
void set_fixed_size()
Definition: sqltypes.h:428
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
SQLTypeInfo columnType
bool is_string_array() const
Definition: sqltypes.h:510
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:850
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 392 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().

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

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

412  {
413  // days encoding for dates
414  if (cd.columnType.get_type() == kARRAY && cd.columnType.get_subtype() == kDATE) {
415  throw std::runtime_error(cd.columnName +
416  ": Cannot apply days encoding to date array.");
417  }
418  if (cd.columnType.get_type() != kDATE) {
419  throw std::runtime_error(cd.columnName +
420  ": Days encoding is only supported for DATE columns.");
421  }
422  if (encoding_size != 32 && encoding_size != 16) {
423  throw std::runtime_error(cd.columnName +
424  ": Compression parameter for Days encoding on "
425  "DATE must be 16 or 32.");
426  }
428  cd.columnType.set_comp_param((encoding_size == 16) ? 16 : 0);
429 }
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:330
void set_compression(EncodingType c)
Definition: sqltypes.h:429
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
void set_comp_param(int p)
Definition: sqltypes.h:430
Definition: sqltypes.h:53
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 624 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().

626  {
627  bool is_null_literal =
628  default_value && ((to_upper(*default_value) == "NULL") ||
629  (cd.columnType.is_geometry() && default_value->empty()));
630  if (not_null && (is_null_literal)) {
631  throw std::runtime_error(cd.columnName +
632  ": cannot set default value to NULL for "
633  "NOT NULL column");
634  }
635  if (!default_value || is_null_literal) {
636  cd.default_value = std::nullopt;
637  return;
638  }
639  const auto& column_type = cd.columnType;
640  const auto& val = *default_value;
641  validate_literal(val, column_type, cd.columnName);
642  cd.default_value = std::make_optional(*default_value);
643 }
void validate_literal(const std::string &val, SQLTypeInfo column_type, const std::string &column_name)
Definition: DdlUtils.cpp:513
std::string to_upper(const std::string &str)
std::optional< std::string > default_value
bool is_geometry() const
Definition: sqltypes.h:521
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 338 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().

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

433  {
434  if (encoding == nullptr) {
436  } else {
437  const std::string& comp = *encoding->get_encoding_name();
438  if (boost::iequals(comp, "fixed")) {
439  validate_and_set_fixed_encoding(cd, encoding->get_encoding_param(), column_type);
440  } else if (boost::iequals(comp, "rl")) {
441  // run length encoding
444  // throw std::runtime_error("RL(Run Length) encoding not supported yet.");
445  } else if (boost::iequals(comp, "diff")) {
446  // differential encoding
449  // throw std::runtime_error("DIFF(differential) encoding not supported yet.");
450  } else if (boost::iequals(comp, "dict")) {
451  validate_and_set_dictionary_encoding(cd, encoding->get_encoding_param());
452  } else if (boost::iequals(comp, "NONE")) {
454  } else if (boost::iequals(comp, "sparse")) {
455  validate_and_set_sparse_encoding(cd, encoding->get_encoding_param());
456  } else if (boost::iequals(comp, "compressed")) {
457  validate_and_set_compressed_encoding(cd, encoding->get_encoding_param());
458  } else if (boost::iequals(comp, "days")) {
459  validate_and_set_date_encoding(cd, encoding->get_encoding_param());
460  } else {
461  throw std::runtime_error(cd.columnName + ": Invalid column compression scheme " +
462  comp);
463  }
464  }
465 }
void set_compression(EncodingType c)
Definition: sqltypes.h:429
void validate_and_set_sparse_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:375
void validate_and_set_dictionary_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:338
void validate_and_set_none_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:364
void set_default_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:212
void set_comp_param(int p)
Definition: sqltypes.h:430
void validate_and_set_compressed_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:392
void validate_and_set_fixed_encoding(ColumnDescriptor &cd, int encoding_size, const SqlType *column_type)
Definition: DdlUtils.cpp:240
void validate_and_set_date_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:412
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 240 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().

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

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

364  {
365  if (!cd.columnType.is_string() && !cd.columnType.is_string_array() &&
366  !cd.columnType.is_geometry()) {
367  throw std::runtime_error(
368  cd.columnName +
369  ": None encoding is only supported on string, string array, or geo columns.");
370  }
373 }
void set_compression(EncodingType c)
Definition: sqltypes.h:429
void set_comp_param(int p)
Definition: sqltypes.h:430
bool is_geometry() const
Definition: sqltypes.h:521
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:509
bool is_string_array() const
Definition: sqltypes.h:510
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 375 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().

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

467  {
468  column_type->check_type();
469 
470  if (column_type->get_is_array()) {
472  cd.columnType.set_subtype(column_type->get_type());
473  } else {
474  cd.columnType.set_type(column_type->get_type());
475  }
476  if (IS_GEO(column_type->get_type())) {
477  cd.columnType.set_subtype(static_cast<SQLTypes>(column_type->get_param1()));
478  cd.columnType.set_input_srid(column_type->get_param2());
479  cd.columnType.set_output_srid(column_type->get_param2());
480  } else {
481  cd.columnType.set_dimension(column_type->get_param1());
482  cd.columnType.set_scale(column_type->get_param2());
483  }
484 }
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:420
void set_input_srid(int d)
Definition: sqltypes.h:423
void set_scale(int s)
Definition: sqltypes.h:424
void set_output_srid(int s)
Definition: sqltypes.h:425
void set_dimension(int d)
Definition: sqltypes.h:421
SQLTypeInfo columnType
#define IS_GEO(T)
Definition: sqltypes.h:251
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:419

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

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

729  {
730  const auto& canonical_file_path = boost::filesystem::canonical(file_path);
731  for (const auto& root_path : whitelisted_root_paths) {
732  if (boost::istarts_with(canonical_file_path.string(), root_path)) {
733  return;
734  }
735  }
736  if (canonical_file_path == boost::filesystem::absolute(file_path)) {
737  throw std::runtime_error{"File or directory path \"" + file_path +
738  "\" is not whitelisted."};
739  }
740  throw std::runtime_error{"File or directory path \"" + file_path +
741  "\" (resolved to \"" + canonical_file_path.string() +
742  "\") is not whitelisted."};
743 }

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

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

676  {
677  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
678  const auto insert_it = upper_column_names.insert(upper_column_name);
679  if (!insert_it.second) {
680  throw std::runtime_error("Column '" + column_name + "' defined more than once");
681  }
682 }

+ Here is the caller graph for this function:

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

Definition at line 684 of file DdlUtils.cpp.

References reserved_keywords.

Referenced by CreateForeignTableCommand::setColumnDetails().

684  {
685  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
686  if (reserved_keywords.find(upper_column_name) != reserved_keywords.end()) {
687  throw std::runtime_error("Cannot create column with reserved keyword '" +
688  column_name + "'");
689  }
690 }
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 692 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().

694  {
695  if (td->isView) {
696  if (expected_table_type != TableType::VIEW) {
697  throw std::runtime_error(td->tableName + " is a view. Use " + command + " VIEW.");
698  }
699  } else if (td->storageType == StorageType::FOREIGN_TABLE) {
700  if (expected_table_type != TableType::FOREIGN_TABLE) {
701  throw std::runtime_error(td->tableName + " is a foreign table. Use " + command +
702  " FOREIGN TABLE.");
703  }
704  } else if (expected_table_type != TableType::TABLE) {
705  throw std::runtime_error(td->tableName + " is a table. Use " + command + " TABLE.");
706  }
707 }
std::string tableName
std::string storageType
#define VIEW
static constexpr char const * FOREIGN_TABLE

+ Here is the caller graph for this function: