OmniSciDB  06b3bd477c
 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_drop_table_type (const TableDescriptor *td, const TableType expected_table_type)
 
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)
 
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 584 of file DdlUtils.cpp.

References IMPORT, and mapd_glob().

Referenced by validate_allowed_file_path().

586  {
587  std::vector<std::string> file_paths;
588  if (data_transfer_type == DataTransferType::IMPORT) {
589  file_paths = mapd_glob(file_path);
590  if (file_paths.size() == 0) {
591  throw std::runtime_error{"File or directory \"" + file_path + "\" does not exist."};
592  }
593  } else {
594  std::string path;
595  if (!boost::filesystem::exists(file_path)) {
596  // For exports, it is possible to provide a path to a new (nonexistent) file. In
597  // this case, validate using the parent path.
598  path = boost::filesystem::path(file_path).parent_path().string();
599  if (!boost::filesystem::exists(path)) {
600  throw std::runtime_error{"File or directory \"" + file_path +
601  "\" does not exist."};
602  }
603  } else {
604  path = file_path;
605  }
606  file_paths = {path};
607  }
608  return file_paths;
609 }
std::vector< std::string > mapd_glob(const std::string &pattern)
Definition: mapd_glob.cpp:22

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

Referenced by set_whitelisted_paths().

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

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

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

+ 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:358
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
bool g_use_date_in_days_default_encoding
Definition: DdlUtils.cpp:32
int get_precision() const
Definition: sqltypes.h:261
void set_comp_param(int p)
Definition: sqltypes.h:359
Definition: sqltypes.h:54
bool is_geometry() const
Definition: sqltypes.h:427
SQLTypeInfo columnType
bool is_string() const
Definition: sqltypes.h:415
bool is_string_array() const
Definition: sqltypes.h:416
bool is_decimal() const
Definition: sqltypes.h:418
std::string columnName
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:264

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

508  {
509  td.tableName = table_name;
510  td.nColumns = column_count;
511  td.isView = false;
512  td.fragmenter = nullptr;
518 }
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 624 of file DdlUtils.cpp.

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

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

626  {
627  CHECK(whitelisted_paths.empty());
628  rapidjson::Document whitelisted_root_paths;
629  whitelisted_root_paths.Parse(config_value);
630  if (!whitelisted_root_paths.IsArray()) {
631  throw std::runtime_error{get_malformed_config_error_message(config_key)};
632  }
633  for (const auto& root_path : whitelisted_root_paths.GetArray()) {
634  if (!root_path.IsString()) {
635  throw std::runtime_error{get_malformed_config_error_message(config_key)};
636  }
637  if (!boost::filesystem::exists(root_path.GetString())) {
638  throw std::runtime_error{"Whitelisted root path \"" +
639  std::string{root_path.GetString()} + "\" does not exist."};
640  }
641  whitelisted_paths.emplace_back(
642  boost::filesystem::canonical(root_path.GetString()).string());
643  }
644  LOG(INFO) << config_key << " " << shared::printContainer(whitelisted_paths);
645 }
#define LOG(tag)
Definition: Logger.h:188
CHECK(cgen_state)
std::string get_malformed_config_error_message(const std::string &config_key)
Definition: DdlUtils.cpp:566
PrintContainer< CONTAINER > printContainer(CONTAINER &container)
Definition: misc.h:63

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

References FOREIGN_TABLE, TABLE, and VIEW.

553  {
554  if (table_type == ddl_utils::TableType::TABLE) {
555  return "Table";
556  }
557  if (table_type == ddl_utils::TableType::FOREIGN_TABLE) {
558  return "ForeignTable";
559  }
560  if (table_type == ddl_utils::TableType::VIEW) {
561  return "View";
562  }
563  throw std::runtime_error{"Unexpected table type"};
564 }
void ddl_utils::validate_allowed_file_path ( const std::string &  file_path,
const DataTransferType  data_transfer_type 
)

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.

Parameters
file_path- file path to validate
data_transfer_type- enum indicating whether validation is for an import or export use case

Definition at line 611 of file DdlUtils.cpp.

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

Referenced by Parser::CopyTableStmt::execute(), Parser::ExportQueryStmt::execute(), foreign_storage::ParquetDataWrapper::validateFilePath(), and foreign_storage::CsvDataWrapper::validateFilePath().

612  {
613  const auto& expanded_file_paths =
614  get_expanded_file_paths(file_path, data_transfer_type);
615  for (const auto& path : expanded_file_paths) {
616  if (FilePathBlacklist::isBlacklistedPath(path)) {
617  throw std::runtime_error{"Access to file or directory path \"" + file_path +
618  "\" is not allowed."};
619  }
620  }
621  FilePathWhitelist::validateWhitelistedFilePath(expanded_file_paths, data_transfer_type);
622 }
std::vector< std::string > get_expanded_file_paths(const std::string &file_path, const DataTransferType data_transfer_type)
Definition: DdlUtils.cpp:584

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

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

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

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

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

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

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

Definition at line 349 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().

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

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

448  {
449  column_type->check_type();
450 
451  if (column_type->get_is_array()) {
453  cd.columnType.set_subtype(column_type->get_type());
454  } else {
455  cd.columnType.set_type(column_type->get_type());
456  }
457  if (IS_GEO(column_type->get_type())) {
458  cd.columnType.set_subtype(static_cast<SQLTypes>(column_type->get_param1()));
459  cd.columnType.set_input_srid(column_type->get_param2());
460  cd.columnType.set_output_srid(column_type->get_param2());
461  } else {
462  cd.columnType.set_dimension(column_type->get_param1());
463  cd.columnType.set_scale(column_type->get_param2());
464  }
465 }
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:349
void set_input_srid(int d)
Definition: sqltypes.h:352
void set_scale(int s)
Definition: sqltypes.h:353
void set_output_srid(int s)
Definition: sqltypes.h:354
void set_dimension(int d)
Definition: sqltypes.h:350
SQLTypeInfo columnType
#define IS_GEO(T)
Definition: sqltypes.h:173
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:348

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ddl_utils::validate_drop_table_type ( const TableDescriptor td,
const TableType  expected_table_type 
)

Definition at line 537 of file DdlUtils.cpp.

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

Referenced by DropForeignTableCommand::execute(), Parser::DropTableStmt::execute(), and Parser::DropViewStmt::execute().

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

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

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

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

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

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

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

+ Here is the caller graph for this function:

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

Definition at line 529 of file DdlUtils.cpp.

References reserved_keywords.

Referenced by CreateForeignTableCommand::setColumnDetails().

529  {
530  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
531  if (reserved_keywords.find(upper_column_name) != reserved_keywords.end()) {
532  throw std::runtime_error("Cannot create column with reserved keyword '" +
533  column_name + "'");
534  }
535 }
static std::set< std::string > reserved_keywords

+ Here is the caller graph for this function: