zoukankan      html  css  js  c++  java
  • 问题一:【Hive】explain command throw ClassCastException in 2.3.4

    参考:https://issues.apache.org/jira/browse/HIVE-21489


    (一)问题描述:

         Hive-2.3.4 执行  explain select * from src in hive-2.3.4

        报错: ClassCastException: org.apache.hadoop.hive.ql.parse.ExplainSemanticAnalyzer cannot be cast to org.apache.hadoop.hive.ql.parse.SemanticAnalyzer

    (二)解决方法

    1. 找到Hive-2.3.4 源码;
    2. 修改类:   /ql/src/java/org/apache/hadoop/hive/ql/Driver.java    
    diff --git a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java
    index cac14a6..70a8028 100644
    --- a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java
    +++ b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java
    @@ -114,6 +114,7 @@
     import org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer;
     import org.apache.hadoop.hive.ql.parse.ColumnAccessInfo;
     import org.apache.hadoop.hive.ql.parse.ExplainConfiguration.AnalyzeState;
    +import org.apache.hadoop.hive.ql.parse.ExplainSemanticAnalyzer;
     import org.apache.hadoop.hive.ql.parse.HiveSemanticAnalyzerHookContext;
     import org.apache.hadoop.hive.ql.parse.HiveSemanticAnalyzerHookContextImpl;
     import org.apache.hadoop.hive.ql.parse.ImportSemanticAnalyzer;
    @@ -1292,10 +1293,14 @@ private static void getTablePartitionUsedColumns(HiveOperation op, BaseSemanticA
         // (par2Cols) or
         // table to columns mapping (tab2Cols)
         if (op.equals(HiveOperation.CREATETABLE_AS_SELECT) || op.equals(HiveOperation.QUERY)) {
    -      SemanticAnalyzer querySem = (SemanticAnalyzer) sem;
    -      ParseContext parseCtx = querySem.getParseContext();
    +      ParseContext parseCtx;
    +      if (sem instanceof ExplainSemanticAnalyzer) {
    +        parseCtx = ((ExplainSemanticAnalyzer)sem).getParseContext();
    +      } else {
    +        parseCtx = ((SemanticAnalyzer)sem).getParseContext();
    +      }
     
    -      for (Map.Entry<String, TableScanOperator> topOpMap : querySem.getParseContext().getTopOps()
    +      for (Map.Entry<String, TableScanOperator> topOpMap : parseCtx.getTopOps()
               .entrySet()) {
             TableScanOperator tableScanOp = topOpMap.getValue();
             if (!tableScanOp.isInsideView()) {

             修改类 :/ql/src/java/org/apache/hadoop/hive/ql/parse/ExplainSemanticAnalyzer.java

    diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/ExplainSemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/ExplainSemanticAnalyzer.java
    index 6d7af38..73ba8e3 100644
    --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/ExplainSemanticAnalyzer.java
    +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/ExplainSemanticAnalyzer.java
    @@ -56,6 +56,7 @@
     public class ExplainSemanticAnalyzer extends BaseSemanticAnalyzer {
       List<FieldSchema> fieldList;
       ExplainConfiguration config;
    +  ParseContext pCtx = null;
     
       public ExplainSemanticAnalyzer(QueryState queryState) throws SemanticException {
         super(queryState);
    @@ -189,7 +190,6 @@ public void analyzeInternal(ASTNode ast) throws SemanticException {
           fetchTask.getWork().initializeForFetch(ctx.getOpContext());
         }
     
    -    ParseContext pCtx = null;
         if (sem instanceof SemanticAnalyzer) {
           pCtx = ((SemanticAnalyzer)sem).getParseContext();
         }
    @@ -285,4 +285,7 @@ public boolean skipAuthorization() {
         return task instanceof ExplainTask && ((ExplainTask)task).getWork().isAuthorize();
       }
     
    +  public ParseContext getParseContext() {
    +    return pCtx;
    +  }
     }

             3. 编译生成class文件,替换hive-exec-2.3.4.jar

             4. 执行以下命令(如果配置有,则不需要)

    set hive.security.authorization.enabled=true;
    set hive.execution.engine=mr;
    set hive.security.authorization.manager=org.apache.hadoop.hive.ql.security.authorization.DefaultHiveAuthorizationProvider;
  • 相关阅读:
    (转载)林轩田机器学习基石课程学习笔记1 — The Learning Problem
    二、HDFS(架构、读写、NN)
    剑指:和为S的两个数字
    剑指:和为S的连续正数序列
    Hive:数据倾斜
    linux如何查看端口被哪个进程占用
    du查看某个文件或目录占用磁盘空间的大小
    剑指:滑动窗口的最大值
    leetcode之求众数
    剑指:重建二叉树
  • 原文地址:https://www.cnblogs.com/shix0909/p/11078695.html
Copyright © 2011-2022 走看看