OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
foreign_storage::ForeignDataWrapperFactory Class Reference

#include <ForeignDataWrapperFactory.h>

Static Public Member Functions

static std::unique_ptr
< ForeignDataWrapper
create (const std::string &data_wrapper_type, const int db_id, const ForeignTable *foreign_table)
 
static const ForeignDataWrappercreateForValidation (const std::string &data_wrapper_type, const ForeignTable *foreign_table=nullptr)
 
static void validateDataWrapperType (const std::string &data_wrapper_type)
 

Static Private Attributes

static std::map< std::string,
std::unique_ptr
< ForeignDataWrapper > > 
validation_data_wrappers_
 

Detailed Description

Definition at line 34 of file ForeignDataWrapperFactory.h.

Member Function Documentation

std::unique_ptr< ForeignDataWrapper > foreign_storage::ForeignDataWrapperFactory::create ( const std::string &  data_wrapper_type,
const int  db_id,
const ForeignTable foreign_table 
)
static

Creates an instance of a ForeignDataWrapper for the given data wrapper type using provided database and foreign table details.

Definition at line 27 of file ForeignDataWrapperFactory.cpp.

References foreign_storage::DataWrapperType::CSV, foreign_storage::DataWrapperType::PARQUET, UNREACHABLE, and foreign_storage::Csv::validate_and_get_is_s3_select().

30  {
31  std::unique_ptr<ForeignDataWrapper> data_wrapper;
32  if (data_wrapper_type == DataWrapperType::CSV) {
33  if (Csv::validate_and_get_is_s3_select(foreign_table)) {
34  UNREACHABLE();
35  } else {
36  data_wrapper = std::make_unique<CsvDataWrapper>(db_id, foreign_table);
37  }
38 #ifdef ENABLE_IMPORT_PARQUET
39  } else if (data_wrapper_type == DataWrapperType::PARQUET) {
40  data_wrapper = std::make_unique<ParquetDataWrapper>(db_id, foreign_table);
41 #endif
42  } else {
43  throw std::runtime_error("Unsupported data wrapper");
44  }
45  return data_wrapper;
46 }
#define UNREACHABLE()
Definition: Logger.h:247
static constexpr char const * CSV
bool validate_and_get_is_s3_select(const ForeignTable *foreign_table)
Definition: CsvShared.cpp:93
static constexpr char const * PARQUET

+ Here is the call graph for this function:

const ForeignDataWrapper & foreign_storage::ForeignDataWrapperFactory::createForValidation ( const std::string &  data_wrapper_type,
const ForeignTable foreign_table = nullptr 
)
static

Creates an instance (or gets an existing instance) of an immutable ForeignDataWrapper to be used for validation purposes. Returned instance should not be used for any stateful operations, such as fetching foreign table data/metadata.

Definition at line 48 of file ForeignDataWrapperFactory.cpp.

References CHECK, foreign_storage::DataWrapperType::CSV, foreign_storage::DataWrapperType::PARQUET, UNREACHABLE, foreign_storage::Csv::validate_and_get_is_s3_select(), and validation_data_wrappers_.

Referenced by foreign_storage::ForeignServer::validateStorageParameters().

50  {
51  bool is_s3_select_wrapper{false};
52  std::string data_wrapper_type_key{data_wrapper_type};
53  constexpr const char* S3_SELECT_WRAPPER_KEY = "CSV_S3_SELECT";
54  if (foreign_table && data_wrapper_type == DataWrapperType::CSV &&
55  Csv::validate_and_get_is_s3_select(foreign_table)) {
56  is_s3_select_wrapper = true;
57  data_wrapper_type_key = S3_SELECT_WRAPPER_KEY;
58  }
59 
60  if (validation_data_wrappers_.find(data_wrapper_type_key) ==
62  if (data_wrapper_type == DataWrapperType::CSV) {
63  if (is_s3_select_wrapper) {
64  UNREACHABLE();
65  } else {
66  validation_data_wrappers_[data_wrapper_type_key] =
67  std::make_unique<CsvDataWrapper>();
68  }
69  } else if (data_wrapper_type == DataWrapperType::PARQUET) {
70  validation_data_wrappers_[data_wrapper_type_key] =
71  std::make_unique<ParquetDataWrapper>();
72  } else {
73  UNREACHABLE();
74  }
75  }
76  CHECK(validation_data_wrappers_.find(data_wrapper_type_key) !=
78  return *validation_data_wrappers_[data_wrapper_type_key];
79 }
#define UNREACHABLE()
Definition: Logger.h:247
static std::map< std::string, std::unique_ptr< ForeignDataWrapper > > validation_data_wrappers_
#define CHECK(condition)
Definition: Logger.h:203
static constexpr char const * CSV
bool validate_and_get_is_s3_select(const ForeignTable *foreign_table)
Definition: CsvShared.cpp:93
static constexpr char const * PARQUET

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void foreign_storage::ForeignDataWrapperFactory::validateDataWrapperType ( const std::string &  data_wrapper_type)
static

Checks that the given data wrapper type is valid.

Definition at line 81 of file ForeignDataWrapperFactory.cpp.

References join(), and foreign_storage::DataWrapperType::supported_data_wrapper_types.

Referenced by foreign_storage::ForeignServer::validate().

82  {
83  const auto& supported_wrapper_types = DataWrapperType::supported_data_wrapper_types;
84  if (std::find(supported_wrapper_types.begin(),
85  supported_wrapper_types.end(),
86  data_wrapper_type) == supported_wrapper_types.end()) {
87  throw std::runtime_error{"Invalid data wrapper type \"" + data_wrapper_type +
88  "\". Data wrapper type must be one of the following: " +
89  join(supported_wrapper_types, ", ") + "."};
90  }
91 }
std::string join(T const &container, std::string const &delim)
static constexpr std::array< std::string_view, 2 > supported_data_wrapper_types

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::map< std::string, std::unique_ptr< ForeignDataWrapper > > foreign_storage::ForeignDataWrapperFactory::validation_data_wrappers_
staticprivate

Definition at line 60 of file ForeignDataWrapperFactory.h.

Referenced by createForValidation().


The documentation for this class was generated from the following files: