【问题标题】:how to convert a hive query into abstract syntax tree?如何将配置单元查询转换为抽象语法树?
【发布时间】:2013-06-13 10:47:36
【问题描述】:

谁能告诉我如何将配置单元查询转换为抽象语法树? 例如:select * from orders where cust_num = 100; 如何将其转换为 AST?以及如何将此 AST 转换为 QB 树?请帮忙。提前致谢。

【问题讨论】:

    标签: hive abstract-syntax-tree


    【解决方案1】:

    您可以使用EXPLAIN 命令和EXTENDED。假设我有一个名为demo 的表,其列为n1,然后发出解释会给我这个:

    hive> EXPLAIN EXTENDED select * from demo where n1='aaa';
    OK
    ABSTRACT SYNTAX TREE:
      (TOK_QUERY (TOK_FROM (TOK_TABREF (TOK_TABNAME demo))) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR TOK_ALLCOLREF)) (TOK_WHERE (= (TOK_TABLE_OR_COL n1) 'aaa'))))
    
    STAGE DEPENDENCIES:
      Stage-1 is a root stage
      Stage-0 is a root stage
    
    STAGE PLANS:
      Stage: Stage-1
        Map Reduce
          Alias -> Map Operator Tree:
            demo 
              TableScan
                alias: demo
                GatherStats: false
                Filter Operator
                  isSamplingPred: false
                  predicate:
                      expr: (n1 = 'aaa')
                      type: boolean
                  Select Operator
                    expressions:
                          expr: n1
                          type: string
                          expr: n2
                          type: string
                    outputColumnNames: _col0, _col1
                    File Output Operator
                      compressed: false
                      GlobalTableId: 0
                      directory: hdfs://localhost:9000/tmp/hive-apache/hive_2013-06-13_19-55-21_578_6086176948010779575/-ext-10001
                      NumFilesPerFileSink: 1
                      Stats Publishing Key Prefix: hdfs://localhost:9000/tmp/hive-apache/hive_2013-06-13_19-55-21_578_6086176948010779575/-ext-10001/
                      table:
                          input format: org.apache.hadoop.mapred.TextInputFormat
                          output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
                          properties:
                            columns _col0,_col1
                            columns.types string:string
                            escape.delim \
                            serialization.format 1
                      TotalFiles: 1
                      GatherStats: false
                      MultiFileSpray: false
          Needs Tagging: false
          Path -> Alias:
            hdfs://localhost:9000/user/hive/warehouse/demo [demo]
          Path -> Partition:
            hdfs://localhost:9000/user/hive/warehouse/demo 
              Partition
                base file name: demo
                input format: org.apache.hadoop.mapred.TextInputFormat
                output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
                properties:
                  bucket_count -1
                  columns n1,n2
                  columns.types string:string
                  field.delim ,
                  file.inputformat org.apache.hadoop.mapred.TextInputFormat
                  file.outputformat org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
                  location hdfs://localhost:9000/user/hive/warehouse/demo
                  name default.demo
                  serialization.ddl struct demo { string n1, string n2}
                  serialization.format ,
                  serialization.lib org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
                  transient_lastDdlTime 1370932655
                serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
    
                  input format: org.apache.hadoop.mapred.TextInputFormat
                  output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
                  properties:
                    bucket_count -1
                    columns n1,n2
                    columns.types string:string
                    field.delim ,
                    file.inputformat org.apache.hadoop.mapred.TextInputFormat
                    file.outputformat org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat
                    location hdfs://localhost:9000/user/hive/warehouse/demo
                    name default.demo
                    serialization.ddl struct demo { string n1, string n2}
                    serialization.format ,
                    serialization.lib org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
                    transient_lastDdlTime 1370932655
                  serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
                  name: default.demo
                name: default.demo
    
      Stage: Stage-0
        Fetch Operator
          limit: -1
    
    
    Time taken: 5.316 seconds
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-08
      • 2022-11-17
      • 1970-01-01
      • 2016-09-20
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多