OmniSciDB  fe05a0c208
 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  switch (type) {
246  case kTINYINT:
247  case kSMALLINT:
248  case kINT:
249  case kBIGINT:
250  case kDATE:
251  throw std::runtime_error(cd.columnName + ": Cannot apply FIXED encoding to " +
252  column_type->to_string() + " type array.");
253  break;
254  default:
255  break;
256  }
257  }
258 
259  if (!IS_INTEGER(type) && !is_datetime(type) &&
260  !(type == kDECIMAL || type == kNUMERIC)) {
261  throw std::runtime_error(
262  cd.columnName +
263  ": Fixed encoding is only supported for integer or time columns.");
264  }
265 
266  switch (type) {
267  case kSMALLINT:
268  if (encoding_size != 8) {
269  throw std::runtime_error(
270  cd.columnName +
271  ": Compression parameter for Fixed encoding on SMALLINT must be 8.");
272  }
273  break;
274  case kINT:
275  if (encoding_size != 8 && encoding_size != 16) {
276  throw std::runtime_error(
277  cd.columnName +
278  ": Compression parameter for Fixed encoding on INTEGER must be 8 or 16.");
279  }
280  break;
281  case kBIGINT:
282  if (encoding_size != 8 && encoding_size != 16 && encoding_size != 32) {
283  throw std::runtime_error(cd.columnName +
284  ": Compression parameter for Fixed encoding on "
285  "BIGINT must be 8 or 16 or 32.");
286  }
287  break;
288  case kTIMESTAMP:
289  case kTIME:
290  if (encoding_size != 32) {
291  throw std::runtime_error(cd.columnName +
292  ": Compression parameter for Fixed encoding on "
293  "TIME or TIMESTAMP must be 32.");
294  } else if (cd.columnType.is_high_precision_timestamp()) {
295  throw std::runtime_error("Fixed encoding is not supported for TIMESTAMP(3|6|9).");
296  }
297  break;
298  case kDECIMAL:
299  case kNUMERIC:
300  if (encoding_size != 32 && encoding_size != 16) {
301  throw std::runtime_error(cd.columnName +
302  ": Compression parameter for Fixed encoding on "
303  "DECIMAL must be 16 or 32.");
304  }
305 
306  if (encoding_size == 32 && cd.columnType.get_precision() > 9) {
307  throw std::runtime_error(cd.columnName +
308  ": Precision too high for Fixed(32) encoding, max 9.");
309  }
310 
311  if (encoding_size == 16 && cd.columnType.get_precision() > 4) {
312  throw std::runtime_error(cd.columnName +
313  ": Precision too high for Fixed(16) encoding, max 4.");
314  }
315  break;
316  case kDATE:
317  if (encoding_size != 32 && encoding_size != 16) {
318  throw std::runtime_error(cd.columnName +
319  ": Compression parameter for Fixed encoding on "
320  "DATE must be 16 or 32.");
321  }
322  break;
323  default:
324  throw std::runtime_error(cd.columnName + ": Cannot apply FIXED encoding to " +
325  column_type->to_string());
326  }
327  if (type == kDATE) {
329  cd.columnType.set_comp_param(16);
330  } else {
332  cd.columnType.set_comp_param(encoding_size);
333  }
334 }
335 
337  if (!cd.columnType.is_string() && !cd.columnType.is_string_array()) {
338  throw std::runtime_error(
339  cd.columnName +
340  ": Dictionary encoding is only supported on string or string array columns.");
341  }
342  int comp_param;
343  if (encoding_size == 0) {
344  comp_param = 32; // default to 32-bits
345  } else {
346  comp_param = encoding_size;
347  }
348  if (cd.columnType.is_string_array() && comp_param != 32) {
349  throw std::runtime_error(cd.columnName +
350  ": Compression parameter for string arrays must be 32");
351  }
352  if (comp_param != 8 && comp_param != 16 && comp_param != 32) {
353  throw std::runtime_error(
354  cd.columnName +
355  ": Compression parameter for Dictionary encoding must be 8 or 16 or 32.");
356  }
357  // dictionary encoding
359  cd.columnType.set_comp_param(comp_param);
360 }
361 
363  if (!cd.columnType.is_string() && !cd.columnType.is_string_array() &&
364  !cd.columnType.is_geometry()) {
365  throw std::runtime_error(
366  cd.columnName +
367  ": None encoding is only supported on string, string array, or geo columns.");
368  }
371 }
372 
374  // sparse column encoding with mostly NULL values
375  if (cd.columnType.get_notnull()) {
376  throw std::runtime_error(cd.columnName +
377  ": Cannot do sparse column encoding on a NOT NULL column.");
378  }
379  if (encoding_size == 0 || encoding_size % 8 != 0 || encoding_size > 48) {
380  throw std::runtime_error(
381  cd.columnName +
382  "Must specify number of bits as 8, 16, 24, 32 or 48 as the parameter to "
383  "sparse-column encoding.");
384  }
386  cd.columnType.set_comp_param(encoding_size);
387  // throw std::runtime_error("SPARSE encoding not supported yet.");
388 }
389 
391  if (!cd.columnType.is_geometry() || cd.columnType.get_output_srid() != 4326) {
392  throw std::runtime_error(
393  cd.columnName + ": COMPRESSED encoding is only supported on WGS84 geo columns.");
394  }
395  int comp_param;
396  if (encoding_size == 0) {
397  comp_param = 32; // default to 32-bits
398  } else {
399  comp_param = encoding_size;
400  }
401  if (comp_param != 32) {
402  throw std::runtime_error(cd.columnName +
403  ": only 32-bit COMPRESSED geo encoding is supported");
404  }
405  // encoding longitude/latitude as integers
407  cd.columnType.set_comp_param(comp_param);
408 }
409 
410 void validate_and_set_date_encoding(ColumnDescriptor& cd, int encoding_size) {
411  // days encoding for dates
412  if (cd.columnType.get_type() == kARRAY && cd.columnType.get_subtype() == kDATE) {
413  throw std::runtime_error(cd.columnName +
414  ": Cannot apply days encoding to date array.");
415  }
416  if (cd.columnType.get_type() != kDATE) {
417  throw std::runtime_error(cd.columnName +
418  ": Days encoding is only supported for DATE columns.");
419  }
420  if (encoding_size != 32 && encoding_size != 16) {
421  throw std::runtime_error(cd.columnName +
422  ": Compression parameter for Days encoding on "
423  "DATE must be 16 or 32.");
424  }
426  cd.columnType.set_comp_param((encoding_size == 16) ? 16 : 0);
427 }
428 
430  const Encoding* encoding,
431  const SqlType* column_type) {
432  if (encoding == nullptr) {
434  } else {
435  const std::string& comp = *encoding->get_encoding_name();
436  if (boost::iequals(comp, "fixed")) {
437  validate_and_set_fixed_encoding(cd, encoding->get_encoding_param(), column_type);
438  } else if (boost::iequals(comp, "rl")) {
439  // run length encoding
442  // throw std::runtime_error("RL(Run Length) encoding not supported yet.");
443  } else if (boost::iequals(comp, "diff")) {
444  // differential encoding
447  // throw std::runtime_error("DIFF(differential) encoding not supported yet.");
448  } else if (boost::iequals(comp, "dict")) {
450  } else if (boost::iequals(comp, "NONE")) {
452  } else if (boost::iequals(comp, "sparse")) {
454  } else if (boost::iequals(comp, "compressed")) {
456  } else if (boost::iequals(comp, "days")) {
458  } else {
459  throw std::runtime_error(cd.columnName + ": Invalid column compression scheme " +
460  comp);
461  }
462  }
463 }
464 
466  column_type->check_type();
467 
468  if (column_type->get_is_array()) {
470  cd.columnType.set_subtype(column_type->get_type());
471  } else {
472  cd.columnType.set_type(column_type->get_type());
473  }
474  if (IS_GEO(column_type->get_type())) {
475  cd.columnType.set_subtype(static_cast<SQLTypes>(column_type->get_param1()));
476  cd.columnType.set_input_srid(column_type->get_param2());
477  cd.columnType.set_output_srid(column_type->get_param2());
478  } else {
479  cd.columnType.set_dimension(column_type->get_param1());
480  cd.columnType.set_scale(column_type->get_param2());
481  }
482 }
483 
484 void validate_and_set_array_size(ColumnDescriptor& cd, const SqlType* column_type) {
485  if (cd.columnType.is_string_array() &&
487  throw std::runtime_error(
488  cd.columnName +
489  ": Array of strings must be dictionary encoded. Specify ENCODING DICT");
490  }
491 
492  if (column_type->get_is_array()) {
493  int s = -1;
494  auto array_size = column_type->get_array_size();
495  if (array_size > 0) {
496  auto sti = cd.columnType.get_elem_type();
497  s = array_size * sti.get_size();
498  if (s <= 0) {
499  throw std::runtime_error(cd.columnName + ": Unexpected fixed length array size");
500  }
501  }
502  cd.columnType.set_size(s);
503 
504  } else {
506  }
507 }
508 
509 void set_column_descriptor(const std::string& column_name,
510  ColumnDescriptor& cd,
511  SqlType* column_type,
512  const bool not_null,
513  const Encoding* encoding) {
514  cd.columnName = column_name;
515  validate_and_set_type(cd, column_type);
516  cd.columnType.set_notnull(not_null);
517  validate_and_set_encoding(cd, encoding, column_type);
518  validate_and_set_array_size(cd, column_type);
519  cd.isSystemCol = false;
520  cd.isVirtualCol = false;
521 }
522 
523 void set_default_table_attributes(const std::string& table_name,
524  TableDescriptor& td,
525  const int32_t column_count) {
526  td.tableName = table_name;
527  td.nColumns = column_count;
528  td.isView = false;
529  td.fragmenter = nullptr;
535 }
536 
537 void validate_non_duplicate_column(const std::string& column_name,
538  std::unordered_set<std::string>& upper_column_names) {
539  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
540  const auto insert_it = upper_column_names.insert(upper_column_name);
541  if (!insert_it.second) {
542  throw std::runtime_error("Column '" + column_name + "' defined more than once");
543  }
544 }
545 
546 void validate_non_reserved_keyword(const std::string& column_name) {
547  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
548  if (reserved_keywords.find(upper_column_name) != reserved_keywords.end()) {
549  throw std::runtime_error("Cannot create column with reserved keyword '" +
550  column_name + "'");
551  }
552 }
553 
555  const TableType expected_table_type,
556  const std::string& command) {
557  if (td->isView) {
558  if (expected_table_type != TableType::VIEW) {
559  throw std::runtime_error(td->tableName + " is a view. Use " + command + " VIEW.");
560  }
561  } else if (td->storageType == StorageType::FOREIGN_TABLE) {
562  if (expected_table_type != TableType::FOREIGN_TABLE) {
563  throw std::runtime_error(td->tableName + " is a foreign table. Use " + command +
564  " FOREIGN TABLE.");
565  }
566  } else if (expected_table_type != TableType::TABLE) {
567  throw std::runtime_error(td->tableName + " is a table. Use " + command + " TABLE.");
568  }
569 }
570 
571 std::string table_type_enum_to_string(const TableType table_type) {
572  if (table_type == ddl_utils::TableType::TABLE) {
573  return "Table";
574  }
575  if (table_type == ddl_utils::TableType::FOREIGN_TABLE) {
576  return "ForeignTable";
577  }
578  if (table_type == ddl_utils::TableType::VIEW) {
579  return "View";
580  }
581  throw std::runtime_error{"Unexpected table type"};
582 }
583 
584 std::string get_malformed_config_error_message(const std::string& config_key) {
585  return "Configuration value for \"" + config_key +
586  "\" is malformed. Value should be a list of paths with format: [ "
587  "\"root-path-1\", \"root-path-2\", ... ]";
588 }
589 
590 void validate_expanded_file_path(const std::string& file_path,
591  const std::vector<std::string>& whitelisted_root_paths) {
592  const auto& canonical_file_path = boost::filesystem::canonical(file_path);
593  for (const auto& root_path : whitelisted_root_paths) {
594  if (boost::istarts_with(canonical_file_path.string(), root_path)) {
595  return;
596  }
597  }
598  if (canonical_file_path == boost::filesystem::absolute(file_path)) {
599  throw std::runtime_error{"File or directory path \"" + file_path +
600  "\" is not whitelisted."};
601  }
602  throw std::runtime_error{"File or directory path \"" + file_path +
603  "\" (resolved to \"" + canonical_file_path.string() +
604  "\") is not whitelisted."};
605 }
606 
607 std::vector<std::string> get_expanded_file_paths(
608  const std::string& file_path,
609  const DataTransferType data_transfer_type) {
610  std::vector<std::string> file_paths;
611  if (data_transfer_type == DataTransferType::IMPORT) {
612  file_paths = omnisci::glob(file_path);
613  if (file_paths.size() == 0) {
614  throw std::runtime_error{"File or directory \"" + file_path + "\" does not exist."};
615  }
616  } else {
617  std::string path;
618  if (!boost::filesystem::exists(file_path)) {
619  // For exports, it is possible to provide a path to a new (nonexistent) file. In
620  // this case, validate using the parent path.
621  path = boost::filesystem::path(file_path).parent_path().string();
622  if (!boost::filesystem::exists(path)) {
623  throw std::runtime_error{"File or directory \"" + file_path +
624  "\" does not exist."};
625  }
626  } else {
627  path = file_path;
628  }
629  file_paths = {path};
630  }
631  return file_paths;
632 }
633 
634 void validate_allowed_file_path(const std::string& file_path,
635  const DataTransferType data_transfer_type,
636  const bool allow_wildcards) {
637  // Reject any punctuation characters except for a few safe ones.
638  // Some punctuation characters present a security risk when passed
639  // to subprocesses. Don't change this without a security review.
640  static const std::string safe_punctuation{"./_+-=:~"};
641  for (const auto& ch : file_path) {
642  if (std::ispunct(ch) && safe_punctuation.find(ch) == std::string::npos &&
643  !(allow_wildcards && ch == '*')) {
644  throw std::runtime_error(std::string("Punctuation \"") + ch +
645  "\" is not allowed in file path: " + file_path);
646  }
647  }
648 
649  // Enforce our whitelist and blacklist for file paths.
650  const auto& expanded_file_paths =
651  get_expanded_file_paths(file_path, data_transfer_type);
652  for (const auto& path : expanded_file_paths) {
654  const auto& canonical_file_path = boost::filesystem::canonical(file_path);
655  if (canonical_file_path == boost::filesystem::absolute(file_path)) {
656  throw std::runtime_error{"Access to file or directory path \"" + file_path +
657  "\" is not allowed."};
658  }
659  throw std::runtime_error{"Access to file or directory path \"" + file_path +
660  "\" (resolved to \"" + canonical_file_path.string() +
661  "\") is not allowed."};
662  }
663  }
664  FilePathWhitelist::validateWhitelistedFilePath(expanded_file_paths, data_transfer_type);
665 }
666 
667 void set_whitelisted_paths(const std::string& config_key,
668  const std::string& config_value,
669  std::vector<std::string>& whitelisted_paths) {
670  rapidjson::Document whitelisted_root_paths;
671  whitelisted_root_paths.Parse(config_value);
672  if (!whitelisted_root_paths.IsArray()) {
673  throw std::runtime_error{get_malformed_config_error_message(config_key)};
674  }
675  for (const auto& root_path : whitelisted_root_paths.GetArray()) {
676  if (!root_path.IsString()) {
677  throw std::runtime_error{get_malformed_config_error_message(config_key)};
678  }
679  if (!boost::filesystem::exists(root_path.GetString())) {
680  throw std::runtime_error{"Whitelisted root path \"" +
681  std::string{root_path.GetString()} + "\" does not exist."};
682  }
683  whitelisted_paths.emplace_back(
684  boost::filesystem::canonical(root_path.GetString()).string());
685  }
686  LOG(INFO) << "Parsed " << config_key << ": "
687  << shared::printContainer(whitelisted_paths);
688 }
689 
690 void FilePathWhitelist::initialize(const std::string& data_dir,
691  const std::string& allowed_import_paths,
692  const std::string& allowed_export_paths) {
693  CHECK(!data_dir.empty());
694  CHECK(boost::filesystem::is_directory(data_dir));
695 
696  auto data_dir_path = boost::filesystem::canonical(data_dir);
698  whitelisted_import_paths_.emplace_back((data_dir_path / "mapd_import").string());
699 
701  whitelisted_export_paths_.emplace_back((data_dir_path / "mapd_export").string());
702 
703  if (!allowed_import_paths.empty()) {
705  "allowed-import-paths", allowed_import_paths, whitelisted_import_paths_);
706  }
707  if (!allowed_export_paths.empty()) {
709  "allowed-export-paths", allowed_export_paths, whitelisted_export_paths_);
710  }
711 }
712 
714  const std::vector<std::string>& expanded_file_paths,
715  const DataTransferType data_transfer_type) {
716  for (const auto& path : expanded_file_paths) {
717  if (data_transfer_type == DataTransferType::IMPORT) {
719  } else if (data_transfer_type == DataTransferType::EXPORT) {
721  } else {
722  UNREACHABLE();
723  }
724  }
725 }
726 
730 }
731 
732 std::vector<std::string> FilePathWhitelist::whitelisted_import_paths_{};
733 std::vector<std::string> FilePathWhitelist::whitelisted_export_paths_{};
734 
735 void FilePathBlacklist::addToBlacklist(const std::string& path) {
736  CHECK(!path.empty());
737  blacklisted_paths_.emplace_back(path);
738 }
739 
740 bool FilePathBlacklist::isBlacklistedPath(const std::string& path) {
741  const auto canonical_path = boost::filesystem::canonical(path).string();
742  for (const auto& blacklisted_path : blacklisted_paths_) {
743  std::string full_path;
744  try {
745  full_path = boost::filesystem::canonical(blacklisted_path).string();
746  } catch (...) {
753  full_path = boost::filesystem::absolute(blacklisted_path).string();
754  }
755  if (boost::istarts_with(canonical_path, full_path)) {
756  return true;
757  }
758  }
759  return false;
760 }
761 
763  blacklisted_paths_.clear();
764 }
765 
766 std::vector<std::string> FilePathBlacklist::blacklisted_paths_{};
767 } // namespace ddl_utils
static std::set< std::string > reserved_keywords
DataTransferType
Definition: DdlUtils.h:80
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:315
void set_compression(EncodingType c)
Definition: sqltypes.h:414
void set_size(int s)
Definition: sqltypes.h:412
void validate_and_set_sparse_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:373
std::vector< std::string > get_expanded_file_paths(const std::string &file_path, const DataTransferType data_transfer_type)
Definition: DdlUtils.cpp:607
static std::vector< std::string > whitelisted_export_paths_
Definition: DdlUtils.h:94
HOST DEVICE int get_size() const
Definition: sqltypes.h:324
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:484
virtual void check_type()
Definition: DdlUtils.cpp:150
static void initialize(const std::string &data_dir, const std::string &allowed_import_paths, const std::string &allowed_export_paths)
Definition: DdlUtils.cpp:690
void validate_and_set_dictionary_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:336
#define LOG(tag)
Definition: Logger.h:194
std::string storageType
#define DEFAULT_MAX_CHUNK_SIZE
#define UNREACHABLE()
Definition: Logger.h:247
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:405
virtual int get_encoding_param() const
Definition: DdlUtils.cpp:206
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
void validate_non_duplicate_column(const std::string &column_name, std::unordered_set< std::string > &upper_column_names)
Definition: DdlUtils.cpp:537
void validate_and_set_none_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:362
void set_input_srid(int d)
Definition: sqltypes.h:408
void validate_and_set_encoding(ColumnDescriptor &cd, const Encoding *encoding, const SqlType *column_type)
Definition: DdlUtils.cpp:429
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:93
static void validateWhitelistedFilePath(const std::vector< std::string > &expanded_file_paths, const DataTransferType data_transfer_type)
Definition: DdlUtils.cpp:713
void set_fixed_size()
Definition: sqltypes.h:413
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:409
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:590
virtual std::string to_string() const
Definition: DdlUtils.cpp:74
void validate_non_reserved_keyword(const std::string &column_name)
Definition: DdlUtils.cpp:546
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:523
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
int get_precision() const
Definition: sqltypes.h:317
void validate_allowed_file_path(const std::string &file_path, const DataTransferType data_transfer_type, const bool allow_wildcards)
Definition: DdlUtils.cpp:634
void set_output_srid(int s)
Definition: sqltypes.h:410
#define DEFAULT_PAGE_SIZE
void set_comp_param(int p)
Definition: sqltypes.h:415
void set_column_descriptor(const std::string &column_name, ColumnDescriptor &cd, SqlType *column_type, const bool not_null, const Encoding *encoding)
Definition: DdlUtils.cpp:509
void validate_and_set_compressed_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:390
Definition: sqltypes.h:51
Definition: sqltypes.h:52
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:322
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:584
void set_dimension(int d)
Definition: sqltypes.h:406
#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:571
Fragmenter_Namespace::FragmenterType fragType
Encoding(std::string *encoding_name, int encoding_param)
Definition: DdlUtils.cpp:199
#define IS_INTEGER(T)
Definition: sqltypes.h:239
void set_whitelisted_paths(const std::string &config_key, const std::string &config_value, std::vector< std::string > &whitelisted_paths)
Definition: DdlUtils.cpp:667
Definition: sqltypes.h:40
virtual void set_param1(int param)
Definition: DdlUtils.cpp:50
static bool isBlacklistedPath(const std::string &path)
Definition: DdlUtils.cpp:740
void validate_table_type(const TableDescriptor *td, const TableType expected_table_type, const std::string &command)
Definition: DdlUtils.cpp:554
void set_notnull(bool n)
Definition: sqltypes.h:411
#define CHECK(condition)
Definition: Logger.h:203
bool is_geometry() const
Definition: sqltypes.h:501
bool is_high_precision_timestamp() const
Definition: sqltypes.h:733
void validate_and_set_date_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:410
static void addToBlacklist(const std::string &path)
Definition: DdlUtils.cpp:735
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:80
bool is_string() const
Definition: sqltypes.h:489
virtual int get_param1() const
Definition: DdlUtils.cpp:46
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:321
static constexpr char const * FOREIGN_TABLE
bool is_string_array() const
Definition: sqltypes.h:490
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:713
bool is_decimal() const
Definition: sqltypes.h:492
virtual int get_param2() const
Definition: DdlUtils.cpp:54
std::string columnName
#define IS_GEO(T)
Definition: sqltypes.h:245
virtual bool get_is_array() const
Definition: DdlUtils.cpp:58
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:320
virtual void set_array_size(int s)
Definition: DdlUtils.cpp:70
constexpr auto is_datetime(SQLTypes type)
Definition: sqltypes.h:257
static std::vector< std::string > blacklisted_paths_
Definition: DdlUtils.h:104
virtual int get_array_size() const
Definition: DdlUtils.cpp:66
void validate_and_set_type(ColumnDescriptor &cd, SqlType *column_type)
Definition: DdlUtils.cpp:465
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:404