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
9 // http://www.apache.org/licenses/LICENSE-2.0
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
24 #include "arrow/dbi/hiveserver2/columnar_row_set.h"
25 #include "arrow/dbi/hiveserver2/types.h"
27 #include "arrow/util/macros.h"
28 #include "arrow/util/visibility.h"
34 namespace hiveserver2
{
38 // Maps directly to TFetchOrientation in the HiveServer2 interface.
39 enum class FetchOrientation
{
41 PRIOR
, // not supported
42 RELATIVE
, // not supported
43 ABSOLUTE
, // not supported
44 FIRST
, // supported if query result caching is enabled in Impala
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.
52 // Operations are created using Session functions, eg. ExecuteStatement. They must
53 // have Close called on them before they can be deleted.
55 // This class is not thread-safe.
56 class ARROW_EXPORT Operation
{
58 // Maps directly to TOperationState in the HiveServer2 interface.
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;
77 // May be called after successfully creating the operation and before calling Close.
78 Status
GetLog(std::string
* out
) const;
80 // May be called after successfully creating the operation and before calling Close.
81 Status
GetProfile(std::string
* out
) const;
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;
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;
94 // May be called after successfully creating the operation and before calling Close.
95 Status
Cancel() const;
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.
102 // May be called after successfully creating the operation and before calling Close.
103 bool HasResultSet() const;
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;
110 // Hides Thrift objects from the header.
111 struct OperationImpl
;
113 explicit Operation(const std::shared_ptr
<ThriftRPC
>& rpc
);
115 std::unique_ptr
<OperationImpl
> impl_
;
116 std::shared_ptr
<ThriftRPC
> rpc_
;
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.
123 ARROW_DISALLOW_COPY_AND_ASSIGN(Operation
);
126 } // namespace hiveserver2