OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CsvDataWrapper.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 "CsvDataWrapper.h"
18 
21 
22 namespace foreign_storage {
24 
25 CsvDataWrapper::CsvDataWrapper(const int db_id, const ForeignTable* foreign_table)
26  : AbstractTextFileDataWrapper(db_id, foreign_table) {}
27 
29  const ForeignTable* foreign_table,
30  const UserMapping* user_mapping,
31  const bool disable_cache)
32  : AbstractTextFileDataWrapper(db_id, foreign_table, user_mapping, disable_cache) {}
33 
34 void CsvDataWrapper::validateTableOptions(const ForeignTable* foreign_table) const {
37  validateAndGetIsS3Select(foreign_table);
38 }
39 
40 const std::set<std::string_view>& CsvDataWrapper::getSupportedTableOptions() const {
41  static const auto supported_table_options = getAllCsvTableOptions();
42  return supported_table_options;
43 }
44 
45 std::set<std::string_view> CsvDataWrapper::getAllCsvTableOptions() const {
46  std::set<std::string_view> supported_table_options(
49  supported_table_options.insert(csv_table_options_.begin(), csv_table_options_.end());
50  return supported_table_options;
51 }
52 
55 }
56 
58  static constexpr const char* S3_DIRECT = "S3_DIRECT";
59  static constexpr const char* S3_SELECT = "S3_SELECT";
60  static constexpr const char* S3_ACCESS_TYPE = "S3_ACCESS_TYPE";
61  auto access_type = foreign_table->options.find(S3_ACCESS_TYPE);
62 
63  if (access_type != foreign_table->options.end()) {
64  auto& server_options = foreign_table->foreign_server->options;
65  if (server_options.find(AbstractFileStorageDataWrapper::STORAGE_TYPE_KEY)->second !=
67  throw std::runtime_error{
68  "The \"" + std::string{S3_ACCESS_TYPE} +
69  "\" option is only valid for foreign tables using servers with \"" +
70  AbstractFileStorageDataWrapper::STORAGE_TYPE_KEY + "\" option value of \"" +
72  }
73  if (access_type->second != S3_DIRECT && access_type->second != S3_SELECT) {
74  throw std::runtime_error{
75  "Invalid value provided for the \"" + std::string{S3_ACCESS_TYPE} +
76  "\" option. Value must be one of the following: " + S3_DIRECT + ", " +
77  S3_SELECT + "."};
78  }
79  return (access_type->second == S3_SELECT);
80  } else {
81  return false;
82  }
83 }
84 
85 const std::set<std::string_view> CsvDataWrapper::csv_table_options_{"ARRAY_DELIMITER",
86  "ARRAY_MARKER",
87  "BUFFER_SIZE",
88  "DELIMITER",
89  "ESCAPE",
90  "HEADER",
91  "LINE_DELIMITER",
92  "LONLAT",
93  "NULLS",
94  "QUOTE",
95  "QUOTED",
96  "S3_ACCESS_TYPE",
97  "TRIM_SPACES"};
98 
99 const CsvFileBufferParser CsvDataWrapper::csv_file_buffer_parser_{};
100 } // namespace foreign_storage
static const std::set< std::string_view > csv_table_options_
const TextFileBufferParser & getFileBufferParser() const override
static bool validateAndGetIsS3Select(const ForeignTable *foreign_table)
std::set< std::string_view > getAllCsvTableOptions() const
void validateTableOptions(const ForeignTable *foreign_table) const override
const std::set< std::string_view > & getSupportedTableOptions() const override
import_export::CopyParams validateAndGetCopyParams(const ForeignTable *foreign_table) const override
void validateTableOptions(const ForeignTable *foreign_table) const override
const std::set< std::string_view > & getSupportedTableOptions() const override
static const CsvFileBufferParser csv_file_buffer_parser_
const ForeignServer * foreign_server
Definition: ForeignTable.h:57