OmniSciDB  21ac014ffc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  const std::string* default_value) {
515  cd.columnName = column_name;
516  validate_and_set_type(cd, column_type);
517  cd.columnType.set_notnull(not_null);
518  validate_and_set_encoding(cd, encoding, column_type);
519  validate_and_set_array_size(cd, column_type);
520  cd.isSystemCol = false;
521  cd.isVirtualCol = false;
522  cd.default_value = default_value ? std::make_optional(*default_value) : std::nullopt;
523 }
524 
525 void set_default_table_attributes(const std::string& table_name,
526  TableDescriptor& td,
527  const int32_t column_count) {
528  td.tableName = table_name;
529  td.nColumns = column_count;
530  td.isView = false;
531  td.fragmenter = nullptr;
537 }
538 
539 void validate_non_duplicate_column(const std::string& column_name,
540  std::unordered_set<std::string>& upper_column_names) {
541  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
542  const auto insert_it = upper_column_names.insert(upper_column_name);
543  if (!insert_it.second) {
544  throw std::runtime_error("Column '" + column_name + "' defined more than once");
545  }
546 }
547 
548 void validate_non_reserved_keyword(const std::string& column_name) {
549  const auto upper_column_name = boost::to_upper_copy<std::string>(column_name);
550  if (reserved_keywords.find(upper_column_name) != reserved_keywords.end()) {
551  throw std::runtime_error("Cannot create column with reserved keyword '" +
552  column_name + "'");
553  }
554 }
555 
557  const TableType expected_table_type,
558  const std::string& command) {
559  if (td->isView) {
560  if (expected_table_type != TableType::VIEW) {
561  throw std::runtime_error(td->tableName + " is a view. Use " + command + " VIEW.");
562  }
563  } else if (td->storageType == StorageType::FOREIGN_TABLE) {
564  if (expected_table_type != TableType::FOREIGN_TABLE) {
565  throw std::runtime_error(td->tableName + " is a foreign table. Use " + command +
566  " FOREIGN TABLE.");
567  }
568  } else if (expected_table_type != TableType::TABLE) {
569  throw std::runtime_error(td->tableName + " is a table. Use " + command + " TABLE.");
570  }
571 }
572 
573 std::string table_type_enum_to_string(const TableType table_type) {
574  if (table_type == ddl_utils::TableType::TABLE) {
575  return "Table";
576  }
577  if (table_type == ddl_utils::TableType::FOREIGN_TABLE) {
578  return "ForeignTable";
579  }
580  if (table_type == ddl_utils::TableType::VIEW) {
581  return "View";
582  }
583  throw std::runtime_error{"Unexpected table type"};
584 }
585 
586 std::string get_malformed_config_error_message(const std::string& config_key) {
587  return "Configuration value for \"" + config_key +
588  "\" is malformed. Value should be a list of paths with format: [ "
589  "\"root-path-1\", \"root-path-2\", ... ]";
590 }
591 
592 void validate_expanded_file_path(const std::string& file_path,
593  const std::vector<std::string>& whitelisted_root_paths) {
594  const auto& canonical_file_path = boost::filesystem::canonical(file_path);
595  for (const auto& root_path : whitelisted_root_paths) {
596  if (boost::istarts_with(canonical_file_path.string(), root_path)) {
597  return;
598  }
599  }
600  if (canonical_file_path == boost::filesystem::absolute(file_path)) {
601  throw std::runtime_error{"File or directory path \"" + file_path +
602  "\" is not whitelisted."};
603  }
604  throw std::runtime_error{"File or directory path \"" + file_path +
605  "\" (resolved to \"" + canonical_file_path.string() +
606  "\") is not whitelisted."};
607 }
608 
609 std::vector<std::string> get_expanded_file_paths(
610  const std::string& file_path,
611  const DataTransferType data_transfer_type) {
612  std::vector<std::string> file_paths;
613  if (data_transfer_type == DataTransferType::IMPORT) {
614  file_paths = omnisci::glob(file_path);
615  if (file_paths.size() == 0) {
616  throw std::runtime_error{"File or directory \"" + file_path + "\" does not exist."};
617  }
618  } else {
619  std::string path;
620  if (!boost::filesystem::exists(file_path)) {
621  // For exports, it is possible to provide a path to a new (nonexistent) file. In
622  // this case, validate using the parent path.
623  path = boost::filesystem::path(file_path).parent_path().string();
624  if (!boost::filesystem::exists(path)) {
625  throw std::runtime_error{"File or directory \"" + file_path +
626  "\" does not exist."};
627  }
628  } else {
629  path = file_path;
630  }
631  file_paths = {path};
632  }
633  return file_paths;
634 }
635 
636 void validate_allowed_file_path(const std::string& file_path,
637  const DataTransferType data_transfer_type,
638  const bool allow_wildcards) {
639  // Reject any punctuation characters except for a few safe ones.
640  // Some punctuation characters present a security risk when passed
641  // to subprocesses. Don't change this without a security review.
642  static const std::string safe_punctuation{"./_+-=:~"};
643  for (const auto& ch : file_path) {
644  if (std::ispunct(ch) && safe_punctuation.find(ch) == std::string::npos &&
645  !(allow_wildcards && ch == '*')) {
646  throw std::runtime_error(std::string("Punctuation \"") + ch +
647  "\" is not allowed in file path: " + file_path);
648  }
649  }
650 
651  // Enforce our whitelist and blacklist for file paths.
652  const auto& expanded_file_paths =
653  get_expanded_file_paths(file_path, data_transfer_type);
654  for (const auto& path : expanded_file_paths) {
656  const auto& canonical_file_path = boost::filesystem::canonical(file_path);
657  if (canonical_file_path == boost::filesystem::absolute(file_path)) {
658  throw std::runtime_error{"Access to file or directory path \"" + file_path +
659  "\" is not allowed."};
660  }
661  throw std::runtime_error{"Access to file or directory path \"" + file_path +
662  "\" (resolved to \"" + canonical_file_path.string() +
663  "\") is not allowed."};
664  }
665  }
666  FilePathWhitelist::validateWhitelistedFilePath(expanded_file_paths, data_transfer_type);
667 }
668 
669 void set_whitelisted_paths(const std::string& config_key,
670  const std::string& config_value,
671  std::vector<std::string>& whitelisted_paths) {
672  rapidjson::Document whitelisted_root_paths;
673  whitelisted_root_paths.Parse(config_value);
674  if (!whitelisted_root_paths.IsArray()) {
675  throw std::runtime_error{get_malformed_config_error_message(config_key)};
676  }
677  for (const auto& root_path : whitelisted_root_paths.GetArray()) {
678  if (!root_path.IsString()) {
679  throw std::runtime_error{get_malformed_config_error_message(config_key)};
680  }
681  if (!boost::filesystem::exists(root_path.GetString())) {
682  throw std::runtime_error{"Whitelisted root path \"" +
683  std::string{root_path.GetString()} + "\" does not exist."};
684  }
685  whitelisted_paths.emplace_back(
686  boost::filesystem::canonical(root_path.GetString()).string());
687  }
688  LOG(INFO) << "Parsed " << config_key << ": "
689  << shared::printContainer(whitelisted_paths);
690 }
691 
692 void FilePathWhitelist::initialize(const std::string& data_dir,
693  const std::string& allowed_import_paths,
694  const std::string& allowed_export_paths) {
695  CHECK(!data_dir.empty());
696  CHECK(boost::filesystem::is_directory(data_dir));
697 
698  auto data_dir_path = boost::filesystem::canonical(data_dir);
700  whitelisted_import_paths_.emplace_back((data_dir_path / "mapd_import").string());
701 
703  whitelisted_export_paths_.emplace_back((data_dir_path / "mapd_export").string());
704 
705  if (!allowed_import_paths.empty()) {
707  "allowed-import-paths", allowed_import_paths, whitelisted_import_paths_);
708  }
709  if (!allowed_export_paths.empty()) {
711  "allowed-export-paths", allowed_export_paths, whitelisted_export_paths_);
712  }
713 }
714 
716  const std::vector<std::string>& expanded_file_paths,
717  const DataTransferType data_transfer_type) {
718  for (const auto& path : expanded_file_paths) {
719  if (data_transfer_type == DataTransferType::IMPORT) {
721  } else if (data_transfer_type == DataTransferType::EXPORT) {
723  } else {
724  UNREACHABLE();
725  }
726  }
727 }
728 
732 }
733 
734 std::vector<std::string> FilePathWhitelist::whitelisted_import_paths_{};
735 std::vector<std::string> FilePathWhitelist::whitelisted_export_paths_{};
736 
737 void FilePathBlacklist::addToBlacklist(const std::string& path) {
738  CHECK(!path.empty());
739  blacklisted_paths_.emplace_back(path);
740 }
741 
742 bool FilePathBlacklist::isBlacklistedPath(const std::string& path) {
743  const auto canonical_path = boost::filesystem::canonical(path).string();
744  for (const auto& blacklisted_path : blacklisted_paths_) {
745  std::string full_path;
746  try {
747  full_path = boost::filesystem::canonical(blacklisted_path).string();
748  } catch (...) {
755  full_path = boost::filesystem::absolute(blacklisted_path).string();
756  }
757  if (boost::istarts_with(canonical_path, full_path)) {
758  return true;
759  }
760  }
761  return false;
762 }
763 
765  blacklisted_paths_.clear();
766 }
767 
768 std::vector<std::string> FilePathBlacklist::blacklisted_paths_{};
769 } // namespace ddl_utils
static std::set< std::string > reserved_keywords
DataTransferType
Definition: DdlUtils.h:80
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:324
void set_compression(EncodingType c)
Definition: sqltypes.h:423
void set_size(int s)
Definition: sqltypes.h:421
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:609
static std::vector< std::string > whitelisted_export_paths_
Definition: DdlUtils.h:94
HOST DEVICE int get_size() const
Definition: sqltypes.h:333
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:692
void validate_and_set_dictionary_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:336
#define LOG(tag)
Definition: Logger.h:200
std::string storageType
#define DEFAULT_MAX_CHUNK_SIZE
#define UNREACHABLE()
Definition: Logger.h:250
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:414
virtual int get_encoding_param() const
Definition: DdlUtils.cpp:206
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:323
void validate_non_duplicate_column(const std::string &column_name, std::unordered_set< std::string > &upper_column_names)
Definition: DdlUtils.cpp:539
void set_column_descriptor(const std::string &column_name, ColumnDescriptor &cd, SqlType *column_type, const bool not_null, const Encoding *encoding, const std::string *default_value)
Definition: DdlUtils.cpp:509
void validate_and_set_none_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:362
void set_input_srid(int d)
Definition: sqltypes.h:417
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:715
void set_fixed_size()
Definition: sqltypes.h:422
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:418
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:592
virtual std::string to_string() const
Definition: DdlUtils.cpp:74
void validate_non_reserved_keyword(const std::string &column_name)
Definition: DdlUtils.cpp:548
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:525
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
int get_precision() const
Definition: sqltypes.h:326
void validate_allowed_file_path(const std::string &file_path, const DataTransferType data_transfer_type, const bool allow_wildcards)
Definition: DdlUtils.cpp:636
void set_output_srid(int s)
Definition: sqltypes.h:419
#define DEFAULT_PAGE_SIZE
void set_comp_param(int p)
Definition: sqltypes.h:424
void validate_and_set_compressed_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:390
std::optional< std::string > default_value
Definition: sqltypes.h:51
Definition: sqltypes.h:52
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:331
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:586
void set_dimension(int d)
Definition: sqltypes.h:415
#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:573
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:669
Definition: sqltypes.h:40
virtual void set_param1(int param)
Definition: DdlUtils.cpp:50
static bool isBlacklistedPath(const std::string &path)
Definition: DdlUtils.cpp:742
void validate_table_type(const TableDescriptor *td, const TableType expected_table_type, const std::string &command)
Definition: DdlUtils.cpp:556
void set_notnull(bool n)
Definition: sqltypes.h:420
#define CHECK(condition)
Definition: Logger.h:206
bool is_geometry() const
Definition: sqltypes.h:510
bool is_high_precision_timestamp() const
Definition: sqltypes.h:746
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:737
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:96
bool is_string() const
Definition: sqltypes.h:498
virtual int get_param1() const
Definition: DdlUtils.cpp:46
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:330
static constexpr char const * FOREIGN_TABLE
bool is_string_array() const
Definition: sqltypes.h:499
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:726
bool is_decimal() const
Definition: sqltypes.h:501
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:329
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:413