Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::ChildQuery Class Reference

#include <child-query.h>

Collaboration diagram for impala::ChildQuery:

Public Member Functions

 ChildQuery (const std::string &query, ImpalaServer::QueryExecState *parent_exec_state, ImpalaServer *parent_server)
 
 ChildQuery (const ChildQuery &other)
 
ChildQueryoperator= (const ChildQuery &other)
 
Status ExecAndFetch ()
 Executes this child query through HiveServer2 and fetches all its results. More...
 
void Cancel ()
 
const
apache::hive::service::cli::thrift::TTableSchema & 
result_schema ()
 
const
apache::hive::service::cli::thrift::TRowSet & 
result_data ()
 

Static Public Attributes

static const string PARENT_QUERY_OPT = "impala.parent_query_id"
 

Private Member Functions

void SetQueryOptions (const TQueryOptions &parent_options, apache::hive::service::cli::thrift::TExecuteStatementReq *exec_stmt_req)
 
Status IsCancelled ()
 

Private Attributes

std::string query_
 SQL string to be executed. More...
 
ImpalaServer::QueryExecStateparent_exec_state_
 
ImpalaServerparent_server_
 Parent Impala server used for executing this child query. Not owned. More...
 
apache::hive::service::cli::thrift::TGetResultSetMetadataResp meta_resp_
 Result metadata and result rows of query. More...
 
apache::hive::service::cli::thrift::TFetchResultsResp fetch_resp_
 
apache::hive::service::cli::thrift::TOperationHandle hs2_handle_
 HS2 query handle. Set in ExecChildQuery(). More...
 
boost::mutex lock_
 Protects is_running_ and is_cancelled_ to ensure idempotent cancellations. More...
 
bool is_running_
 
bool is_cancelled_
 Indicates whether this child query has been cancelled. Set in Cancel(). More...
 

Detailed Description

Child queries are used for implementing statements that consist of one or several query statements (e.g., compute stats) that require independent query handles for fetching results. Such queries are 'children' of a parent exec state in the sense that they are executed in the same session and that child queries are cancelled if the parent is cancelled (but not necessarily vice versa). For simplicity and consistency, child queries are always executed via HiveServer2, regardless of whether the parent session is Beeswax or HiveServer2. Parent queries are expected to call ExecAndWait() of a child query in a separate thread, and then join that thread to wait for child-query completion. The parent QueryExecState is independent of the child query's QueryExecState, with the exception that the child query selectively checks the parent's status for failure/cancellation detection. Child queries should never call into their parent's QueryExecState to avoid deadlock. TODO: Compute stats is the only stmt that requires child queries. Once the CatalogService performs background stats gathering the concept of child queries will likely become obsolete. Remove this class and all child-query related code.

Definition at line 47 of file child-query.h.

Constructor & Destructor Documentation

impala::ChildQuery::ChildQuery ( const std::string &  query,
ImpalaServer::QueryExecState parent_exec_state,
ImpalaServer parent_server 
)
inline

Definition at line 49 of file child-query.h.

References parent_exec_state_, parent_server_, and query_.

impala::ChildQuery::ChildQuery ( const ChildQuery other)
inline

Allow child queries to be added to std collections. (boost::mutex's operator= and copy c'tor are private)

Definition at line 63 of file child-query.h.

Member Function Documentation

void impala::ChildQuery::Cancel ( )

Cancels and closes the given child query if it is running. Sets is_cancelled_. Child queries can be cancelled by the parent query through QueryExecState::Cancel(). Child queries should never cancel their parent to avoid deadlock (but the parent query may decide to cancel itself based on a non-OK status from a child query). Note that child queries have a different QueryExecState than their parent query, so cancellation of a child query does not call into the parent's QueryExecState.

Definition at line 158 of file child-query.cc.

References impala::lock_, and VLOG_QUERY.

Referenced by impala::ImpalaServer::QueryExecState::Cancel().

Status impala::ChildQuery::ExecAndFetch ( )

Executes this child query through HiveServer2 and fetches all its results.

Definition at line 32 of file child-query.cc.

References impala::lock_, impala::Status::ok(), impala::PrintId(), RETURN_IF_ERROR, impala::ImpalaServer::TUniqueIdToTHandleIdentifier(), and VLOG_QUERY.

Status impala::ChildQuery::IsCancelled ( )
private

Returns Status::Cancelled if this child query has been cancelled, otherwise OK. Acquires lock_.

Definition at line 179 of file child-query.cc.

References impala::Status::CANCELLED, impala::lock_, and impala::Status::OK.

ChildQuery& impala::ChildQuery::operator= ( const ChildQuery other)
inline

Allow child queries to be added to std collections. (boost::mutex's operator= and copy c'tor are private)

Definition at line 72 of file child-query.h.

References is_cancelled_, is_running_, parent_exec_state_, parent_server_, and query_.

const apache::hive::service::cli::thrift::TRowSet& impala::ChildQuery::result_data ( )
inline

Definition at line 96 of file child-query.h.

References fetch_resp_.

const apache::hive::service::cli::thrift::TTableSchema& impala::ChildQuery::result_schema ( )
inline

Definition at line 92 of file child-query.h.

References meta_resp_.

void impala::ChildQuery::SetQueryOptions ( const TQueryOptions &  parent_options,
apache::hive::service::cli::thrift::TExecuteStatementReq *  exec_stmt_req 
)
private

Sets the query options from the parent query in child's HS2 request. TODO: Consider moving this function into a more appropriate place.

Definition at line 119 of file child-query.cc.

References BATCH_SIZE, and SET_QUERY_OPTION.

Member Data Documentation

apache::hive::service::cli::thrift::TFetchResultsResp impala::ChildQuery::fetch_resp_
private

Definition at line 126 of file child-query.h.

Referenced by result_data().

apache::hive::service::cli::thrift::TOperationHandle impala::ChildQuery::hs2_handle_
private

HS2 query handle. Set in ExecChildQuery().

Definition at line 129 of file child-query.h.

bool impala::ChildQuery::is_cancelled_
private

Indicates whether this child query has been cancelled. Set in Cancel().

Definition at line 139 of file child-query.h.

Referenced by operator=().

bool impala::ChildQuery::is_running_
private

Indicates whether this query is running. False if the query has not started yet or if the query has finished either successfully or because of an error.

Definition at line 136 of file child-query.h.

Referenced by operator=().

boost::mutex impala::ChildQuery::lock_
private

Protects is_running_ and is_cancelled_ to ensure idempotent cancellations.

Definition at line 132 of file child-query.h.

apache::hive::service::cli::thrift::TGetResultSetMetadataResp impala::ChildQuery::meta_resp_
private

Result metadata and result rows of query.

Definition at line 125 of file child-query.h.

Referenced by result_schema().

ImpalaServer::QueryExecState* impala::ChildQuery::parent_exec_state_
private

Execution state of parent query. Used to synchronize and propagate parent cancellations/failures to this child query. Not owned.

Definition at line 119 of file child-query.h.

Referenced by ChildQuery(), and operator=().

const string impala::ChildQuery::PARENT_QUERY_OPT = "impala.parent_query_id"
static

The key in the HS2 conf overlay which indicates to the executing ImpalaServer that this query is a child query.

Definition at line 102 of file child-query.h.

ImpalaServer* impala::ChildQuery::parent_server_
private

Parent Impala server used for executing this child query. Not owned.

Definition at line 122 of file child-query.h.

Referenced by ChildQuery(), and operator=().

std::string impala::ChildQuery::query_
private

SQL string to be executed.

Definition at line 115 of file child-query.h.

Referenced by ChildQuery(), and operator=().


The documentation for this class was generated from the following files: