hive学习(8)--- Hive任务转换为MP的原理分析(通过explain查看hive映射到mp的stage)

来源:互联网 发布:马思纯演技 知乎 编辑:程序博客网 时间:2024/05/22 13:04

Hive任务分析

       如果要深入学习hive,那数据倾斜的问题是必然要面临的,又称为hive调优。想要调优,就必须了解hive是如何把hql转换成MP程序的,转换的规则是什么,只有知道规则,才能分析它的过程,从而有针对性的优化。

       Hive通常以hql的形式执行,它的本质是MP程序。不同的hql,会根据自己的规则,转换成不同的MP任务,比如比较简单的hql,会转成一个job(包括一个map和一个reduce),比较复杂的hql(如三表联合),会转成成3个job。

       hive提供了explain命令,用于告诉用户hql会转成成哪些stage以及每个stage会干什么。这为深入学习hive提供了可能。

 

先来看一个简单的例子:

hive> explain select * from weather where city='beijin' limit 5;

OK

ABSTRACT SYNTAX TREE:

  (TOK_QUERY (TOK_FROM (TOK_TABREF(TOK_TABNAME weather))) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE))(TOK_SELECT (TOK_SELEXPR TOK_ALLCOLREF)) (TOK_WHERE (= (TOK_TABLE_OR_COL city)'beijin')) (TOK_LIMIT 5)))

 

STAGE DEPENDENCIES:

  Stage-1 is a root stage

  Stage-0 is a root stage

 

STAGE PLANS:

  Stage: Stage-1

    Map Reduce

      Alias -> Map OperatorTree:

        weather

          TableScan

            alias: weather

            Filter Operator

              predicate:

                  expr: (city ='beijin')

                  type: boolean

              Select Operator

                expressions:

                      expr: date

                      type: string

                      expr:country

                      type: string

                      expr: city

                      type: string

                      expr: weath

                      type: string

                      expr:mintemperat

                      type: int

                      expr:maxtemperat

                      type: int

                      expr:pmvalue

                      type: int

                outputColumnNames:_col0, _col1, _col2, _col3, _col4, _col5, _col6

                Limit

                  File OutputOperator

                    compressed: false

                    GlobalTableId:0

                    table:

                        inputformat: org.apache.hadoop.mapred.TextInputFormat

                        outputformat: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat

 

  Stage: Stage-0

    Fetch Operator

      limit: 5

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

参考文章:

http://blog.csdn.net/kntao/article/details/12837329

http://yugouai.iteye.com/blog/1850816

 

0 0