]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/arrow/dbi/hiveserver2/operation.h
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / arrow / dbi / hiveserver2 / operation.h
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 <memory>
21 #include <string>
22 #include <vector>
23
24 #include "arrow/dbi/hiveserver2/columnar_row_set.h"
25 #include "arrow/dbi/hiveserver2/types.h"
26
27 #include "arrow/util/macros.h"
28 #include "arrow/util/visibility.h"
29
30 namespace arrow {
31
32 class Status;
33
34 namespace hiveserver2 {
35
36 struct ThriftRPC;
37
38 // Maps directly to TFetchOrientation in the HiveServer2 interface.
39 enum class FetchOrientation {
40 NEXT, // supported
41 PRIOR, // not supported
42 RELATIVE, // not supported
43 ABSOLUTE, // not supported
44 FIRST, // supported if query result caching is enabled in Impala
45 LAST // not supported
46 };
47
48 // Represents a single HiveServer2 operation. Used to monitor the status of an operation
49 // and to retrieve its results. The only Operation function that will block is Fetch,
50 // which blocks if there aren't any results ready yet.
51 //
52 // Operations are created using Session functions, eg. ExecuteStatement. They must
53 // have Close called on them before they can be deleted.
54 //
55 // This class is not thread-safe.
56 class ARROW_EXPORT Operation {
57 public:
58 // Maps directly to TOperationState in the HiveServer2 interface.
59 enum class State {
60 INITIALIZED,
61 RUNNING,
62 FINISHED,
63 CANCELED,
64 CLOSED,
65 ERROR,
66 UNKNOWN,
67 PENDING,
68 };
69
70 ~Operation();
71
72 // Fetches the current state of this operation. If successful, sets the operation state
73 // in 'out' and returns an OK status, otherwise an error status is returned. May be
74 // called after successfully creating the operation and before calling Close.
75 Status GetState(Operation::State* out) const;
76
77 // May be called after successfully creating the operation and before calling Close.
78 Status GetLog(std::string* out) const;
79
80 // May be called after successfully creating the operation and before calling Close.
81 Status GetProfile(std::string* out) const;
82
83 // Fetches metadata for the columns in the output of this operation, such as the
84 // names and types of the columns, and returns it as a list of column descriptions.
85 // May be called after successfully creating the operation and before calling Close.
86 Status GetResultSetMetadata(std::vector<ColumnDesc>* column_descs) const;
87
88 // Fetches a batch of results, stores them in 'results', and sets has_more_rows.
89 // Fetch will block if there aren't any results that are ready.
90 Status Fetch(std::unique_ptr<ColumnarRowSet>* results, bool* has_more_rows) const;
91 Status Fetch(int max_rows, FetchOrientation orientation,
92 std::unique_ptr<ColumnarRowSet>* results, bool* has_more_rows) const;
93
94 // May be called after successfully creating the operation and before calling Close.
95 Status Cancel() const;
96
97 // Closes the operation. Must be called before the operation is deleted. May be safely
98 // called on an invalid or already closed operation - will only return an error if the
99 // operation is open but the close rpc fails.
100 Status Close();
101
102 // May be called after successfully creating the operation and before calling Close.
103 bool HasResultSet() const;
104
105 // Returns true iff this operation's results will be returned in a columnar format.
106 // May be called at any time.
107 bool IsColumnar() const;
108
109 protected:
110 // Hides Thrift objects from the header.
111 struct OperationImpl;
112
113 explicit Operation(const std::shared_ptr<ThriftRPC>& rpc);
114
115 std::unique_ptr<OperationImpl> impl_;
116 std::shared_ptr<ThriftRPC> rpc_;
117
118 // True iff this operation has been successfully created and has not been closed yet,
119 // corresponding to when the operation has a valid operation handle.
120 bool open_;
121
122 private:
123 ARROW_DISALLOW_COPY_AND_ASSIGN(Operation);
124 };
125
126 } // namespace hiveserver2
127 } // namespace arrow