OmniSciDB  471d68cefb
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QueryExporter.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 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 
18 
19 #include <boost/algorithm/string.hpp>
20 
23 
24 namespace import_export {
25 
26 QueryExporter::QueryExporter(const FileType file_type) : file_type_{file_type} {}
27 
28 std::unique_ptr<QueryExporter> QueryExporter::create(FileType file_type) {
29  switch (file_type) {
30  case FileType::kCSV:
31  return std::make_unique<QueryExporterCSV>();
32  case FileType::kGeoJSON:
36  return std::make_unique<QueryExporterGDAL>(file_type);
37  }
38  CHECK(false);
39  return nullptr;
40 }
41 
43  const std::string& file_path,
44  const std::string& file_type,
45  const std::unordered_set<std::string>& valid_extensions) const {
46  auto extension = boost::algorithm::to_lower_copy(
47  boost::filesystem::path(file_path).extension().string());
48  if (valid_extensions.find(extension) == valid_extensions.end()) {
49  throw std::runtime_error("Invalid file extension '" + extension +
50  "' for file type '" + file_type + "'");
51  }
52 }
53 
54 std::string QueryExporter::safeColumnName(const std::string& resname,
55  const int column_index) {
56  if (resname.size() == 0) {
57  return "result_" + std::to_string(column_index);
58  }
59  return resname;
60 }
61 
62 } // namespace import_export
std::string safeColumnName(const std::string &resname, const int column_index)
static std::unique_ptr< QueryExporter > create(const FileType file_type)
std::string to_string(char const *&&v)
#define CHECK(condition)
Definition: Logger.h:209
void validateFileExtensions(const std::string &file_path, const std::string &file_type, const std::unordered_set< std::string > &valid_extensions) const