OmniSciDB  cde582ebc3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ForeignStorageException.h
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 
17 #pragma once
18 
19 #include <stdexcept>
20 #include <string>
21 
22 namespace foreign_storage {
23 
24 class ForeignStorageException : public std::runtime_error {
25  public:
26  ForeignStorageException(const std::string& error_message)
27  : std::runtime_error(error_message) {}
28 };
29 
30 class MetadataScanInfeasibleFragmentSizeException : public std::runtime_error {
31  public:
32  MetadataScanInfeasibleFragmentSizeException(const std::string& error_message)
33  : std::runtime_error(error_message), min_feasible_fragment_size_(-1) {}
34 
35  int32_t
36  min_feasible_fragment_size_; // may be set to indicate what the minimum feasible
37  // fragment size for metadata scan should be
38 };
39 
40 inline void throw_unexpected_number_of_items(const size_t& num_expected,
41  const size_t& num_loaded,
42  const std::string& item_type) {
44  "Unexpected number of " + item_type +
45  " while loading from foreign data source: expected " +
46  std::to_string(num_expected) + " , obtained " + std::to_string(num_loaded) + " " +
47  item_type +
48  ". Please use the \"REFRESH FOREIGN TABLES\" command on the foreign table "
49  "if data source has been updated.");
50 }
51 
52 inline void throw_removed_row_in_result_set_error(const std::string& select_statement) {
54  "Refresh of foreign table created with \"APPEND\" update type failed as result set "
55  "of select statement "
56  "reduced in size: \"" +
57  select_statement + "\""};
58 }
59 
60 inline void throw_removed_row_in_file_error(const std::string& file_path) {
62  "Refresh of foreign table created with \"APPEND\" update type failed as file "
63  "reduced in size: \"" +
64  file_path + "\""};
65 }
66 
67 inline void throw_removed_file_error(const std::string& file_path) {
69  "Refresh of foreign table created with \"APPEND\" update type failed as "
70  "file \"" +
71  file_path + "\" was removed."};
72 }
73 
74 inline void throw_number_of_columns_mismatch_error(size_t num_table_cols,
75  size_t num_file_cols,
76  const std::string& file_path) {
77  throw ForeignStorageException{"Mismatched number of logical columns: (expected " +
78  std::to_string(num_table_cols) + " columns, has " +
79  std::to_string(num_file_cols) + "): in file '" +
80  file_path + "'"};
81 }
82 
83 inline void throw_file_access_error(const std::string& file_path,
84  const std::string& message) {
85  std::string error_message{"Unable to access file \"" + file_path + "\". " + message};
86  throw ForeignStorageException{error_message};
87 }
88 
89 inline void throw_file_not_found_error(const std::string& file_path) {
90  throw ForeignStorageException{"File or directory \"" + file_path +
91  "\" does not exist."};
92 }
93 
94 inline void throw_s3_compressed_mime_type(const std::string& file_path,
95  const std::string& mime_type) {
97  "File \"" + file_path + "\" has mime type \"" + mime_type +
98  "\", compressed file formats are not supported by S3 Foreign Tables."};
99 }
100 
101 inline void throw_s3_compressed_extension(const std::string& file_path,
102  const std::string& ext_type) {
104  "File \"" + file_path + "\" has extension type \"" + ext_type +
105  "\", compressed file formats are not supported by S3 Foreign Tables."};
106 }
107 
108 } // namespace foreign_storage
void throw_file_access_error(const std::string &file_path, const std::string &message)
void throw_removed_row_in_file_error(const std::string &file_path)
void throw_file_not_found_error(const std::string &file_path)
std::string to_string(char const *&&v)
void throw_s3_compressed_extension(const std::string &file_path, const std::string &ext_type)
ForeignStorageException(const std::string &error_message)
void throw_removed_file_error(const std::string &file_path)
void throw_number_of_columns_mismatch_error(size_t num_table_cols, size_t num_file_cols, const std::string &file_path)
MetadataScanInfeasibleFragmentSizeException(const std::string &error_message)
void throw_s3_compressed_mime_type(const std::string &file_path, const std::string &mime_type)
void throw_unexpected_number_of_items(const size_t &num_expected, const size_t &num_loaded, const std::string &item_type)
void throw_removed_row_in_result_set_error(const std::string &select_statement)