OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
26  ForeignTable();
27 
28  ForeignTable(const int32_t id,
29  const ForeignServer* server,
30  const std::string& options_str,
31  const int64_t last_refresh,
32  const int64_t next_refresh)
33  : OptionsContainer(options_str)
34  , foreign_server(server)
35  , last_refresh_time(last_refresh)
36  , next_refresh_time(next_refresh) {
37  tableId = id;
38  }
39 
40  // Option keys
41  static constexpr const char* FRAGMENT_SIZE_KEY = "FRAGMENT_SIZE";
42  static constexpr const char* REFRESH_TIMING_TYPE_KEY = "REFRESH_TIMING_TYPE";
43  static constexpr const char* REFRESH_START_DATE_TIME_KEY = "REFRESH_START_DATE_TIME";
44  static constexpr const char* REFRESH_INTERVAL_KEY = "REFRESH_INTERVAL";
45  static constexpr const char* REFRESH_UPDATE_TYPE_KEY = "REFRESH_UPDATE_TYPE";
46  static constexpr const char* BUFFER_SIZE_KEY = "BUFFER_SIZE";
47  // Option values
48  static constexpr const char* ALL_REFRESH_UPDATE_TYPE = "ALL";
49  static constexpr const char* APPEND_REFRESH_UPDATE_TYPE = "APPEND";
50  static constexpr const char* SCHEDULE_REFRESH_TIMING_TYPE = "SCHEDULED";
51  static constexpr const char* MANUAL_REFRESH_TIMING_TYPE = "MANUAL";
52  static constexpr int NULL_REFRESH_TIME = -1;
53 
56 
57  inline static const std::set<const char*> supported_options{FRAGMENT_SIZE_KEY,
62 
63  inline static const std::set<const char*> upper_case_options{
68 
69  // We don't want all options to be alterable, so this contains a subset.
70  inline static const std::set<const char*> alterable_options{REFRESH_TIMING_TYPE_KEY,
75 
79  void validateOptionValues() const;
80 
88  void initializeOptions();
89 
95  void initializeOptions(const rapidjson::Value& options);
96 
101  void validateSupportedOptionKeys(const OptionsMap& options_map) const;
102 
106  bool isAppendMode() const;
107 
112  static OptionsMap createOptionsMap(const rapidjson::Value& json_options);
113 
118  static void validateAlterOptions(const OptionsMap& options_map);
119 
123  void validateSchema(const std::list<ColumnDescriptor>& columns) const;
124 
125  private:
126  void validateDataWrapperOptions() const;
127  void validateRefreshOptionValues() const;
128 };
129 } // namespace foreign_storage
static void validateAlterOptions(const OptionsMap &options_map)
Verifies that the given options map only contains options that can be legally altered.
void validateDataWrapperOptions() const
static constexpr const char * BUFFER_SIZE_KEY
Definition: ForeignTable.h:46
static const std::set< const char * > supported_options
Definition: ForeignTable.h:57
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...
static constexpr const char * MANUAL_REFRESH_TIMING_TYPE
Definition: ForeignTable.h:51
static OptionsMap createOptionsMap(const rapidjson::Value &json_options)
Creates an options map from given options. Converts options that must be upper case appropriately...
static constexpr const char * REFRESH_START_DATE_TIME_KEY
Definition: ForeignTable.h:43
static constexpr const char * REFRESH_UPDATE_TYPE_KEY
Definition: ForeignTable.h:45
static constexpr const char * REFRESH_INTERVAL_KEY
Definition: ForeignTable.h:44
void validateRefreshOptionValues() const
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:28
bool isAppendMode() const
Checks if the table is in append mode.
void validateSchema(const std::list< ColumnDescriptor > &columns) const
Verifies the schema is supported by this foreign table.
static const std::set< const char * > alterable_options
Definition: ForeignTable.h:70
static constexpr const char * ALL_REFRESH_UPDATE_TYPE
Definition: ForeignTable.h:48
static constexpr const char * FRAGMENT_SIZE_KEY
Definition: ForeignTable.h:41
static constexpr const char * APPEND_REFRESH_UPDATE_TYPE
Definition: ForeignTable.h:49
const ForeignServer * foreign_server
Definition: ForeignTable.h:54
static constexpr const char * REFRESH_TIMING_TYPE_KEY
Definition: ForeignTable.h:42
std::map< std::string, std::string, std::less<>> OptionsMap
static constexpr int NULL_REFRESH_TIME
Definition: ForeignTable.h:52
static constexpr const char * SCHEDULE_REFRESH_TIMING_TYPE
Definition: ForeignTable.h:50
static const std::set< const char * > upper_case_options
Definition: ForeignTable.h:63