20 #include <unordered_map> 22 #include "rapidjson/document.h" 23 #include "rapidjson/stringbuffer.h" 24 #include "rapidjson/writer.h" 37 static constexpr
char const*
CSV =
"OMNISCI_CSV";
38 static constexpr
char const*
PARQUET =
"OMNISCI_PARQUET";
45 static constexpr std::string_view STORAGE_TYPE_KEY =
"STORAGE_TYPE";
46 static constexpr std::string_view BASE_PATH_KEY =
"BASE_PATH";
47 static constexpr std::string_view LOCAL_FILE_STORAGE_TYPE =
"LOCAL_FILE";
49 static constexpr std::string_view S3_STORAGE_TYPE =
"AWS_S3";
51 static constexpr std::array<std::string_view, 1> supported_storage_types{
52 LOCAL_FILE_STORAGE_TYPE};
54 static constexpr std::array<std::string_view, 2> all_option_keys{STORAGE_TYPE_KEY,
66 const std::string& server_name,
67 const std::string& data_wrapper_type,
68 const std::string& options_str,
69 const int32_t user_id,
70 const time_t creation_time)
74 , data_wrapper_type(data_wrapper_type)
76 , creation_time(creation_time) {}
79 const std::string& data_wrapper_type,
80 const std::map<std::string, std::string, std::less<>>& options,
81 const int32_t user_id)
84 , data_wrapper_type(data_wrapper_type)
88 validateDataWrapperType();
89 validateStorageParameters();
90 validateRecognizedOption();
96 if (std::find(supported_wrapper_types.begin(),
97 supported_wrapper_types.end(),
98 data_wrapper_type) == supported_wrapper_types.end()) {
99 throw std::runtime_error{
"Invalid data wrapper type \"" + data_wrapper_type +
100 "\". Data wrapper type must be one of the following: " +
101 join(supported_wrapper_types,
", ") +
"."};
106 if (options.find(STORAGE_TYPE_KEY) == options.end()) {
107 throw std::runtime_error{
"Foreign server options must contain \"STORAGE_TYPE\"."};
110 const auto& storage_type = options.find(STORAGE_TYPE_KEY)->second;
112 throw std::runtime_error{
113 "Foreign server storage type value of \"" + std::string{S3_STORAGE_TYPE} +
114 "\" is not allowed because FSI S3 support is currently disabled."};
115 }
else if (std::find(supported_storage_types.begin(),
116 supported_storage_types.end(),
117 storage_type) == supported_storage_types.end()) {
118 std::string error_message =
119 "Invalid storage type value. Value must be one of the following: " +
120 join(supported_storage_types,
", ") +
".";
121 throw std::runtime_error{error_message};
126 for (
const auto& entry : options) {
127 if (std::find(all_option_keys.begin(), all_option_keys.end(), entry.first) ==
128 all_option_keys.end()) {
129 std::string error_message =
130 "Invalid option \"" + entry.first +
"\"." +
131 " Option must be one of the following: " +
join(all_option_keys,
", ") +
".";
132 throw std::runtime_error{error_message};
void validateStorageParameters()
static constexpr std::array< std::string_view, 2 > supported_data_wrapper_types
Encapsulates an enumeration of foreign data wrapper type strings.
void validateDataWrapperType()
ForeignServer(const int32_t server_id, const std::string &server_name, const std::string &data_wrapper_type, const std::string &options_str, const int32_t user_id, const time_t creation_time)
std::string data_wrapper_type
ForeignServer(const std::string &server_name, const std::string &data_wrapper_type, const std::map< std::string, std::string, std::less<>> &options, const int32_t user_id)
static constexpr char const * CSV
void validateRecognizedOption()
static constexpr char const * PARQUET