OmniSciDB  a5dc49c757
 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 2022 HEAVY.AI, 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* MAX_CHUNK_SIZE_KEY = "MAX_CHUNK_SIZE";
43  static constexpr const char* REFRESH_TIMING_TYPE_KEY = "REFRESH_TIMING_TYPE";
44  static constexpr const char* REFRESH_START_DATE_TIME_KEY = "REFRESH_START_DATE_TIME";
45  static constexpr const char* REFRESH_INTERVAL_KEY = "REFRESH_INTERVAL";
46  static constexpr const char* REFRESH_UPDATE_TYPE_KEY = "REFRESH_UPDATE_TYPE";
47  static constexpr const char* BUFFER_SIZE_KEY = "BUFFER_SIZE";
48  static constexpr const char* PARTITIONS_KEY = "PARTITIONS";
49  static constexpr const char* GEO_VALIDATE_GEOMETRY_KEY = "GEO_VALIDATE_GEOMETRY";
50  // Option values
51  static constexpr const char* ALL_REFRESH_UPDATE_TYPE = "ALL";
52  static constexpr const char* APPEND_REFRESH_UPDATE_TYPE = "APPEND";
53  static constexpr const char* SCHEDULE_REFRESH_TIMING_TYPE = "SCHEDULED";
54  static constexpr const char* MANUAL_REFRESH_TIMING_TYPE = "MANUAL";
55  static constexpr int NULL_REFRESH_TIME = -1;
56 
59 
60  inline static const std::set<const char*> supported_options{FRAGMENT_SIZE_KEY,
68 
69  inline static const std::set<const char*> upper_case_options{
74 
75  // We don't want all options to be alterable, so this contains a subset.
76  inline static const std::set<const char*> alterable_options{REFRESH_TIMING_TYPE_KEY,
82 
86  void validateOptionValues() const;
87 
95  void initializeOptions();
96 
102  void initializeOptions(const rapidjson::Value& options);
103 
108  void validateSupportedOptionKeys(const OptionsMap& options_map) const;
109 
113  bool isAppendMode() const;
114 
119  static OptionsMap createOptionsMap(const rapidjson::Value& json_options);
120 
125  void validateAlterOptions(const OptionsMap& options_map) const;
126 
130  void validateSchema(const std::list<ColumnDescriptor>& columns) const;
131 
132  private:
133  void validateDataWrapperOptions() const;
134  void validateRefreshOptionValues() const;
135 };
136 } // namespace foreign_storage
void validateDataWrapperOptions() const
static constexpr const char * BUFFER_SIZE_KEY
Definition: ForeignTable.h:47
static const std::set< const char * > supported_options
Definition: ForeignTable.h:60
void validateAlterOptions(const OptionsMap &options_map) const
Verifies that the given options map only contains options that can be legally altered.
void initializeOptions()
Creates an empty option map for the table. Verifies that the required option keys are present and tha...
static constexpr const char * MAX_CHUNK_SIZE_KEY
Definition: ForeignTable.h:42
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:54
static constexpr const char * PARTITIONS_KEY
Definition: ForeignTable.h:48
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:44
static constexpr const char * REFRESH_UPDATE_TYPE_KEY
Definition: ForeignTable.h:46
static constexpr const char * REFRESH_INTERVAL_KEY
Definition: ForeignTable.h:45
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 constexpr const char * GEO_VALIDATE_GEOMETRY_KEY
Definition: ForeignTable.h:49
static const std::set< const char * > alterable_options
Definition: ForeignTable.h:76
static constexpr const char * ALL_REFRESH_UPDATE_TYPE
Definition: ForeignTable.h:51
static constexpr const char * FRAGMENT_SIZE_KEY
Definition: ForeignTable.h:41
static constexpr const char * APPEND_REFRESH_UPDATE_TYPE
Definition: ForeignTable.h:52
const ForeignServer * foreign_server
Definition: ForeignTable.h:57
static constexpr const char * REFRESH_TIMING_TYPE_KEY
Definition: ForeignTable.h:43
std::map< std::string, std::string, std::less<>> OptionsMap
static constexpr int NULL_REFRESH_TIME
Definition: ForeignTable.h:55
static constexpr const char * SCHEDULE_REFRESH_TIMING_TYPE
Definition: ForeignTable.h:53
static const std::set< const char * > upper_case_options
Definition: ForeignTable.h:69