OmniSciDB  a5dc49c757
 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 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 
18 
19 #include <boost/algorithm/string.hpp>
20 #include <boost/filesystem.hpp>
21 
24 
25 namespace import_export {
26 
27 QueryExporter::QueryExporter(const FileType file_type) : file_type_{file_type} {}
28 
29 std::unique_ptr<QueryExporter> QueryExporter::create(FileType file_type) {
30  switch (file_type) {
31  case FileType::kCSV:
32  return std::make_unique<QueryExporterCSV>();
33  case FileType::kGeoJSON:
37  return std::make_unique<QueryExporterGDAL>(file_type);
38  }
39  CHECK(false);
40  return nullptr;
41 }
42 
44  const std::string& file_path,
45  const std::string& file_type,
46  const std::unordered_set<std::string>& valid_extensions) const {
47  auto extension = boost::algorithm::to_lower_copy(
48  boost::filesystem::path(file_path).extension().string());
49  if (valid_extensions.find(extension) == valid_extensions.end()) {
50  throw std::runtime_error("Invalid file extension '" + extension +
51  "' for file type '" + file_type + "'");
52  }
53 }
54 
55 std::string QueryExporter::safeColumnName(const std::string& resname,
56  const int column_index) {
57  if (resname.size() == 0) {
58  return "result_" + std::to_string(column_index);
59  }
60  return resname;
61 }
62 
63 } // 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:291
void validateFileExtensions(const std::string &file_path, const std::string &file_type, const std::unordered_set< std::string > &valid_extensions) const