OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RegexParserDataWrapper.cpp
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 #include "RegexParserDataWrapper.h"
21 
22 namespace foreign_storage {
24  : AbstractTextFileDataWrapper(), regex_file_buffer_parser_{nullptr} {}
25 
27  const ForeignTable* foreign_table)
28  : AbstractTextFileDataWrapper(db_id, foreign_table)
29  , regex_file_buffer_parser_{foreign_table} {}
30 
32  const ForeignTable* foreign_table,
33  const UserMapping* user_mapping,
34  const bool disable_cache)
35  : AbstractTextFileDataWrapper(db_id, foreign_table, user_mapping, disable_cache)
36  , regex_file_buffer_parser_{foreign_table} {}
37 
38 namespace {
39 void validate_regex(const std::string& regex, const std::string& option_name) {
40  try {
41  boost::regex{regex};
42  } catch (const std::exception& e) {
43  throw ForeignStorageException{"Error parsing " + option_name + " \"" + regex +
44  "\": " + e.what()};
45  }
46 }
47 } // namespace
48 
50  const ForeignTable* foreign_table) const {
52  auto line_regex_it = foreign_table->options.find(RegexFileBufferParser::LINE_REGEX_KEY);
53  if (line_regex_it == foreign_table->options.end() || line_regex_it->second.empty()) {
55  "Foreign table options must contain a non-empty value for \"" +
57  }
59 
60  auto line_start_regex_it =
62  if (line_start_regex_it != foreign_table->options.end()) {
63  if (line_start_regex_it->second.empty()) {
64  throw ForeignStorageException{"Foreign table option \"" +
66  "\", when set, must contain a non-empty value."};
67  }
68  validate_regex(line_start_regex_it->second,
70  }
71 }
72 
73 const std::set<std::string_view>& RegexParserDataWrapper::getSupportedTableOptions()
74  const {
75  static const auto supported_table_options = getAllRegexTableOptions();
76  return supported_table_options;
77 }
78 
79 std::set<std::string_view> RegexParserDataWrapper::getAllRegexTableOptions() const {
80  std::set<std::string_view> supported_table_options(
83  supported_table_options.insert(regex_table_options_.begin(),
84  regex_table_options_.end());
85  return supported_table_options;
86 }
87 
90 }
91 
92 const std::set<std::string_view> RegexParserDataWrapper::regex_table_options_{
97 } // namespace foreign_storage
const RegexFileBufferParser regex_file_buffer_parser_
std::set< std::string_view > getAllRegexTableOptions() const
static const std::set< std::string_view > regex_table_options_
void validateTableOptions(const ForeignTable *foreign_table) const override
const std::set< std::string_view > & getSupportedTableOptions() const override
const TextFileBufferParser & getFileBufferParser() const override
void validateTableOptions(const ForeignTable *foreign_table) const override
const std::set< std::string_view > & getSupportedTableOptions() const override
void validate_regex(const std::string &regex, const std::string &option_name)