OmniSciDB  2e3a973ef4
DdlUtils.h
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 #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 initializeFromConfigFile(const std::string& server_config_path);
85  static void validateWhitelistedFilePath(
86  const std::vector<std::string>& expanded_file_paths,
87  const DataTransferType data_transfer_type);
88  static void clear();
89 
90  private:
91  static std::vector<std::string> whitelisted_import_paths_;
92  static std::vector<std::string> whitelisted_export_paths_;
93 };
94 
96  public:
97  static void addToBlacklist(const std::string& path);
98  static bool isBlacklistedPath(const std::string& path);
99  static void clear();
100 
101  private:
102  static std::vector<std::string> blacklisted_paths_;
103 };
104 
105 enum class TableType { TABLE = 1, VIEW, FOREIGN_TABLE };
106 
108 
110  int encoding_size,
111  const SqlType* column_type);
112 
113 void validate_and_set_dictionary_encoding(ColumnDescriptor& cd, int encoding_size);
114 
116 
117 void validate_and_set_sparse_encoding(ColumnDescriptor& cd, int encoding_size);
118 
119 void validate_and_set_compressed_encoding(ColumnDescriptor& cd, int encoding_size);
120 
121 void validate_and_set_date_encoding(ColumnDescriptor& cd, int encoding_size);
122 
124  const Encoding* encoding,
125  const SqlType* column_type);
126 
127 void validate_and_set_type(ColumnDescriptor& cd, SqlType* column_type);
128 
129 void validate_and_set_array_size(ColumnDescriptor& cd, const SqlType* column_type);
130 
131 void set_column_descriptor(const std::string& column_name,
132  ColumnDescriptor& cd,
133  SqlType* column_type,
134  const bool not_null,
135  const Encoding* encoding);
136 
137 void set_default_table_attributes(const std::string& table_name,
138  TableDescriptor& td,
139  const int32_t column_count);
140 
141 void validate_non_duplicate_column(const std::string& column_name,
142  std::unordered_set<std::string>& upper_column_names);
143 
144 void validate_non_reserved_keyword(const std::string& column_name);
145 
147  const TableType expected_table_type);
148 
149 std::string table_type_enum_to_string(const TableType table_type);
150 
162 void validate_allowed_file_path(const std::string& file_path,
163  const DataTransferType data_transfer_type,
164  const bool allow_wildcards = false);
165 } // namespace ddl_utils
virtual int get_array_size() const
Definition: DdlUtils.cpp:66
DataTransferType
Definition: DdlUtils.h:80
void validate_and_set_sparse_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:360
static std::vector< std::string > whitelisted_export_paths_
Definition: DdlUtils.h:92
SQLTypes
Definition: sqltypes.h:40
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:467
virtual void check_type()
Definition: DdlUtils.cpp:150
void validate_and_set_dictionary_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:323
virtual int get_param2() const
Definition: DdlUtils.cpp:54
Constants for Builtin SQL Types supported by OmniSci.
void validate_non_duplicate_column(const std::string &column_name, std::unordered_set< std::string > &upper_column_names)
Definition: DdlUtils.cpp:520
void validate_and_set_none_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:349
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:412
static std::vector< std::string > whitelisted_import_paths_
Definition: DdlUtils.h:91
void set_default_encoding(ColumnDescriptor &cd)
Definition: DdlUtils.cpp:210
SQLTypes type
Definition: DdlUtils.h:54
virtual ~Encoding()
Definition: DdlUtils.h:70
void validate_non_reserved_keyword(const std::string &column_name)
Definition: DdlUtils.cpp:529
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:506
void validate_allowed_file_path(const std::string &file_path, const DataTransferType data_transfer_type, const bool allow_wildcards)
Definition: DdlUtils.cpp:611
void set_column_descriptor(const std::string &column_name, ColumnDescriptor &cd, SqlType *column_type, const bool not_null, const Encoding *encoding)
Definition: DdlUtils.cpp:492
void validate_and_set_compressed_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:377
void validate_drop_table_type(const TableDescriptor *td, const TableType expected_table_type)
Definition: DdlUtils.cpp:537
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:553
virtual void set_param1(int param)
Definition: DdlUtils.cpp:50
virtual int get_param1() const
Definition: DdlUtils.cpp:46
virtual bool get_is_array() const
Definition: DdlUtils.cpp:58
void validate_and_set_date_encoding(ColumnDescriptor &cd, int encoding_size)
Definition: DdlUtils.cpp:397
virtual std::string to_string() const
Definition: DdlUtils.cpp:74
std::unique_ptr< std::string > encoding_name
Definition: DdlUtils.h:76
virtual void set_is_array(bool a)
Definition: DdlUtils.cpp:62
specifies the content in-memory of a row in the table metadata table
virtual SQLTypes get_type() const
Definition: DdlUtils.cpp:42
virtual void set_array_size(int s)
Definition: DdlUtils.cpp:70
static std::vector< std::string > blacklisted_paths_
Definition: DdlUtils.h:102
void validate_and_set_type(ColumnDescriptor &cd, SqlType *column_type)
Definition: DdlUtils.cpp:448