OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DdlUtils.h
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  * 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 #pragma once
18 
19 #include "Catalog/Catalog.h"
20 #include "Shared/sqltypes.h"
21 
22 namespace ddl_utils {
23 class SqlType {
24  public:
40  SqlType(SQLTypes type, int param1, int param2, bool is_array, int array_size);
41 
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();
52 
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 };
60 
61 class Encoding {
62  public:
69  Encoding(std::string* encoding_name, int encoding_param);
70  virtual ~Encoding() {}
71 
72  virtual const std::string* get_encoding_name() const;
73  virtual int get_encoding_param() const;
74 
75  protected:
76  std::unique_ptr<std::string> encoding_name;
78 };
79 
80 enum class DataTransferType { IMPORT = 1, EXPORT };
81 
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();
91 
92  private:
93  static std::vector<std::string> whitelisted_import_paths_;
94  static std::vector<std::string> whitelisted_export_paths_;
95 };
96 
98  public:
99  static void addToBlacklist(const std::string& path);
100  static bool isBlacklistedPath(const std::string& path);
101  static void clear();
102 
103  private:
104  static std::vector<std::string> blacklisted_paths_;
105 };
106 
107 enum class TableType { TABLE = 1, VIEW, FOREIGN_TABLE };
108 
110 
112  int encoding_size,
113  const SqlType* column_type);
114 
115 void validate_and_set_dictionary_encoding(ColumnDescriptor& cd, int encoding_size);
116 
118 
119 void validate_and_set_sparse_encoding(ColumnDescriptor& cd, int encoding_size);
120 
121 void validate_and_set_compressed_encoding(ColumnDescriptor& cd, int encoding_size);
122 
123 void validate_and_set_date_encoding(ColumnDescriptor& cd, int encoding_size);
124 
126  const Encoding* encoding,
127  const SqlType* column_type);
128 
129 void validate_and_set_type(ColumnDescriptor& cd, SqlType* column_type);
130 
131 void validate_and_set_array_size(ColumnDescriptor& cd, const SqlType* column_type);
132 
134  const std::string* default_value,
135  bool not_null);
136 
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);
143 
144 void set_default_table_attributes(const std::string& table_name,
145  TableDescriptor& td,
146  const int32_t column_count);
147 
148 void validate_non_duplicate_column(const std::string& column_name,
149  std::unordered_set<std::string>& upper_column_names);
150 
151 void validate_non_reserved_keyword(const std::string& column_name);
152 
153 void validate_table_type(const TableDescriptor* td,
154  const TableType expected_table_type,
155  const std::string& command);
156 
157 std::string table_type_enum_to_string(const TableType table_type);
158 
170 void validate_allowed_file_path(const std::string& file_path,
171  const DataTransferType data_transfer_type,
172  const bool allow_wildcards = false);
173 
174 namespace alter_column_utils {
175 bool compare_sql_type_infos(const SQLTypeInfo& lhs, const SQLTypeInfo& rhs);
176 
182 };
183 
185  const ColumnDescriptor* rhs);
186 } // namespace alter_column_utils
187 
188 } // namespace ddl_utils
DataTransferType
Definition: DdlUtils.h:80
void validate_and_set_sparse_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:416
static std::vector< std::string > whitelisted_export_paths_
Definition: DdlUtils.h:94
SQLTypes
Definition: sqltypes.h:65
SqlType(SQLTypes type, int param1, int param2, bool is_array, int array_size)
Definition: DdlUtils.cpp:73
CompareResult compare_column_descriptors(const ColumnDescriptor *lhs, const ColumnDescriptor *rhs)
Definition: DdlUtils.cpp:52
void validate_and_set_array_size(ColumnDescriptor &cd, const SqlType *column_type)
Definition: DdlUtils.cpp:531
virtual void check_type()
Definition: DdlUtils.cpp:188
static void initialize(const std::string &data_dir, const std::string &allowed_import_paths, const std::string &allowed_export_paths)
Definition: DdlUtils.cpp:878
void validate_and_set_dictionary_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:379
virtual int get_encoding_param() const
Definition: DdlUtils.cpp:247
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:728
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:698
void validate_and_set_none_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:405
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:472
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:903
void set_default_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:251
SQLTypes type
Definition: DdlUtils.h:54
virtual ~Encoding()
Definition: DdlUtils.h:70
virtual SQLTypes get_type() const
Definition: DdlUtils.cpp:80
virtual std::string to_string() const
Definition: DdlUtils.cpp:112
void validate_non_reserved_keyword(const std::string &column_name)
Definition: DdlUtils.cpp:737
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:714
void validate_allowed_file_path(const std::string &file_path, const DataTransferType data_transfer_type, const bool allow_wildcards)
Definition: DdlUtils.cpp:822
void validate_and_set_compressed_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:433
bool compare_sql_type_infos(const SQLTypeInfo &lhs, const SQLTypeInfo &rhs)
Definition: DdlUtils.cpp:40
virtual const std::string * get_encoding_name() const
Definition: DdlUtils.cpp:243
void validate_and_set_fixed_encoding(ColumnDescriptor &cd, int encoding_size, const SqlType *column_type)
Definition: DdlUtils.cpp:281
std::string table_type_enum_to_string(const TableType table_type)
Definition: DdlUtils.cpp:762
Encoding(std::string *encoding_name, int encoding_param)
Definition: DdlUtils.cpp:240
virtual void set_param1(int param)
Definition: DdlUtils.cpp:88
static bool isBlacklistedPath(const std::string &path)
Definition: DdlUtils.cpp:930
void validate_table_type(const TableDescriptor *td, const TableType expected_table_type, const std::string &command)
Definition: DdlUtils.cpp:745
void validate_and_set_default_value(ColumnDescriptor &cd, const std::string *default_value, bool not_null)
Definition: DdlUtils.cpp:677
void validate_and_set_date_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:453
static void addToBlacklist(const std::string &path)
Definition: DdlUtils.cpp:925
std::unique_ptr< std::string > encoding_name
Definition: DdlUtils.h:76
virtual void set_is_array(bool a)
Definition: DdlUtils.cpp:100
virtual int get_param1() const
Definition: DdlUtils.cpp:84
virtual int get_param2() const
Definition: DdlUtils.cpp:92
virtual bool get_is_array() const
Definition: DdlUtils.cpp:96
virtual void set_array_size(int s)
Definition: DdlUtils.cpp:108
static std::vector< std::string > blacklisted_paths_
Definition: DdlUtils.h:104
virtual int get_array_size() const
Definition: DdlUtils.cpp:104
void validate_and_set_type(ColumnDescriptor &cd, SqlType *column_type)
Definition: DdlUtils.cpp:508