18 #include <boost/algorithm/string/predicate.hpp>
28 namespace foreign_storage {
53 return (update_mode !=
options.end() &&
59 std::optional<std::string> base_path{};
69 CHECK(file_path || base_path);
70 const std::string separator{boost::filesystem::path::preferred_separator};
71 return std::regex_replace(
72 (base_path ? *base_path + separator :
"") + (file_path ? *file_path :
""),
73 std::regex{separator +
"{2,}"},
82 CHECK(storage_type) <<
"No storage type found in parent server. Server \""
114 for (
const auto& [key, value] : options_map) {
116 throw std::runtime_error{
"Invalid foreign table option \"" + key +
"\"."};
122 auto update_type_entry =
124 CHECK(update_type_entry != options.end());
125 auto update_type_value = update_type_entry->second;
128 std::string error_message =
132 throw std::runtime_error{error_message};
135 auto refresh_timing_entry =
137 CHECK(refresh_timing_entry != options.end());
138 if (
auto refresh_timing_value = refresh_timing_entry->second;
141 if (start_date_entry == options.end()) {
143 " option must be provided for scheduled refreshes."};
145 auto start_date_time = dateTimeParse<kTIMESTAMP>(start_date_entry->second, 0);
146 int64_t current_time = std::chrono::duration_cast<std::chrono::seconds>(
147 std::chrono::system_clock::now().time_since_epoch())
149 if (start_date_time < current_time) {
151 " cannot be a past date time."};
155 if (interval_entry != options.end()) {
156 std::string interval_types{
"HD"};
158 interval_types +=
"S";
160 boost::regex interval_regex{
"^\\d{1,}[" + interval_types +
"]$",
161 boost::regex::extended | boost::regex::icase};
162 if (!boost::regex_match(interval_entry->second, interval_regex)) {
163 throw std::runtime_error{
"Invalid value provided for the " +
168 throw std::runtime_error{
"Invalid value provided for the " +
178 throw std::runtime_error(
179 "Cannot create S3 backed foreign table as AWS S3 support is currently disabled.");
197 CHECK(json_options.IsObject());
198 for (
const auto& member : json_options.GetObject()) {
199 auto key =
to_upper(member.name.GetString());
202 options_map[key] =
to_upper(member.value.GetString());
204 options_map[key] = member.value.GetString();
211 for (
const auto& [key, value] : options_map) {
213 throw std::runtime_error{std::string(
"Altering foreign table option \"") + key +
214 "\" is not currently supported."};
220 std::stringstream ss;
221 ss <<
"No file_path found for Foreign Table \"" <<
tableName
222 <<
"\". Table must have either set a \"" <<
FILE_PATH_KEY <<
"\" option, or its "
223 <<
"parent server must have set a \"" << missing_path <<
"\" option.";
224 throw std::runtime_error(ss.str());
void validateDataWrapperOptions() const
static const std::set< const char * > supported_options
static constexpr std::string_view S3_STORAGE_TYPE
static std::vector< std::string_view > getSupportedOptions()
static std::vector< std::string_view > getSupportedOptions()
static void validateOptions(const ForeignTable *foreign_table)
void initializeOptions()
Creates an empty option map for the table. Verifies that the required option keys are present and tha...
void validateOptionValues() const
Verifies the values for mapped options are valid.
void validateSupportedOptionKeys(const OptionsMap &options_map) const
Verifies that the options_map contains the keys required by a foreign table; including those specifie...
bool contains(const T &set, const std::string_view element)
static constexpr const char * MANUAL_REFRESH_TIMING_TYPE
void throwFilePathError(const std::string_view &missing_path) const
static void validate_alter_options(const OptionsMap &options_map)
Verifies that the given options map only contains options that can be legally altered.
static constexpr std::string_view STORAGE_TYPE_KEY
static constexpr const char * REFRESH_START_DATE_TIME_KEY
static constexpr const char * REFRESH_UPDATE_TYPE_KEY
void populateOptionsMap(OptionsMap &&options_map, bool clear=false)
static constexpr const char * REFRESH_INTERVAL_KEY
void validateRefreshOptionValues() const
std::optional< std::string > getOption(const std::string_view &key) const
bool isAppendMode() const
Checks if the table is in append mode.
std::vector< std::string_view > getSupportedDataWrapperOptions() const
Returns the list of required data wrapper options based on the type of data wrapper.
static const std::set< const char * > alterable_options
bool g_enable_seconds_refresh
static constexpr const char * ALL_REFRESH_UPDATE_TYPE
static constexpr std::string_view LOCAL_FILE_STORAGE_TYPE
static OptionsMap create_options_map(const rapidjson::Value &json_options)
Creates an options map from given options. Converts options that must be upper case appropriately...
std::string data_wrapper_type
static constexpr const char * APPEND_REFRESH_UPDATE_TYPE
static constexpr const char * FILE_PATH_KEY
std::string getFullFilePath() const
Returns the path to the source file/dir of the table. Depending on options this may result from a con...
const ForeignServer * foreign_server
static constexpr const char * REFRESH_TIMING_TYPE_KEY
static constexpr std::string_view BASE_PATH_KEY
static constexpr char const * CSV
std::map< std::string, std::string, std::less<>> OptionsMap
static void validateOptions(const ForeignTable *foreign_table)
bool validate_and_get_is_s3_select(const ForeignTable *foreign_table)
static constexpr char const * PARQUET
static constexpr const char * SCHEDULE_REFRESH_TIMING_TYPE
void validateFilePathOptionKey() const
static const std::set< const char * > upper_case_options