iceberg-cpp
Loading...
Searching...
No Matches
arrow_status_internal.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <arrow/result.h>
23#include <arrow/status.h>
24
25#include "iceberg/result.h"
26
27namespace iceberg::arrow {
28
29inline ErrorKind ToErrorKind(const ::arrow::Status& status) {
30 switch (status.code()) {
31 case ::arrow::StatusCode::IOError:
32 return ErrorKind::kIOError;
33 case ::arrow::StatusCode::NotImplemented:
34 return ErrorKind::kNotImplemented;
35 default:
36 return ErrorKind::kUnknownError;
37 }
38}
39
40#define ICEBERG_ARROW_ASSIGN_OR_RETURN_IMPL(result_name, lhs, rexpr, error_transform) \
41 auto&& result_name = (rexpr); \
42 if (!result_name.ok()) { \
43 return std::unexpected<Error>{{.kind = error_transform(result_name.status()), \
44 .message = result_name.status().ToString()}}; \
45 } \
46 lhs = std::move(result_name).ValueOrDie();
47
48#define ICEBERG_ARROW_ASSIGN_OR_RETURN(lhs, rexpr) \
49 ICEBERG_ARROW_ASSIGN_OR_RETURN_IMPL( \
50 ARROW_ASSIGN_OR_RAISE_NAME(_error_or_value, __COUNTER__), lhs, rexpr, \
51 ::iceberg::arrow::ToErrorKind)
52
53#define ICEBERG_ARROW_RETURN_NOT_OK(expr) \
54 do { \
55 auto&& _status = (expr); \
56 if (!_status.ok()) { \
57 return std::unexpected<Error>{{.kind = ::iceberg::arrow::ToErrorKind(_status), \
58 .message = _status.ToString()}}; \
59 } \
60 } while (0)
61
62} // namespace iceberg::arrow