MCPcopy Create free account
hub / github.com/apache/impala / executeAndWait

Method executeAndWait

be/src/service/impala-beeswax-server.cc:98–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98void ImpalaServer::executeAndWait(beeswax::QueryHandle& beeswax_handle,
99 const Query& query, const LogContextId& client_ctx) {
100 VLOG_QUERY << "executeAndWait(): query=" << query.query;
101 RAISE_IF_ERROR(CheckNotShuttingDown(), SQLSTATE_GENERAL_ERROR);
102 ScopedSessionState session_handle(this);
103 shared_ptr<SessionState> session;
104 RAISE_IF_ERROR(
105 session_handle.WithBeeswaxSession(ThriftServer::GetThreadConnectionId(), &session),
106 SQLSTATE_GENERAL_ERROR);
107 TQueryCtx query_ctx;
108 // raise general error for request conversion error;
109 RAISE_IF_ERROR(QueryToTQueryContext(query, &query_ctx), SQLSTATE_GENERAL_ERROR);
110
111 DCHECK(session != nullptr); // The session should exist.
112 {
113 // The session is created when the client connects. Depending on the underlying
114 // transport, the username may be known at that time. If the username hasn't been set
115 // yet, set it now.
116 lock_guard<mutex> l(session->lock);
117 if (session->connected_user.empty()) {
118 session->connected_user = query.hadoop_user.empty() ?
119 FLAGS_anonymous_user_name : query.hadoop_user;
120 }
121 }
122
123 // raise Syntax error or access violation; it's likely to be syntax/analysis error
124 // TODO: that may not be true; fix this
125 QueryHandle query_handle;
126 RAISE_IF_ERROR(Execute(&query_ctx, session, &query_handle, nullptr),
127 SQLSTATE_SYNTAX_ERROR_OR_ACCESS_VIOLATION);
128
129 // Make query id available to the following RaiseBeeswaxException().
130 ScopedThreadContext scoped_tdi(GetThreadDebugInfo(), query_handle->query_id());
131
132 // Once the query is running do a final check for session closure and add it to the
133 // set of in-flight queries.
134 Status status = SetQueryInflight(session, query_handle);
135 if (!status.ok()) {
136 discard_result(UnregisterQuery(query_handle->query_id(), &status));
137 RaiseBeeswaxException(status.GetDetail(), SQLSTATE_GENERAL_ERROR);
138 }
139 // block until results are ready
140 query_handle->Wait();
141 {
142 lock_guard<mutex> l(*query_handle->lock());
143 status = query_handle->query_status();
144 }
145 if (!status.ok()) {
146 discard_result(UnregisterQuery(query_handle->query_id(), &status));
147 RaiseBeeswaxException(status.GetDetail(), SQLSTATE_GENERAL_ERROR);
148 }
149
150 TUniqueIdToBeeswaxHandle(query_handle->query_id(), &beeswax_handle);
151
152 // If the input log context id is an empty string, then create a new number and
153 // set it to _return. Otherwise, set _return with the input log context
154 beeswax_handle.log_context = client_ctx.empty() ? beeswax_handle.id : client_ctx;
155}

Callers 1

ExecMethod · 0.80

Calls 9

GetThreadDebugInfoFunction · 0.85
discard_resultFunction · 0.85
WithBeeswaxSessionMethod · 0.80
GetDetailMethod · 0.80
emptyMethod · 0.45
query_idMethod · 0.45
okMethod · 0.45
WaitMethod · 0.45
lockMethod · 0.45

Tested by

no test coverage detected