接触越多,越需要了解hive背后的理论知识以及底层的一些实现细节,会让用户更加高效地使用Hive
--摘于HIVE 编程指南.
----1
使用EXPLAIN
了解Hive是如何工作,第一个就是需要了解EXPLAIN功能
使用例子:
hive >explain select sum(id) from my;
OK
ABSTRACT SYNTAX TREE:
(TOK_QUERY (TOK_FROM (TOK_TABREF (TOK_TABNAME my))) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION sum (TOK_TABLE_OR_COL id))))))
STAGE DEPENDENCIES:
Stage-1 is a root stage
Stage-0 is a root stage
STAGE PLANS:
Stage: Stage-1
Map Reduce --发生在job的map处理阶段过程
Alias -> Map Operator Tree:
my
TableScan --TableScan以my表作为输入
alias: my
Select Operator
expressions:
expr: id
type: int
outputColumnNames: id
Group By Operator
aggregations:
expr: sum(id) --group by Operator会应用到sum(id)
bucketGroup: false
mode: hash
outputColumnNames: _col0 ----为临时结果字段按规则起的临时字段名
Reduce Output Operator
sort order:
tag: -1
value expressions:
expr: _col0
type: bigint
Reduce Operator Tree: --reduce过程
Group By Operator
aggregations:
expr: sum(VALUE._col0)
bucketGroup: false
mode: mergepartial
outputColumnNames: _col0
Select Operator
expressions:
expr: _col0
type: bigint
outputColumnNames: _col0
File Output Operator --在reducer中科院看到File Output Operator,说明输出结果将是文本格式
compressed: false
GlobalTableId: 0
table:
input format: org.apache.hadoop.mapred.TextInputFormat
output format: org.apache.hadoop.hive.ql.io. HiveIgnoreKeyTextOutputFormat ---说明输出结果将是文本格式,基于字符串的输出格式
Stage: Stage-0
Fetch Operator
limit: -1 --job没有limit ,因此是一个没有操作的阶段
解释:
1、TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE) 说明,虽然查询会将结果输出到控制台,但hive实际上会先将输出写入到一个临时文件。
2、Stage: Stage-1 一个Hive任务会包含一个或多个stage