OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, 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  *
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  */
17 #pragma once
19 #include "Catalog/Catalog.h"
20 #include "Shared/sqltypes.h"
22 namespace ddl_utils {
23 class SqlType {
24  public:
40  SqlType(SQLTypes type, int param1, int param2, bool is_array, int array_size);
42  virtual SQLTypes get_type() const;
43  virtual int get_param1() const;
44  virtual void set_param1(int param);
45  virtual int get_param2() const;
46  virtual bool get_is_array() const;
47  virtual void set_is_array(bool a);
48  virtual int get_array_size() const;
49  virtual void set_array_size(int s);
50  virtual std::string to_string() const;
51  virtual void check_type();
53  protected:
55  int param1; // e.g. for NUMERIC(10). -1 means unspecified.
56  int param2; // e.g. for NUMERIC(10,3). 0 is default value.
57  bool is_array;
59 };
61 class Encoding {
62  public:
69  Encoding(std::string* encoding_name, int encoding_param);
70  virtual ~Encoding() {}
72  virtual const std::string* get_encoding_name() const;
73  virtual int get_encoding_param() const;
75  protected:
76  std::unique_ptr<std::string> encoding_name;
78 };
80 enum class DataTransferType { IMPORT = 1, EXPORT };
83  public:
84  static void initialize(const std::string& data_dir,
85  const std::string& allowed_import_paths,
86  const std::string& allowed_export_paths);
87  static void validateWhitelistedFilePath(
88  const std::vector<std::string>& expanded_file_paths,
89  const DataTransferType data_transfer_type);
90  static void clear();
92  private:
93  static std::vector<std::string> whitelisted_import_paths_;
94  static std::vector<std::string> whitelisted_export_paths_;
95 };
98  public:
99  static void addToBlacklist(const std::string& path);
100  static bool isBlacklistedPath(const std::string& path);
101  static void clear();
103  private:
104  static std::vector<std::string> blacklisted_paths_;
105 };
107 enum class TableType { TABLE = 1, VIEW, FOREIGN_TABLE };
112  int encoding_size,
113  const SqlType* column_type);
115 void validate_and_set_dictionary_encoding(ColumnDescriptor& cd, int encoding_size);
119 void validate_and_set_sparse_encoding(ColumnDescriptor& cd, int encoding_size);
121 void validate_and_set_compressed_encoding(ColumnDescriptor& cd, int encoding_size);
123 void validate_and_set_date_encoding(ColumnDescriptor& cd, int encoding_size);
126  const Encoding* encoding,
127  const SqlType* column_type);
129 void validate_and_set_type(ColumnDescriptor& cd, SqlType* column_type);
131 void validate_and_set_array_size(ColumnDescriptor& cd, const SqlType* column_type);
134  const std::string* default_value,
135  bool not_null);
137 void set_column_descriptor(const std::string& column_name,
138  ColumnDescriptor& cd,
139  SqlType* column_type,
140  const bool not_null,
141  const Encoding* encoding,
142  const std::string* default_value);
144 void set_default_table_attributes(const std::string& table_name,
145  TableDescriptor& td,
146  const int32_t column_count);
148 void validate_non_duplicate_column(const std::string& column_name,
149  std::unordered_set<std::string>& upper_column_names);
151 void validate_non_reserved_keyword(const std::string& column_name);
153 void validate_table_type(const TableDescriptor* td,
154  const TableType expected_table_type,
155  const std::string& command);
157 std::string table_type_enum_to_string(const TableType table_type);
170 void validate_allowed_file_path(const std::string& file_path,
171  const DataTransferType data_transfer_type,
172  const bool allow_wildcards = false);
173 } // namespace ddl_utils
Definition: DdlUtils.h:80
void validate_and_set_sparse_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:381
static std::vector< std::string > whitelisted_export_paths_
Definition: DdlUtils.h:94
Definition: sqltypes.h:55
SqlType(SQLTypes type, int param1, int param2, bool is_array, int array_size)
Definition: DdlUtils.cpp:38
void validate_and_set_array_size(ColumnDescriptor &cd, const SqlType *column_type)
Definition: DdlUtils.cpp:496
virtual void check_type()
Definition: DdlUtils.cpp:153
static void initialize(const std::string &data_dir, const std::string &allowed_import_paths, const std::string &allowed_export_paths)
Definition: DdlUtils.cpp:841
void validate_and_set_dictionary_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:344
virtual int get_encoding_param() const
Definition: DdlUtils.cpp:212
Constants for Builtin SQL Types supported by HEAVY.AI.
void validate_non_duplicate_column(const std::string &column_name, std::unordered_set< std::string > &upper_column_names)
Definition: DdlUtils.cpp:691
constexpr double a
Definition: Utm.h:32
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:661
void validate_and_set_none_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:370
This file contains the class specification and related data structures for Catalog.
void validate_and_set_encoding(ColumnDescriptor &cd, const Encoding *encoding, const SqlType *column_type)
Definition: DdlUtils.cpp:437
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:866
void set_default_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:216
SQLTypes type
Definition: DdlUtils.h:54
virtual ~Encoding()
Definition: DdlUtils.h:70
virtual SQLTypes get_type() const
Definition: DdlUtils.cpp:45
virtual std::string to_string() const
Definition: DdlUtils.cpp:77
void validate_non_reserved_keyword(const std::string &column_name)
Definition: DdlUtils.cpp:700
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:677
void validate_allowed_file_path(const std::string &file_path, const DataTransferType data_transfer_type, const bool allow_wildcards)
Definition: DdlUtils.cpp:785
void validate_and_set_compressed_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:398
virtual const std::string * get_encoding_name() const
Definition: DdlUtils.cpp:208
void validate_and_set_fixed_encoding(ColumnDescriptor &cd, int encoding_size, const SqlType *column_type)
Definition: DdlUtils.cpp:246
std::string table_type_enum_to_string(const TableType table_type)
Definition: DdlUtils.cpp:725
Encoding(std::string *encoding_name, int encoding_param)
Definition: DdlUtils.cpp:205
virtual void set_param1(int param)
Definition: DdlUtils.cpp:53
static bool isBlacklistedPath(const std::string &path)
Definition: DdlUtils.cpp:893
void validate_table_type(const TableDescriptor *td, const TableType expected_table_type, const std::string &command)
Definition: DdlUtils.cpp:708
void validate_and_set_default_value(ColumnDescriptor &cd, const std::string *default_value, bool not_null)
Definition: DdlUtils.cpp:640
void validate_and_set_date_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:418
static void addToBlacklist(const std::string &path)
Definition: DdlUtils.cpp:888
std::unique_ptr< std::string > encoding_name
Definition: DdlUtils.h:76
virtual void set_is_array(bool a)
Definition: DdlUtils.cpp:65
virtual int get_param1() const
Definition: DdlUtils.cpp:49
virtual int get_param2() const
Definition: DdlUtils.cpp:57
virtual bool get_is_array() const
Definition: DdlUtils.cpp:61
virtual void set_array_size(int s)
Definition: DdlUtils.cpp:73
static std::vector< std::string > blacklisted_paths_
Definition: DdlUtils.h:104
virtual int get_array_size() const
Definition: DdlUtils.cpp:69
void validate_and_set_type(ColumnDescriptor &cd, SqlType *column_type)
Definition: DdlUtils.cpp:473