OmniSciDB  340b00dbf6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ForeignTable.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, 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 
19 #include "ForeignServer.h"
20 #include "OptionsContainer.h"
21 #include "TableDescriptor.h"
22 
23 namespace foreign_storage {
24 
25 template <typename T>
26 bool contains(const T& set, const std::string_view element) {
27  if (std::find(set.begin(), set.end(), element) == set.end()) {
28  return false;
29  } else {
30  return true;
31  }
32 }
33 
35  ForeignTable();
36 
37  ForeignTable(const int32_t id,
38  const ForeignServer* server,
39  const std::string& options_str,
40  const int64_t last_refresh,
41  const int64_t next_refresh)
42  : OptionsContainer(options_str)
43  , foreign_server(server)
44  , last_refresh_time(last_refresh)
45  , next_refresh_time(next_refresh) {
46  tableId = id;
47  }
48 
49  // Option keys
50  static constexpr const char* FILE_PATH_KEY = "FILE_PATH";
51  static constexpr const char* FRAGMENT_SIZE_KEY = "FRAGMENT_SIZE";
52  static constexpr const char* REFRESH_TIMING_TYPE_KEY = "REFRESH_TIMING_TYPE";
53  static constexpr const char* REFRESH_START_DATE_TIME_KEY = "REFRESH_START_DATE_TIME";
54  static constexpr const char* REFRESH_INTERVAL_KEY = "REFRESH_INTERVAL";
55  static constexpr const char* REFRESH_UPDATE_TYPE_KEY = "REFRESH_UPDATE_TYPE";
56  // Option values
57  static constexpr const char* ALL_REFRESH_UPDATE_TYPE = "ALL";
58  static constexpr const char* APPEND_REFRESH_UPDATE_TYPE = "APPEND";
59  static constexpr const char* SCHEDULE_REFRESH_TIMING_TYPE = "SCHEDULED";
60  static constexpr const char* MANUAL_REFRESH_TIMING_TYPE = "MANUAL";
61  static constexpr int NULL_REFRESH_TIME = -1;
62 
65  inline static const std::set<const char*> supported_options{FILE_PATH_KEY,
71 
72  inline static const std::set<const char*> upper_case_options{
77 
78  // We don't want all options to be alterable, so this contains a subset.
79  inline static const std::set<const char*> alterable_options{REFRESH_TIMING_TYPE_KEY,
83 
84  void validateOptions() const;
85  void initializeOptions(const rapidjson::Value& options);
86  std::vector<std::string_view> getSupportedDataWrapperOptions() const;
87  void validateSupportedOptions(const OptionsMap& options_map) const;
88  bool isAppendMode() const;
89  std::string getFilePath() const;
90 
91  static OptionsMap create_options_map(const rapidjson::Value& json_options);
92  static void validate_alter_options(const OptionsMap& options_map);
93 
94  private:
95  void validateDataWrapperOptions() const;
96  void validateRefreshOptions() const;
97 };
98 } // namespace foreign_storage
void validateDataWrapperOptions() const
static const std::set< const char * > supported_options
Definition: ForeignTable.h:65
bool contains(const T &set, const std::string_view element)
Definition: ForeignTable.h:26
static constexpr const char * MANUAL_REFRESH_TIMING_TYPE
Definition: ForeignTable.h:60
static void validate_alter_options(const OptionsMap &options_map)
static constexpr const char * REFRESH_START_DATE_TIME_KEY
Definition: ForeignTable.h:53
static constexpr const char * REFRESH_UPDATE_TYPE_KEY
Definition: ForeignTable.h:55
void validateRefreshOptions() const
static constexpr const char * REFRESH_INTERVAL_KEY
Definition: ForeignTable.h:54
ForeignTable(const int32_t id, const ForeignServer *server, const std::string &options_str, const int64_t last_refresh, const int64_t next_refresh)
Definition: ForeignTable.h:37
std::vector< std::string_view > getSupportedDataWrapperOptions() const
std::string getFilePath() const
static const std::set< const char * > alterable_options
Definition: ForeignTable.h:79
static constexpr const char * ALL_REFRESH_UPDATE_TYPE
Definition: ForeignTable.h:57
static OptionsMap create_options_map(const rapidjson::Value &json_options)
void initializeOptions(const rapidjson::Value &options)
static constexpr const char * FRAGMENT_SIZE_KEY
Definition: ForeignTable.h:51
static constexpr const char * APPEND_REFRESH_UPDATE_TYPE
Definition: ForeignTable.h:58
static constexpr const char * FILE_PATH_KEY
Definition: ForeignTable.h:50
const ForeignServer * foreign_server
Definition: ForeignTable.h:63
static constexpr const char * REFRESH_TIMING_TYPE_KEY
Definition: ForeignTable.h:52
std::map< std::string, std::string, std::less<>> OptionsMap
static constexpr int NULL_REFRESH_TIME
Definition: ForeignTable.h:61
specifies the content in-memory of a row in the table metadata table
void validateSupportedOptions(const OptionsMap &options_map) const
static constexpr const char * SCHEDULE_REFRESH_TIMING_TYPE
Definition: ForeignTable.h:59
static const std::set< const char * > upper_case_options
Definition: ForeignTable.h:72