/root/doris/be/src/util/arrow/utils.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <arrow/result.h> |
21 | | |
22 | | #include <iostream> |
23 | | |
24 | | #include "common/compiler_util.h" |
25 | | #include "common/status.h" |
26 | | |
27 | | // This files contains some utilities to convert Doris internal |
28 | | // data format into/from Apache Arrow format. When Doris needs |
29 | | // to share data with others we can leverage Arrow's ability. |
30 | | // We can convert our internal data into Arrow's memory format |
31 | | // and then convert to other format, for example Parquet. Because |
32 | | // Arrow have already implemented this functions. And what's more |
33 | | // Arrow support multiple languages, so it will make it easy to |
34 | | // handle Doris data in other languages. |
35 | | |
36 | | // Forward declaration of arrow class |
37 | | namespace arrow { |
38 | | class Array; |
39 | | class RecordBatch; |
40 | | class Status; |
41 | | } // namespace arrow |
42 | | |
43 | | namespace doris { |
44 | | |
45 | | #define RETURN_ARROW_STATUS_IF_ERROR(stmt) \ |
46 | | do { \ |
47 | | Status _status_ = (stmt); \ |
48 | | if (UNLIKELY(!_status_.ok())) { \ |
49 | | ARROW_RETURN_NOT_OK(to_arrow_status(_status_)); \ |
50 | | } \ |
51 | | } while (false) |
52 | | |
53 | | #define RETURN_DORIS_STATUS_IF_ERROR(stmt) \ |
54 | 0 | do { \ |
55 | 0 | arrow::Status _status_ = (stmt); \ |
56 | 0 | if (UNLIKELY(!_status_.ok())) { \ |
57 | 0 | return to_doris_status(_status_); \ |
58 | 0 | } \ |
59 | 0 | } while (false) |
60 | | |
61 | | #define RETURN_ARROW_STATUS_IF_CATCH_EXCEPTION(stmt) \ |
62 | | do { \ |
63 | | try { \ |
64 | | arrow::Status _status_ = (stmt); \ |
65 | | return _status_; \ |
66 | | } catch (const doris::Exception& e) { \ |
67 | | return to_arrow_status(Status::Error<false>(e.code(), e.to_string())); \ |
68 | | } \ |
69 | | } while (0) |
70 | | |
71 | | // Pretty print a arrow RecordBatch. |
72 | | Status arrow_pretty_print(const arrow::RecordBatch& rb, std::ostream* os); |
73 | | Status arrow_pretty_print(const arrow::Array& rb, std::ostream* os); |
74 | | |
75 | | Status to_doris_status(const arrow::Status& status); |
76 | | arrow::Status to_arrow_status(const Status& status); |
77 | | |
78 | | template <typename T> |
79 | | inline void assign_from_result(T& output, const arrow::Result<T>& result) { |
80 | | output = *result; |
81 | | } |
82 | | |
83 | | template <typename T> |
84 | 0 | inline void assign_from_result(T& output, arrow::Result<T>&& result) { |
85 | 0 | output = std::move(*result); |
86 | 0 | } Unexecuted instantiation: _ZN5doris18assign_from_resultIN5arrow6flight8LocationEEEvRT_ONS1_6ResultIS4_EE Unexecuted instantiation: _ZN5doris18assign_from_resultISt10unique_ptrIN5arrow6flight12FlightClientESt14default_deleteIS4_EEEEvRT_ONS2_6ResultIS8_EE Unexecuted instantiation: _ZN5doris18assign_from_resultIN5arrow6flight12FlightClient16DoExchangeResultEEEvRT_ONS1_6ResultIS5_EE |
87 | | |
88 | | template <typename T> |
89 | | inline void assign_from_result(T* output, const arrow::Result<T>& result) { |
90 | | *output = *result; |
91 | | } |
92 | | |
93 | | template <typename T> |
94 | 0 | inline void assign_from_result(T* output, arrow::Result<T>&& result) { |
95 | 0 | *output = std::move(*result); |
96 | 0 | } Unexecuted instantiation: _ZN5doris18assign_from_resultISt10shared_ptrIN5arrow6SchemaEEEEvPT_ONS2_6ResultIS5_EE Unexecuted instantiation: _ZN5doris18assign_from_resultISt10shared_ptrIN5arrow6BufferEEEEvPT_ONS2_6ResultIS5_EE |
97 | | |
98 | | #define RETURN_DORIS_STATUS_IF_RESULT_ERROR(output, result_expr) \ |
99 | 0 | do { \ |
100 | 0 | auto&& _result_ = (result_expr); \ |
101 | 0 | if (UNLIKELY(!_result_.ok())) { \ |
102 | 0 | return to_doris_status(_result_.status()); \ |
103 | 0 | } \ |
104 | 0 | assign_from_result(output, std::forward<decltype(_result_)>(_result_)); \ |
105 | 0 | } while (0) |
106 | | |
107 | | } // namespace doris |