OmniSciDB  16c4e035a1
 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 2021 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 #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  : AbstractTextFileDataWrapper(db_id, foreign_table, user_mapping) {}
32 
33 void CsvDataWrapper::validateTableOptions(const ForeignTable* foreign_table) const {
36  validateAndGetIsS3Select(foreign_table);
37 }
38 
39 const std::set<std::string_view>& CsvDataWrapper::getSupportedTableOptions() const {
40  static const auto supported_table_options = getAllCsvTableOptions();
41  return supported_table_options;
42 }
43 
44 std::set<std::string_view> CsvDataWrapper::getAllCsvTableOptions() const {
45  std::set<std::string_view> supported_table_options(
48  supported_table_options.insert(csv_table_options_.begin(), csv_table_options_.end());
49  return supported_table_options;
50 }
51 
54 }
55 
57  static constexpr const char* S3_DIRECT = "S3_DIRECT";
58  static constexpr const char* S3_SELECT = "S3_SELECT";
59  static constexpr const char* S3_ACCESS_TYPE = "S3_ACCESS_TYPE";
60  auto access_type = foreign_table->options.find(S3_ACCESS_TYPE);
61 
62  if (access_type != foreign_table->options.end()) {
63  auto& server_options = foreign_table->foreign_server->options;
64  if (server_options.find(AbstractFileStorageDataWrapper::STORAGE_TYPE_KEY)->second !=
66  throw std::runtime_error{
67  "The \"" + std::string{S3_ACCESS_TYPE} +
68  "\" option is only valid for foreign tables using servers with \"" +
69  AbstractFileStorageDataWrapper::STORAGE_TYPE_KEY + "\" option value of \"" +
71  }
72  if (access_type->second != S3_DIRECT && access_type->second != S3_SELECT) {
73  throw std::runtime_error{
74  "Invalid value provided for the \"" + std::string{S3_ACCESS_TYPE} +
75  "\" option. Value must be one of the following: " + S3_DIRECT + ", " +
76  S3_SELECT + "."};
77  }
78  return (access_type->second == S3_SELECT);
79  } else {
80  return false;
81  }
82 }
83 
84 const std::set<std::string_view> CsvDataWrapper::csv_table_options_{"ARRAY_DELIMITER",
85  "ARRAY_MARKER",
86  "BUFFER_SIZE",
87  "DELIMITER",
88  "ESCAPE",
89  "HEADER",
90  "LINE_DELIMITER",
91  "LONLAT",
92  "NULLS",
93  "QUOTE",
94  "QUOTED",
95  "S3_ACCESS_TYPE"};
96 
97 const CsvFileBufferParser CsvDataWrapper::csv_file_buffer_parser_{};
98 } // 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:55