OmniSciDB  a987f07e93
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ForeignDataWrapperFactory.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 
20 #include "ForeignDataWrapper.h"
22 
23 namespace foreign_storage {
24 class UserMapping;
25 
26 bool is_s3_uri(const std::string& file_path);
27 
31 bool is_valid_source_type(const import_export::CopyParams& copy_params);
32 
34 
47 std::tuple<std::unique_ptr<foreign_storage::ForeignServer>,
48  std::unique_ptr<foreign_storage::UserMapping>,
49  std::unique_ptr<foreign_storage::ForeignTable>>
50 create_proxy_fsi_objects(const std::string& copy_from_source,
51  const import_export::CopyParams& copy_params,
52  const int db_id,
53  const TableDescriptor* table,
54  const int32_t user_id);
55 
60 std::tuple<std::unique_ptr<foreign_storage::ForeignServer>,
61  std::unique_ptr<foreign_storage::UserMapping>,
62  std::unique_ptr<foreign_storage::ForeignTable>>
63 create_proxy_fsi_objects(const std::string& copy_from_source,
64  const import_export::CopyParams& copy_params,
65  const TableDescriptor* table);
66 
72  static constexpr char const* CSV = "DELIMITED_FILE";
73  static constexpr char const* PARQUET = "PARQUET_FILE";
74  static constexpr char const* REGEX_PARSER = "REGEX_PARSED_FILE";
75  static constexpr char const* INTERNAL_CATALOG = "INTERNAL_CATALOG";
76  static constexpr char const* INTERNAL_MEMORY_STATS = "INTERNAL_MEMORY_STATS";
77  static constexpr char const* INTERNAL_STORAGE_STATS = "INTERNAL_STORAGE_STATS";
78  static constexpr char const* INTERNAL_LOGS = "INTERNAL_LOGS";
79 
80  static constexpr std::array<char const*, 4> INTERNAL_DATA_WRAPPERS{
85 
86  static constexpr std::array<char const*, 3> IN_MEMORY_DATA_WRAPPERS{
90 
91  static constexpr std::array<std::string_view, 7> supported_data_wrapper_types{
92  PARQUET,
93  CSV,
99 };
100 
102  public:
107  static std::unique_ptr<ForeignDataWrapper> create(const std::string& data_wrapper_type,
108  const int db_id,
109  const ForeignTable* foreign_table);
110 
111  static std::unique_ptr<UserMapping> createUserMappingProxyIfApplicable(
112  const int db_id,
113  const int user_id,
114  const std::string& file_path,
115  const import_export::CopyParams& copy_params,
116  const ForeignServer* server);
117 
118  static std::unique_ptr<ForeignServer> createForeignServerProxy(
119  const int db_id,
120  const int user_id,
121  const std::string& file_path,
122  const import_export::CopyParams& copy_params);
123 
124  static std::unique_ptr<ForeignTable> createForeignTableProxy(
125  const int db_id,
126  const TableDescriptor* table,
127  const std::string& file_path,
128  const import_export::CopyParams& copy_params,
129  const ForeignServer* server);
130 
134  static std::unique_ptr<ForeignDataWrapper> createForImport(
135  const std::string& data_wrapper_type,
136  const int db_id,
137  const ForeignTable* foreign_table,
138  const UserMapping* user_mapping);
139 
140  static std::unique_ptr<ForeignDataWrapper> createForGeneralImport(
141  const import_export::CopyParams& copy_params,
142  const int db_id,
143  const ForeignTable* foreign_table,
144  const UserMapping* user_mapping);
145 
152  const std::string& data_wrapper_type,
153  const ForeignTable* foreign_table = nullptr);
154 
158  static void validateDataWrapperType(const std::string& data_wrapper_type);
159 
160  private:
161  static std::map<std::string, std::unique_ptr<ForeignDataWrapper>>
163 };
164 } // namespace foreign_storage
static const ForeignDataWrapper & createForValidation(const std::string &data_wrapper_type, const ForeignTable *foreign_table=nullptr)
static std::unique_ptr< ForeignDataWrapper > createForImport(const std::string &data_wrapper_type, const int db_id, const ForeignTable *foreign_table, const UserMapping *user_mapping)
static constexpr char const * REGEX_PARSER
static std::unique_ptr< ForeignDataWrapper > create(const std::string &data_wrapper_type, const int db_id, const ForeignTable *foreign_table)
static constexpr char const * INTERNAL_STORAGE_STATS
static constexpr std::array< std::string_view, 7 > supported_data_wrapper_types
static constexpr std::array< char const *, 4 > INTERNAL_DATA_WRAPPERS
static constexpr char const * INTERNAL_CATALOG
std::tuple< std::unique_ptr< foreign_storage::ForeignServer >, std::unique_ptr< foreign_storage::UserMapping >, std::unique_ptr< foreign_storage::ForeignTable > > create_proxy_fsi_objects(const std::string &copy_from_source, const import_export::CopyParams &copy_params, const int db_id, const TableDescriptor *table, const int32_t user_id)
Create proxy fsi objects for use outside FSI.
static std::map< std::string, std::unique_ptr< ForeignDataWrapper > > validation_data_wrappers_
static std::unique_ptr< ForeignDataWrapper > createForGeneralImport(const import_export::CopyParams &copy_params, const int db_id, const ForeignTable *foreign_table, const UserMapping *user_mapping)
static void validateDataWrapperType(const std::string &data_wrapper_type)
Encapsulates an enumeration of foreign data wrapper type strings.
bool is_valid_source_type(const import_export::CopyParams &copy_params)
bool is_s3_uri(const std::string &file_path)
static constexpr std::array< char const *, 3 > IN_MEMORY_DATA_WRAPPERS
void validate_regex_parser_options(const import_export::CopyParams &copy_params)
static std::unique_ptr< ForeignServer > createForeignServerProxy(const int db_id, const int user_id, const std::string &file_path, const import_export::CopyParams &copy_params)
static constexpr char const * INTERNAL_MEMORY_STATS
static std::unique_ptr< ForeignTable > createForeignTableProxy(const int db_id, const TableDescriptor *table, const std::string &file_path, const import_export::CopyParams &copy_params, const ForeignServer *server)
static constexpr char const * CSV
static constexpr char const * INTERNAL_LOGS
static constexpr char const * PARQUET
static std::unique_ptr< UserMapping > createUserMappingProxyIfApplicable(const int db_id, const int user_id, const std::string &file_path, const import_export::CopyParams &copy_params, const ForeignServer *server)