OmniSciDB  a667adc9c8
 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 25 of file ForeignDataWrapperFactory.cpp.

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

28  {
29  std::unique_ptr<ForeignDataWrapper> data_wrapper;
30  if (data_wrapper_type == DataWrapperType::CSV) {
31  if (Csv::validate_and_get_is_s3_select(foreign_table)) {
32  UNREACHABLE();
33  } else {
34  data_wrapper = std::make_unique<CsvDataWrapper>(db_id, foreign_table);
35  }
36  } else if (data_wrapper_type == DataWrapperType::PARQUET) {
37  data_wrapper = std::make_unique<ParquetDataWrapper>(db_id, foreign_table);
38  } else {
39  throw std::runtime_error("Unsupported data wrapper");
40  }
41  return data_wrapper;
42 }
#define UNREACHABLE()
Definition: Logger.h:241
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 44 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().

46  {
47  bool is_s3_select_wrapper{false};
48  std::string data_wrapper_type_key{data_wrapper_type};
49  constexpr const char* S3_SELECT_WRAPPER_KEY = "CSV_S3_SELECT";
50  if (foreign_table && data_wrapper_type == DataWrapperType::CSV &&
51  Csv::validate_and_get_is_s3_select(foreign_table)) {
52  is_s3_select_wrapper = true;
53  data_wrapper_type_key = S3_SELECT_WRAPPER_KEY;
54  }
55 
56  if (validation_data_wrappers_.find(data_wrapper_type_key) ==
58  if (data_wrapper_type == DataWrapperType::CSV) {
59  if (is_s3_select_wrapper) {
60  UNREACHABLE();
61  } else {
62  validation_data_wrappers_[data_wrapper_type_key] =
63  std::make_unique<CsvDataWrapper>();
64  }
65  } else if (data_wrapper_type == DataWrapperType::PARQUET) {
66  validation_data_wrappers_[data_wrapper_type_key] =
67  std::make_unique<ParquetDataWrapper>();
68  } else {
69  UNREACHABLE();
70  }
71  }
72  CHECK(validation_data_wrappers_.find(data_wrapper_type_key) !=
74  return *validation_data_wrappers_[data_wrapper_type_key];
75 }
#define UNREACHABLE()
Definition: Logger.h:241
static std::map< std::string, std::unique_ptr< ForeignDataWrapper > > validation_data_wrappers_
#define CHECK(condition)
Definition: Logger.h:197
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 77 of file ForeignDataWrapperFactory.cpp.

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

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

78  {
79  const auto& supported_wrapper_types = DataWrapperType::supported_data_wrapper_types;
80  if (std::find(supported_wrapper_types.begin(),
81  supported_wrapper_types.end(),
82  data_wrapper_type) == supported_wrapper_types.end()) {
83  throw std::runtime_error{"Invalid data wrapper type \"" + data_wrapper_type +
84  "\". Data wrapper type must be one of the following: " +
85  join(supported_wrapper_types, ", ") + "."};
86  }
87 }
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: