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