22 using namespace impala;
23 using namespace apache::hive::service::cli::thrift;
33 const TUniqueId& session_id = parent_exec_state_->session_id();
34 VLOG_QUERY <<
"Executing child query: " << query_ <<
" in session "
39 TExecuteStatementResp exec_stmt_resp;
40 TExecuteStatementReq exec_stmt_req;
42 &exec_stmt_req.sessionHandle.sessionId);
43 exec_stmt_req.__set_statement(query_);
44 SetQueryOptions(parent_exec_state_->exec_request().query_options, &exec_stmt_req);
45 exec_stmt_req.confOverlay[PARENT_QUERY_OPT] =
PrintId(parent_exec_state_->query_id());
58 parent_server_->ExecuteStatement(exec_stmt_resp, exec_stmt_req);
59 hs2_handle_ = exec_stmt_resp.operationHandle;
61 lock_guard<mutex> l(
lock_);
64 status = exec_stmt_resp.status;
67 TGetResultSetMetadataReq meta_req;
68 meta_req.operationHandle = exec_stmt_resp.operationHandle;
70 parent_server_->GetResultSetMetadata(meta_resp_, meta_req);
71 status = meta_resp_.status;
75 TFetchResultsReq fetch_req;
76 fetch_req.operationHandle = exec_stmt_resp.operationHandle;
77 fetch_req.maxRows = 1024;
80 parent_server_->FetchResults(fetch_resp_, fetch_req);
81 status = fetch_resp_.status;
82 }
while (status.
ok() && fetch_resp_.hasMoreRows);
85 TCloseOperationResp close_resp;
86 TCloseOperationReq close_req;
87 close_req.operationHandle = exec_stmt_resp.operationHandle;
88 parent_server_->CloseOperation(close_resp, close_req);
90 lock_guard<mutex> l(
lock_);
97 if (status.
ok()) status = close_resp.status;
101 template <
typename T>
103 TExecuteStatementReq* exec_stmt_req) {
104 stringstream opt_val_ss;
105 opt_val_ss << opt_val;
106 map<int, const char*>::const_iterator it =
107 _TImpalaQueryOptions_VALUES_TO_NAMES.find(opt);
108 if (it == _TImpalaQueryOptions_VALUES_TO_NAMES.end())
return;
109 exec_stmt_req->confOverlay[it->second] = opt_val_ss.str();
110 exec_stmt_req->__isset.confOverlay =
true;
113 #define SET_QUERY_OPTION(NAME, ENUM)\
114 if (parent_options.__isset.NAME) {\
115 SetQueryOption(TImpalaQueryOptions::ENUM,\
116 parent_options.NAME, exec_stmt_req);\
120 TExecuteStatementReq* exec_stmt_req) {
122 DCHECK_EQ(_TImpalaQueryOptions_VALUES_TO_NAMES.size(),
123 TImpalaQueryOptions::EXEC_SINGLE_NODE_ROWS_THRESHOLD + 1);
124 SET_QUERY_OPTION(abort_on_default_limit_exceeded, ABORT_ON_DEFAULT_LIMIT_EXCEEDED);
155 EXEC_SINGLE_NODE_ROWS_THRESHOLD);
161 lock_guard<mutex> l(
lock_);
162 is_cancelled_ =
true;
163 if (!is_running_)
return;
166 VLOG_QUERY <<
"Cancelling and closing child query with operation id: "
167 << hs2_handle_.operationId.guid;
169 TCancelOperationResp cancel_resp;
170 TCancelOperationReq cancel_req;
171 cancel_req.operationHandle = hs2_handle_;
172 parent_server_->CancelOperation(cancel_resp, cancel_req);
173 TCloseOperationResp close_resp;
174 TCloseOperationReq close_req;
175 close_req.operationHandle = hs2_handle_;
176 parent_server_->CloseOperation(close_resp, close_req);
180 lock_guard<mutex> l(
lock_);
#define RETURN_IF_ERROR(stmt)
some generally useful macros
boost::mutex lock_
protects all fields below
string PrintId(const TUniqueId &id, const string &separator)
void SetQueryOptions(const TQueryOptions &parent_options, apache::hive::service::cli::thrift::TExecuteStatementReq *exec_stmt_req)
static void TUniqueIdToTHandleIdentifier(const TUniqueId &unique_id, const TUniqueId &secret, apache::hive::service::cli::thrift::THandleIdentifier *handle)
Status ExecAndFetch()
Executes this child query through HiveServer2 and fetches all its results.
static const Status CANCELLED
#define SET_QUERY_OPTION(NAME, ENUM)
void SetQueryOption(TImpalaQueryOptions::type opt, const T &opt_val, TExecuteStatementReq *exec_stmt_req)
static const string PARENT_QUERY_OPT