Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
child-query.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef IMPALA_SERVICE_CHILD_QUERY_H
16 #define IMPALA_SERVICE_CHILD_QUERY_H
17 
18 #include <string>
19 #include <boost/thread.hpp>
20 
21 #include "common/status.h"
22 #include "impala-server.h"
23 #include "gen-cpp/TCLIService_types.h"
24 
25 namespace impala {
26 
27 class ImpalaServer;
28 
36 //
43 //
47 class ChildQuery {
48  public:
49  ChildQuery(const std::string& query, ImpalaServer::QueryExecState* parent_exec_state,
50  ImpalaServer* parent_server)
51  : query_(query),
52  parent_exec_state_(parent_exec_state),
53  parent_server_(parent_server),
54  is_running_(false),
55  is_cancelled_(false) {
56  DCHECK(!query_.empty());
57  DCHECK(parent_exec_state_ != NULL);
58  DCHECK(parent_server_ != NULL);
59  }
60 
63  ChildQuery(const ChildQuery& other)
64  : query_(other.query_),
67  is_running_(other.is_running_),
69 
72  ChildQuery& operator=(const ChildQuery& other) {
73  query_ = other.query_;
76  is_running_ = other.is_running_;
78  return *this;
79  }
80 
83 
90  void Cancel();
91 
92  const apache::hive::service::cli::thrift::TTableSchema& result_schema() {
93  return meta_resp_.schema;
94  }
95 
96  const apache::hive::service::cli::thrift::TRowSet& result_data() {
97  return fetch_resp_.results;
98  }
99 
102  static const string PARENT_QUERY_OPT;
103 
104  private:
107  void SetQueryOptions(const TQueryOptions& parent_options,
108  apache::hive::service::cli::thrift::TExecuteStatementReq* exec_stmt_req);
109 
113 
115  std::string query_;
116 
120 
123 
125  apache::hive::service::cli::thrift::TGetResultSetMetadataResp meta_resp_;
126  apache::hive::service::cli::thrift::TFetchResultsResp fetch_resp_;
127 
129  apache::hive::service::cli::thrift::TOperationHandle hs2_handle_;
130 
132  boost::mutex lock_;
133 
137 
140 };
141 
142 }
143 
144 #endif
ImpalaServer::QueryExecState * parent_exec_state_
Definition: child-query.h:119
apache::hive::service::cli::thrift::TOperationHandle hs2_handle_
HS2 query handle. Set in ExecChildQuery().
Definition: child-query.h:129
apache::hive::service::cli::thrift::TGetResultSetMetadataResp meta_resp_
Result metadata and result rows of query.
Definition: child-query.h:125
const apache::hive::service::cli::thrift::TRowSet & result_data()
Definition: child-query.h:96
ImpalaServer * parent_server_
Parent Impala server used for executing this child query. Not owned.
Definition: child-query.h:122
std::string query_
SQL string to be executed.
Definition: child-query.h:115
void SetQueryOptions(const TQueryOptions &parent_options, apache::hive::service::cli::thrift::TExecuteStatementReq *exec_stmt_req)
Definition: child-query.cc:119
ChildQuery(const ChildQuery &other)
Definition: child-query.h:63
const apache::hive::service::cli::thrift::TTableSchema & result_schema()
Definition: child-query.h:92
Status ExecAndFetch()
Executes this child query through HiveServer2 and fetches all its results.
Definition: child-query.cc:32
apache::hive::service::cli::thrift::TFetchResultsResp fetch_resp_
Definition: child-query.h:126
ChildQuery & operator=(const ChildQuery &other)
Definition: child-query.h:72
boost::mutex lock_
Protects is_running_ and is_cancelled_ to ensure idempotent cancellations.
Definition: child-query.h:132
ChildQuery(const std::string &query, ImpalaServer::QueryExecState *parent_exec_state, ImpalaServer *parent_server)
Definition: child-query.h:49
bool is_cancelled_
Indicates whether this child query has been cancelled. Set in Cancel().
Definition: child-query.h:139
static const string PARENT_QUERY_OPT
Definition: child-query.h:102