OmniSciDB  dfae7c3b14
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:
35  return std::make_unique<QueryExporterGDAL>(file_type);
36  }
37  CHECK(false);
38  return nullptr;
39 }
40 
42  const std::string& file_path,
43  const std::string& file_type,
44  const std::unordered_set<std::string>& valid_extensions) const {
45  auto extension = boost::algorithm::to_lower_copy(
46  boost::filesystem::path(file_path).extension().string());
47  if (valid_extensions.find(extension) == valid_extensions.end()) {
48  throw std::runtime_error("Invalid file extension '" + extension +
49  "' for file type '" + file_type + "'");
50  }
51 }
52 
53 std::string QueryExporter::safeColumnName(const std::string& resname,
54  const int column_index) {
55  if (resname.size() == 0) {
56  return "result_" + std::to_string(column_index);
57  }
58  return resname;
59 }
60 
61 } // 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:197
void validateFileExtensions(const std::string &file_path, const std::string &file_type, const std::unordered_set< std::string > &valid_extensions) const