File indexing completed on 2026-04-17 08:28:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #pragma once
0019
0020 #include <exception>
0021 #include <sstream>
0022 #include <string>
0023 #include <utility>
0024
0025 #include "arrow/type_fwd.h"
0026 #include "arrow/util/string_util.h"
0027 #include "parquet/platform.h"
0028
0029
0030 #if !defined(ARROW_UNUSED)
0031 # define ARROW_UNUSED(x) UNUSED(x)
0032 #endif
0033
0034
0035
0036 #define BEGIN_PARQUET_CATCH_EXCEPTIONS try {
0037 #define END_PARQUET_CATCH_EXCEPTIONS \
0038 } \
0039 catch (const ::parquet::ParquetStatusException& e) { \
0040 return e.status(); \
0041 } \
0042 catch (const ::parquet::ParquetException& e) { \
0043 return ::arrow::Status::IOError(e.what()); \
0044 }
0045
0046
0047
0048 #define PARQUET_CATCH_NOT_OK(s) \
0049 BEGIN_PARQUET_CATCH_EXCEPTIONS \
0050 (s); \
0051 END_PARQUET_CATCH_EXCEPTIONS
0052
0053
0054
0055 #define PARQUET_CATCH_AND_RETURN(s) \
0056 BEGIN_PARQUET_CATCH_EXCEPTIONS \
0057 return (s); \
0058 END_PARQUET_CATCH_EXCEPTIONS
0059
0060
0061
0062 #define PARQUET_IGNORE_NOT_OK(s) \
0063 do { \
0064 ::arrow::Status _s = ::arrow::ToStatus(s); \
0065 ARROW_UNUSED(_s); \
0066 } while (0)
0067
0068 #define PARQUET_THROW_NOT_OK(s) \
0069 do { \
0070 ::arrow::Status _s = ::arrow::ToStatus(s); \
0071 if (!_s.ok()) { \
0072 throw ::parquet::ParquetStatusException(std::move(_s)); \
0073 } \
0074 } while (0)
0075
0076 #define PARQUET_ASSIGN_OR_THROW_IMPL(status_name, lhs, rexpr) \
0077 auto status_name = (rexpr); \
0078 PARQUET_THROW_NOT_OK(status_name.status()); \
0079 lhs = std::move(status_name).ValueOrDie();
0080
0081 #define PARQUET_ASSIGN_OR_THROW(lhs, rexpr) \
0082 PARQUET_ASSIGN_OR_THROW_IMPL(ARROW_ASSIGN_OR_RAISE_NAME(_error_or_value, __COUNTER__), \
0083 lhs, rexpr);
0084
0085 namespace parquet {
0086
0087 class ParquetException : public std::exception {
0088 public:
0089 PARQUET_NORETURN static void EofException(const std::string& msg = "") {
0090 static std::string prefix = "Unexpected end of stream";
0091 if (msg.empty()) {
0092 throw ParquetException(prefix);
0093 }
0094 throw ParquetException(prefix, ": ", msg);
0095 }
0096
0097 PARQUET_NORETURN static void NYI(const std::string& msg = "") {
0098 throw ParquetException("Not yet implemented: ", msg, ".");
0099 }
0100
0101 template <typename... Args>
0102 explicit ParquetException(Args&&... args)
0103 : msg_(::arrow::internal::JoinToString(std::forward<Args>(args)...)) {}
0104
0105 explicit ParquetException(std::string msg) : msg_(std::move(msg)) {}
0106
0107 explicit ParquetException(const char* msg, const std::exception&) : msg_(msg) {}
0108
0109 ParquetException(const ParquetException&) = default;
0110 ParquetException& operator=(const ParquetException&) = default;
0111 ParquetException(ParquetException&&) = default;
0112 ParquetException& operator=(ParquetException&&) = default;
0113
0114 const char* what() const noexcept override { return msg_.c_str(); }
0115
0116 private:
0117 std::string msg_;
0118 };
0119
0120
0121
0122
0123 PARQUET_EXPORT
0124 std::ostream& operator<<(std::ostream& os, const ParquetException& exception);
0125
0126 class ParquetStatusException : public ParquetException {
0127 public:
0128 explicit ParquetStatusException(::arrow::Status status)
0129 : ParquetException(status.ToString()), status_(std::move(status)) {}
0130
0131 const ::arrow::Status& status() const { return status_; }
0132
0133 private:
0134 ::arrow::Status status_;
0135 };
0136
0137
0138 class ParquetInvalidOrCorruptedFileException : public ParquetStatusException {
0139 public:
0140 ParquetInvalidOrCorruptedFileException(const ParquetInvalidOrCorruptedFileException&) =
0141 default;
0142
0143 template <typename Arg,
0144 typename std::enable_if<
0145 !std::is_base_of<ParquetInvalidOrCorruptedFileException, Arg>::value,
0146 int>::type = 0,
0147 typename... Args>
0148 explicit ParquetInvalidOrCorruptedFileException(Arg arg, Args&&... args)
0149 : ParquetStatusException(::arrow::Status::Invalid(std::forward<Arg>(arg),
0150 std::forward<Args>(args)...)) {}
0151 };
0152
0153 template <typename StatusReturnBlock>
0154 void ThrowNotOk(StatusReturnBlock&& b) {
0155 PARQUET_THROW_NOT_OK(b());
0156 }
0157
0158 }