参考: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
(二)解决方法
- 找到Hive-2.3.4 源码;
- 修改类: /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;