OmniSciDB  bf83d84833
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DdlUtils.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "DdlUtils.h"
18 
19 #include <unordered_set>
20 
21 #include <boost/algorithm/string.hpp>
22 #include <boost/filesystem.hpp>
23 #include <boost/program_options.hpp>
24 
25 #include "rapidjson/document.h"
26 
30 #include "Shared/misc.h"
31 
33 
34 namespace ddl_utils {
35 SqlType::SqlType(SQLTypes type, int param1, int param2, bool is_array, int array_size)
36  : type(type)
37  , param1(param1)
38  , param2(param2)
39  , is_array(is_array)
40  , array_size(array_size) {}
41 
43  return type;
44 }
45 
46 int SqlType::get_param1() const {
47  return param1;
48 }
49 
50 void SqlType::set_param1(int param) {
51  param1 = param;
52 }
53 
54 int SqlType::get_param2() const {
55  return param2;
56 }
57 
58 bool SqlType::get_is_array() const {
59  return is_array;
60 }
61 
62 void SqlType::set_is_array(bool a) {
63  is_array = a;
64 }
65 
67  return array_size;
68 }
69 
71  array_size = s;
72 }
73 
74 std::string SqlType::to_string() const {
75  std::string str;
76  switch (type) {
77  case kBOOLEAN:
78  str = "BOOLEAN";
79  break;
80  case kCHAR:
81  str = "CHAR(" + boost::lexical_cast<std::string>(param1) + ")";
82  break;
83  case kVARCHAR:
84  str = "VARCHAR(" + boost::lexical_cast<std::string>(param1) + ")";
85  break;
86  case kTEXT:
87  str = "TEXT";
88  break;
89  case kNUMERIC:
90  str = "NUMERIC(" + boost::lexical_cast<std::string>(param1);
91  if (param2 > 0) {
92  str += ", " + boost::lexical_cast<std::string>(param2);
93  }
94  str += ")";
95  break;
96  case kDECIMAL:
97  str = "DECIMAL(" + boost::lexical_cast<std::string>(param1);
98  if (param2 > 0) {
99  str += ", " + boost::lexical_cast<std::string>(param2);
100  }
101  str += ")";
102  break;
103  case kBIGINT:
104  str = "BIGINT";
105  break;
106  case kINT:
107  str = "INT";
108  break;
109  case kTINYINT:
110  str = "TINYINT";
111  break;
112  case kSMALLINT:
113  str = "SMALLINT";
114  break;
115  case kFLOAT:
116  str = "FLOAT";
117  break;
118  case kDOUBLE:
119  str = "DOUBLE";
120  break;
121  case kTIME:
122  str = "TIME";
123  if (param1 < 6) {
124  str += "(" + boost::lexical_cast<std::string>(param1) + ")";
125  }
126  break;
127  case kTIMESTAMP:
128  str = "TIMESTAMP";
129  if (param1 <= 9) {
130  str += "(" + boost::lexical_cast<std::string>(param1) + ")";
131  }
132  break;
133  case kDATE:
134  str = "DATE";
135  break;
136  default:
137  assert(false);
138  break;
139  }
140  if (is_array) {
141  str += "[";
142  if (array_size > 0) {
143  str += boost::lexical_cast<std::string>(array_size);
144  }
145  str += "]";
146  }
147  return str;
148 }
149 
151  switch (type) {
152  case kCHAR:
153  case kVARCHAR:
154  if (param1 <= 0) {
155  throw std::runtime_error("CHAR and VARCHAR must have a positive dimension.");
156  }
157  break;
158  case kDECIMAL:
159  case kNUMERIC:
160  if (param1 <= 0) {
161  throw std::runtime_error("DECIMAL and NUMERIC must have a positive precision.");
162  } else if (param1 > 19) {
163  throw std::runtime_error(
164  "DECIMAL and NUMERIC precision cannot be larger than 19.");
165  } else if (param1 <= param2) {
166  throw std::runtime_error(
167  "DECIMAL and NUMERIC must have precision larger than scale.");
168  }
169  break;
170  case kTIMESTAMP:
171  if (param1 == -1) {
172  param1 = 0; // set default to 0
173  } else if (param1 != 0 && param1 != 3 && param1 != 6 &&
174  param1 != 9) { // support ms, us, ns
175  throw std::runtime_error(
176  "Only TIMESTAMP(n) where n = (0,3,6,9) are supported now.");
177  }
178  break;
179  case kTIME:
180  if (param1 == -1) {
181  param1 = 0; // default precision is 0
182  }
183  if (param1 > 0) { // @TODO(wei) support sub-second precision later.
184  throw std::runtime_error("Only TIME(0) is supported now.");
185  }
186  break;
187  case kPOINT:
188  case kLINESTRING:
189  case kPOLYGON:
190  case kMULTIPOLYGON:
191  // Storing SRID in param1
192  break;
193  default:
194  param1 = 0;
195  break;
196  }
197 }
198 
199 Encoding::Encoding(std::string* encoding_name, int encoding_param)
200  : encoding_name(encoding_name), encoding_param(encoding_param) {}
201 
202 const std::string* Encoding::get_encoding_name() const {
203  return encoding_name.get();
204 }
205 
207  return encoding_param;
208 }
209 
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 }
237 
239  int encoding_size,
240  const SqlType* column_type) {
241  auto type = cd.columnType.get_type();
242  // fixed-bits encoding
243  if (type == kARRAY) {
244  type = cd.columnType.get_subtype();
245  }
246 
247  if (!IS_INTEGER(type) && !is_datetime(type) &&
248  !(type == kDECIMAL || type == kNUMERIC)) {
249  throw std::runtime_error(
250  cd.columnName +
251  ": Fixed encoding is only supported for integer or time columns.");
252  }
253 
254  switch (type) {
255  case kSMALLINT:
256  if (encoding_size != 8) {
257  throw std::runtime_error(
258  cd.columnName +
259  ": Compression parameter for Fixed encoding on SMALLINT must be 8.");
260  }
261  break;
262  case kINT:
263  if (encoding_size != 8 && encoding_size != 16) {
264  throw std::runtime_error(
265  cd.columnName +
266  ": Compression parameter for Fixed encoding on INTEGER must be 8 or 16.");
267  }
268  break;
269  case kBIGINT:
270  if (encoding_size != 8 && encoding_size != 16 && encoding_size != 32) {
271  throw std::runtime_error(cd.columnName +
272  ": Compression parameter for Fixed encoding on "
273  "BIGINT must be 8 or 16 or 32.");
274  }
275  break;
276  case kTIMESTAMP:
277  case kTIME:
278  if (encoding_size != 32) {
279  throw std::runtime_error(cd.columnName +
280  ": Compression parameter for Fixed encoding on "
281  "TIME or TIMESTAMP must be 32.");
282  } else if (cd.columnType.is_high_precision_timestamp()) {
283  throw std::runtime_error("Fixed encoding is not supported for TIMESTAMP(3|6|9).");
284  }
285  break;
286  case kDECIMAL:
287  case kNUMERIC:
288  if (encoding_size != 32 && encoding_size != 16) {
289  throw std::runtime_error(cd.columnName +
290  ": Compression parameter for Fixed encoding on "
291  "DECIMAL must be 16 or 32.");
292  }
293 
294  if (encoding_size == 32 && cd.columnType.get_precision() > 9) {
295  throw std::runtime_error(cd.columnName +
296  ": Precision too high for Fixed(32) encoding, max 9.");
297  }
298 
299  if (encoding_size == 16 && cd.columnType.get_precision() > 4) {
300  throw std::runtime_error(cd.columnName +
301  ": Precision too high for Fixed(16) encoding, max 4.");
302  }
303  break;
304  case kDATE:
305  if (encoding_size != 32 && encoding_size != 16) {
306  throw std::runtime_error(cd.columnName +
307  ": Compression parameter for Fixed encoding on "
308  "DATE must be 16 or 32.");
309  }
310  break;
311  default:
312  throw std::runtime_error(cd.columnName + ": Cannot apply FIXED encoding to " +
313  column_type->to_string());
314  }
315  if (type == kDATE) {
317  cd.columnType.set_comp_param(16);
318  } else {
320  cd.columnType.set_comp_param(encoding_size);
321  }
322 }
323 
325  if (!cd.columnType.is_string() && !cd.columnType.is_string_array()) {
326  throw std::runtime_error(
327  cd.columnName +
328  ": Dictionary encoding is only supported on string or string array columns.");
329  }
330  int comp_param;
331  if (encoding_size == 0) {
332  comp_param = 32; // default to 32-bits
333  } else {
334  comp_param = encoding_size;
335  }
336  if (cd.columnType.is_string_array() && comp_param != 32) {
337  throw std::runtime_error(cd.columnName +
338  ": Compression parameter for string arrays must be 32");
339  }
340  if (comp_param != 8 && comp_param != 16 && comp_param != 32) {
341  throw std::runtime_error(
342  cd.columnName +
343  ": Compression parameter for Dictionary encoding must be 8 or 16 or 32.");
344  }
345  // dictionary encoding
347  cd.columnType.set_comp_param(comp_param);
348 }
349 
351  if (!cd.columnType.is_string() && !cd.columnType.is_string_array() &&
352  !cd.columnType.is_geometry()) {
353  throw std::runtime_error(
354  cd.columnName +
355  ": None encoding is only supported on string, string array, or geo columns.");
356  }
359 }
360 
362  // sparse column encoding with mostly NULL values
363  if (cd.columnType.get_notnull()) {
364  throw std::runtime_error(cd.columnName +
365  ": Cannot do sparse column encoding on a NOT NULL column.");
366  }
367  if (encoding_size == 0 || encoding_size % 8 != 0 || encoding_size > 48) {
368  throw std::runtime_error(
369  cd.columnName +
370  "Must specify number of bits as 8, 16, 24, 32 or 48 as the parameter to "
371  "sparse-column encoding.");
372  }
374  cd.columnType.set_comp_param(encoding_size);
375  // throw std::runtime_error("SPARSE encoding not supported yet.");
376 }
377 
379  if (!cd.columnType.is_geometry() || cd.columnType.get_output_srid() != 4326) {
380  throw std::runtime_error(
381  cd.columnName + ": COMPRESSED encoding is only supported on WGS84 geo columns.");
382  }
383  int comp_param;
384  if (encoding_size == 0) {
385  comp_param = 32; // default to 32-bits
386  } else {
387  comp_param = encoding_size;
388  }
389  if (comp_param != 32) {
390  throw std::runtime_error(cd.columnName +
391  ": only 32-bit COMPRESSED geo encoding is supported");
392  }
393  // encoding longitude/latitude as integers
395  cd.columnType.set_comp_param(comp_param);
396 }
397 
398 void validate_and_set_date_encoding(ColumnDescriptor& cd, int encoding_size) {
399  // days encoding for dates
400  if (cd.columnType.get_type() != kDATE) {
401  throw std::runtime_error(cd.columnName +
402  ": Days encoding is only supported for DATE columns.");
403  }
404  if (encoding_size != 32 && encoding_size != 16) {
405  throw std::runtime_error(cd.columnName +
406  ": Compression parameter for Days encoding on "
407  "DATE must be 16 or 32.");
408  }
410  cd.columnType.set_comp_param((encoding_size == 16) ? 16 : 0);
411 }
412 
414  const Encoding* encoding,
415  const SqlType* column_type) {
416  if (encoding == nullptr) {
418  } else {
419  const std::string& comp = *encoding->get_encoding_name();
420  if (boost::iequals(comp, "fixed")) {
421  validate_and_set_fixed_encoding(cd, encoding->get_encoding_param(), column_type);
422  } else if (boost::iequals(comp, "rl")) {
423  // run length encoding
426  // throw std::runtime_error("RL(Run Length) encoding not supported yet.");
427  } else if (boost::iequals(comp, "diff")) {
428  // differential encoding
431  // throw std::runtime_error("DIFF(differential) encoding not supported yet.");
432  } else if (boost::iequals(comp, "dict")) {
434  } else if (boost::iequals(comp, "NONE")) {
436  } else if (boost::iequals(comp, "sparse")) {
438  } else if (boost::iequals(comp, "compressed")) {
440  } else if (boost::iequals(comp, "days")) {
442  } else {
443  throw std::runtime_error(cd.columnName + ": Invalid column compression scheme " +
444  comp);
445  }
446  }
447 }
448 
450  column_type->check_type();
451 
452  if (column_type->get_is_array()) {
454  cd.columnType.set_subtype(column_type->get_type());
455  } else {
456  cd.columnType.set_type(column_type->get_type());
457  }
458  if (IS_GEO(column_type->get_type())) {
459  cd.columnType.set_subtype(static_cast<SQLTypes>(column_type->get_param1()));
460  cd.columnType.set_input_srid(column_type->get_param2());
461  cd.columnType.set_output_srid(column_type->get_param2());
462  } else {
463  cd.columnType.set_dimension(column_type->get_param1());
464  cd.columnType.set_scale(column_type->get_param2());
465  }
466 }
467 
468 void validate_and_set_array_size(ColumnDescriptor& cd, const SqlType* column_type) {
469  if (cd.columnType.is_string_array() &&
471  throw std::runtime_error(
472  cd.columnName +
473  ": Array of strings must be dictionary encoded. Specify ENCODING DICT");
474  }
475 
476  if (column_type->get_is_array()) {
477  int s = -1;
478  auto array_size = column_type->get_array_size();
479  if (array_size > 0) {
480  auto sti = cd.columnType.get_elem_type();
481  s = array_size * sti.get_size();
482  if (s <= 0) {
483  throw std::runtime_error(cd.columnName + ": Unexpected fixed length array size");
484  }
485  }
486  cd.columnType.set_size(s);
487 
488  } else {
490  }
491 }
492 
493 void set_column_descriptor(const std::string& column_name,
494  ColumnDescriptor& cd,
495  SqlType* column_type,
496  const bool not_null,
497  const Encoding* encoding) {
498  cd.columnName = column_name;
499  validate_and_set_type(cd, column_type);
500  cd.columnType.set_notnull(not_null);
501  validate_and_set_encoding(cd, encoding, column_type);
502  validate_and_set_array_size(cd, column_type);
503  cd.isSystemCol = false;
504  cd.isVirtualCol = false;
505 }
506 
507 void set_default_table_attributes(const std::string& table_name,
508  TableDescriptor& td,
509  const int32_t column_count) {
510  td.tableName = table_name;
511  td.nColumns = column_count;
512  td.isView = false;
513  td.fragmenter = nullptr;
519 }
520 
521 void validate_non_duplicate_column(const std::string& column_name,
522  std::unordered_set<std::string>& upper_column_names) {
523  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
524  const auto insert_it = upper_column_names.insert(upper_column_name);
525  if (!insert_it.second) {
526  throw std::runtime_error("Column '" + column_name + "' defined more than once");
527  }
528 }
529 
530 void validate_non_reserved_keyword(const std::string& column_name) {
531  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
532  if (reserved_keywords.find(upper_column_name) != reserved_keywords.end()) {
533  throw std::runtime_error("Cannot create column with reserved keyword '" +
534  column_name + "'");
535  }
536 }
537 
539  const TableType expected_table_type,
540  const std::string& command) {
541  if (td->isView) {
542  if (expected_table_type != TableType::VIEW) {
543  throw std::runtime_error(td->tableName + " is a view. Use " + command + " VIEW.");
544  }
545  } else if (td->storageType == StorageType::FOREIGN_TABLE) {
546  if (expected_table_type != TableType::FOREIGN_TABLE) {
547  throw std::runtime_error(td->tableName + " is a foreign table. Use " + command +
548  " FOREIGN TABLE.");
549  }
550  } else if (expected_table_type != TableType::TABLE) {
551  throw std::runtime_error(td->tableName + " is a table. Use " + command + " TABLE.");
552  }
553 }
554 
555 std::string table_type_enum_to_string(const TableType table_type) {
556  if (table_type == ddl_utils::TableType::TABLE) {
557  return "Table";
558  }
559  if (table_type == ddl_utils::TableType::FOREIGN_TABLE) {
560  return "ForeignTable";
561  }
562  if (table_type == ddl_utils::TableType::VIEW) {
563  return "View";
564  }
565  throw std::runtime_error{"Unexpected table type"};
566 }
567 
568 std::string get_malformed_config_error_message(const std::string& config_key) {
569  return "Configuration value for \"" + config_key +
570  "\" is malformed. Value should be a list of paths with format: [ "
571  "\"root-path-1\", \"root-path-2\", ... ]";
572 }
573 
574 void validate_expanded_file_path(const std::string& file_path,
575  const std::vector<std::string>& whitelisted_root_paths) {
576  boost::filesystem::path canonical_file_path = boost::filesystem::canonical(file_path);
577  for (const auto& root_path : whitelisted_root_paths) {
578  if (boost::istarts_with(canonical_file_path.string(), root_path)) {
579  return;
580  }
581  }
582  throw std::runtime_error{"File or directory path \"" + file_path +
583  "\" is not whitelisted."};
584 }
585 
586 std::vector<std::string> get_expanded_file_paths(
587  const std::string& file_path,
588  const DataTransferType data_transfer_type) {
589  std::vector<std::string> file_paths;
590  if (data_transfer_type == DataTransferType::IMPORT) {
591  file_paths = omnisci::glob(file_path);
592  if (file_paths.size() == 0) {
593  throw std::runtime_error{"File or directory \"" + file_path + "\" does not exist."};
594  }
595  } else {
596  std::string path;
597  if (!boost::filesystem::exists(file_path)) {
598  // For exports, it is possible to provide a path to a new (nonexistent) file. In
599  // this case, validate using the parent path.
600  path = boost::filesystem::path(file_path).parent_path().string();
601  if (!boost::filesystem::exists(path)) {
602  throw std::runtime_error{"File or directory \"" + file_path +
603  "\" does not exist."};
604  }
605  } else {
606  path = file_path;
607  }
608  file_paths = {path};
609  }
610  return file_paths;
611 }
612 
613 void validate_allowed_file_path(const std::string& file_path,
614  const DataTransferType data_transfer_type,
615  const bool allow_wildcards) {
616  // Reject any punctuation characters except for a few safe ones.
617  // Some punctuation characters present a security risk when passed
618  // to subprocesses. Don't change this without a security review.
619  static const std::string safe_punctuation{"./_+-=:~"};
620  for (const auto& ch : file_path) {
621  if (std::ispunct(ch) && safe_punctuation.find(ch) == std::string::npos &&
622  !(allow_wildcards && ch == '*')) {
623  throw std::runtime_error(std::string("Punctuation \"") + ch +
624  "\" is not allowed in file path: " + file_path);
625  }
626  }
627 
628  // Enforce our whitelist and blacklist for file paths.
629  const auto& expanded_file_paths =
630  get_expanded_file_paths(file_path, data_transfer_type);
631  for (const auto& path : expanded_file_paths) {
633  throw std::runtime_error{"Access to file or directory path \"" + file_path +
634  "\" is not allowed."};
635  }
636  }
637  FilePathWhitelist::validateWhitelistedFilePath(expanded_file_paths, data_transfer_type);
638 }
639 
640 void set_whitelisted_paths(const std::string& config_key,
641  const std::string& config_value,
642  std::vector<std::string>& whitelisted_paths) {
643  CHECK(whitelisted_paths.empty());
644  rapidjson::Document whitelisted_root_paths;
645  whitelisted_root_paths.Parse(config_value);
646  if (!whitelisted_root_paths.IsArray()) {
647  throw std::runtime_error{get_malformed_config_error_message(config_key)};
648  }
649  for (const auto& root_path : whitelisted_root_paths.GetArray()) {
650  if (!root_path.IsString()) {
651  throw std::runtime_error{get_malformed_config_error_message(config_key)};
652  }
653  if (!boost::filesystem::exists(root_path.GetString())) {
654  throw std::runtime_error{"Whitelisted root path \"" +
655  std::string{root_path.GetString()} + "\" does not exist."};
656  }
657  whitelisted_paths.emplace_back(
658  boost::filesystem::canonical(root_path.GetString()).string());
659  }
660  LOG(INFO) << config_key << " " << shared::printContainer(whitelisted_paths);
661 }
662 
663 void FilePathWhitelist::initializeFromConfigFile(const std::string& server_config_path) {
664  if (server_config_path.empty()) {
665  return;
666  }
667 
668  if (!boost::filesystem::exists(server_config_path)) {
669  throw std::runtime_error{"Configuration file at \"" + server_config_path +
670  "\" does not exist."};
671  }
672 
673  std::string import_config_key{"allowed-import-paths"};
674  std::string export_config_key{"allowed-export-paths"};
675  std::string import_config_value, export_config_value;
676 
677  namespace po = boost::program_options;
678  po::options_description desc{};
679  desc.add_options()(import_config_key.c_str(),
680  po::value<std::string>(&import_config_value));
681  desc.add_options()(export_config_key.c_str(),
682  po::value<std::string>(&export_config_value));
683  po::variables_map vm;
684  po::store(po::parse_config_file<char>(server_config_path.c_str(), desc, true), vm);
685  po::notify(vm);
686  if (vm.count(import_config_key)) {
688  import_config_key, import_config_value, whitelisted_import_paths_);
689  }
690  if (vm.count(export_config_key)) {
692  export_config_key, export_config_value, whitelisted_export_paths_);
693  }
694 }
695 
697  const std::vector<std::string>& expanded_file_paths,
698  const DataTransferType data_transfer_type) {
699  // Skip validation if no whitelist configuration is provided.
700  if ((data_transfer_type == DataTransferType::IMPORT &&
701  whitelisted_import_paths_.empty()) ||
702  (data_transfer_type == DataTransferType::EXPORT &&
703  whitelisted_export_paths_.empty())) {
704  return;
705  }
706 
707  for (const auto& path : expanded_file_paths) {
708  if (data_transfer_type == DataTransferType::IMPORT) {
710  } else if (data_transfer_type == DataTransferType::EXPORT) {
712  } else {
713  UNREACHABLE();
714  }
715  }
716 }
717 
721 }
722 
723 std::vector<std::string> FilePathWhitelist::whitelisted_import_paths_{};
724 std::vector<std::string> FilePathWhitelist::whitelisted_export_paths_{};
725 
726 void FilePathBlacklist::addToBlacklist(const std::string& path) {
727  CHECK(!path.empty());
728  blacklisted_paths_.emplace_back(path);
729 }
730 
731 bool FilePathBlacklist::isBlacklistedPath(const std::string& path) {
732  const auto canonical_path = boost::filesystem::canonical(path).string();
733  for (const auto& blacklisted_path : blacklisted_paths_) {
734  std::string full_path;
735  try {
736  full_path = boost::filesystem::canonical(blacklisted_path).string();
737  } catch (...) {
744  full_path = boost::filesystem::absolute(blacklisted_path).string();
745  }
746  if (boost::istarts_with(canonical_path, full_path)) {
747  return true;
748  }
749  }
750  return false;
751 }
752 
754  blacklisted_paths_.clear();
755 }
756 
757 std::vector<std::string> FilePathBlacklist::blacklisted_paths_{};
758 } // namespace ddl_utils
static std::set< std::string > reserved_keywords
DataTransferType
Definition: DdlUtils.h:80
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:312
void set_compression(EncodingType c)
Definition: sqltypes.h:411
void set_size(int s)
Definition: sqltypes.h:409
void validate_and_set_sparse_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:361
std::vector< std::string > get_expanded_file_paths(const std::string &file_path, const DataTransferType data_transfer_type)
Definition: DdlUtils.cpp:586
static std::vector< std::string > whitelisted_export_paths_
Definition: DdlUtils.h:92
HOST DEVICE int get_size() const
Definition: sqltypes.h:321
Definition: sqltypes.h:48
SQLTypes
Definition: sqltypes.h:37
std::string tableName
SqlType(SQLTypes type, int param1, int param2, bool is_array, int array_size)
Definition: DdlUtils.cpp:35
void validate_and_set_array_size(ColumnDescriptor &cd, const SqlType *column_type)
Definition: DdlUtils.cpp:468
virtual void check_type()
Definition: DdlUtils.cpp:150
void validate_and_set_dictionary_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:324
#define LOG(tag)
Definition: Logger.h:188
std::string storageType
#define DEFAULT_MAX_CHUNK_SIZE
static void initializeFromConfigFile(const std::string &server_config_path)
Definition: DdlUtils.cpp:663
#define UNREACHABLE()
Definition: Logger.h:241
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:402
virtual int get_encoding_param() const
Definition: DdlUtils.cpp:206
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:311
void validate_non_duplicate_column(const std::string &column_name, std::unordered_set< std::string > &upper_column_names)
Definition: DdlUtils.cpp:521
void validate_and_set_none_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:350
void set_input_srid(int d)
Definition: sqltypes.h:405
void validate_and_set_encoding(ColumnDescriptor &cd, const Encoding *encoding, const SqlType *column_type)
Definition: DdlUtils.cpp:413
#define DEFAULT_PAGE_SIZE
Definition: FileMgr.h:47
bool g_use_date_in_days_default_encoding
Definition: DdlUtils.cpp:32
#define DEFAULT_MAX_ROWS
static std::vector< std::string > whitelisted_import_paths_
Definition: DdlUtils.h:91
static void validateWhitelistedFilePath(const std::vector< std::string > &expanded_file_paths, const DataTransferType data_transfer_type)
Definition: DdlUtils.cpp:696
void set_fixed_size()
Definition: sqltypes.h:410
void set_default_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:210
std::vector< std::string > glob(const std::string &pattern)
void set_scale(int s)
Definition: sqltypes.h:406
SQLTypes type
Definition: DdlUtils.h:54
virtual SQLTypes get_type() const
Definition: DdlUtils.cpp:42
void validate_expanded_file_path(const std::string &file_path, const std::vector< std::string > &whitelisted_root_paths)
Definition: DdlUtils.cpp:574
virtual std::string to_string() const
Definition: DdlUtils.cpp:74
void validate_non_reserved_keyword(const std::string &column_name)
Definition: DdlUtils.cpp:530
specifies the content in-memory of a row in the column metadata table
void set_default_table_attributes(const std::string &table_name, TableDescriptor &td, const int32_t column_count)
Definition: DdlUtils.cpp:507
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
int get_precision() const
Definition: sqltypes.h:314
void validate_allowed_file_path(const std::string &file_path, const DataTransferType data_transfer_type, const bool allow_wildcards)
Definition: DdlUtils.cpp:613
void set_output_srid(int s)
Definition: sqltypes.h:407
void set_comp_param(int p)
Definition: sqltypes.h:412
void set_column_descriptor(const std::string &column_name, ColumnDescriptor &cd, SqlType *column_type, const bool not_null, const Encoding *encoding)
Definition: DdlUtils.cpp:493
void validate_and_set_compressed_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:378
Definition: sqltypes.h:51
Definition: sqltypes.h:52
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:319
virtual const std::string * get_encoding_name() const
Definition: DdlUtils.cpp:202
std::string get_malformed_config_error_message(const std::string &config_key)
Definition: DdlUtils.cpp:568
void set_dimension(int d)
Definition: sqltypes.h:403
#define DEFAULT_FRAGMENT_ROWS
void validate_and_set_fixed_encoding(ColumnDescriptor &cd, int encoding_size, const SqlType *column_type)
Definition: DdlUtils.cpp:238
std::string table_type_enum_to_string(const TableType table_type)
Definition: DdlUtils.cpp:555
Fragmenter_Namespace::FragmenterType fragType
Encoding(std::string *encoding_name, int encoding_param)
Definition: DdlUtils.cpp:199
#define IS_INTEGER(T)
Definition: sqltypes.h:236
void set_whitelisted_paths(const std::string &config_key, const std::string &config_value, std::vector< std::string > &whitelisted_paths)
Definition: DdlUtils.cpp:640
Definition: sqltypes.h:40
virtual void set_param1(int param)
Definition: DdlUtils.cpp:50
static bool isBlacklistedPath(const std::string &path)
Definition: DdlUtils.cpp:731
void validate_table_type(const TableDescriptor *td, const TableType expected_table_type, const std::string &command)
Definition: DdlUtils.cpp:538
void set_notnull(bool n)
Definition: sqltypes.h:408
#define CHECK(condition)
Definition: Logger.h:197
bool is_geometry() const
Definition: sqltypes.h:490
bool is_high_precision_timestamp() const
Definition: sqltypes.h:717
void validate_and_set_date_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:398
static void addToBlacklist(const std::string &path)
Definition: DdlUtils.cpp:726
Definition: sqltypes.h:44
std::unique_ptr< std::string > encoding_name
Definition: DdlUtils.h:76
SQLTypeInfo columnType
virtual void set_is_array(bool a)
Definition: DdlUtils.cpp:62
PrintContainer< CONTAINER > printContainer(CONTAINER &container)
Definition: misc.h:64
bool is_string() const
Definition: sqltypes.h:478
virtual int get_param1() const
Definition: DdlUtils.cpp:46
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:318
static constexpr char const * FOREIGN_TABLE
bool is_string_array() const
Definition: sqltypes.h:479
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:697
bool is_decimal() const
Definition: sqltypes.h:481
virtual int get_param2() const
Definition: DdlUtils.cpp:54
std::string columnName
#define IS_GEO(T)
Definition: sqltypes.h:242
virtual bool get_is_array() const
Definition: DdlUtils.cpp:58
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:317
virtual void set_array_size(int s)
Definition: DdlUtils.cpp:70
constexpr auto is_datetime(SQLTypes type)
Definition: sqltypes.h:254
static std::vector< std::string > blacklisted_paths_
Definition: DdlUtils.h:102
virtual int get_array_size() const
Definition: DdlUtils.cpp:66
void validate_and_set_type(ColumnDescriptor &cd, SqlType *column_type)
Definition: DdlUtils.cpp:449
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:401