您的位置:首页 > 大数据 > 人工智能

[Hive - LanguageManual ] Explain (待)

2015-01-26 12:49 281 查看
EXPLAIN Syntax

EXPLAIN Syntax

Hive provides an
EXPLAIN
command that shows the execution plan for a query. The syntax for this statement is as follows:

AUTHORIZATION
is supported from HIVE 0.14.0 via HIVE-5961.[/code]
The use of
EXTENDED
in the
EXPLAIN
statement produces extra information about the operators in the plan. This is typically physical information like file names.

A Hive query gets converted into a sequence (it is more an Directed Acyclic Graph) of stages. These stages may be map/reduce stages or they may even be stages that do metastore or file system operations like move and rename. The explain output comprises of three parts:

The Abstract Syntax Tree for the query

The dependencies between the different stages of the plan

The description of each of the stages

The description of the stages itself shows a sequence of operators with the metadata associated with the operators. The metadata may comprise of things like filter expressions for the FilterOperator or the select expressions for the SelectOperator or the output file names for the FileSinkOperator.

As an example, consider the following
EXPLAIN
query:

The output of this statement contains the following parts:

The Abstract Syntax Tree

The Dependency Graph

This shows that Stage-1 is the root stage, Stage-2 is executed after Stage-1 is done and Stage-0 is executed after Stage-2 is done.

The plans of each Stage

In this example there are 2 map/reduce stages (Stage-1 and Stage-2) and 1 File System related stage (Stage-0). Stage-0 basically moves the results from a temporary directory to the directory corresponding to the table dest_g1.

A map/reduce stage itself comprises of 2 parts:

A mapping from table alias to Map Operator Tree - This mapping tells the mappers which operator tree to call in order to process the rows from a particular table or result of a previous map/reduce stage. In Stage-1 in the above example, the rows from src table are processed by the operator tree rooted at a Reduce Output Operator. Similarly, in Stage-2 the rows of the results of Stage-1 are processed by another operator tree rooted at another Reduce Output Operator. Each of these Reduce Output Operators partitions the data to the reducers according to the criteria shown in the metadata.

A Reduce Operator Tree - This is the operator tree which processes all the rows on the reducer of the map/reduce job. In Stage-1 for example, the Reducer Operator Tree is carrying out a partial aggregation where as the Reducer Operator Tree in Stage-2 computes the final aggregation from the partial aggregates computed in Stage-1

The use of
DEPENDENCY
in the
EXPLAIN
statement produces extra information about the inputs in the plan. It shows various attributes for the inputs. For example, for a query like:

the following output is produced:

The inputs contain both the tables and the partitions. Note that the table is present even if none of the partitions is accessed in the query.

The dependencies show the parents in case a table is accessed via a view. Consider the following queries:

The following output is produced:

As above, the inputs contain the view V1 and the table 'src' that the view V1 refers to.

All the outputs are shown if a table is being accessed via multiple parents.

The following output is produced.

As can be seen, src is being accessed via parents v1 and v4.

The use of
AUTHORIZATION
in the
EXPLAIN
statement shows all entities needed to be authorized to execute the query and authorization failures if exists. For example, for a query like:

the following output is produced:

With the
FORMATTED
keyword, it will be returned in JSON format.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: