diff --git ql/src/java/org/apache/hadoop/hive/ql/Driver.java ql/src/java/org/apache/hadoop/hive/ql/Driver.java index 68e7003..49a3536 100644 --- ql/src/java/org/apache/hadoop/hive/ql/Driver.java +++ ql/src/java/org/apache/hadoop/hive/ql/Driver.java @@ -505,7 +505,7 @@ public static void doAuthorization(BaseSemanticAnalyzer sem) HashSet inputs = sem.getInputs(); HashSet outputs = sem.getOutputs(); SessionState ss = SessionState.get(); - HiveOperation op = sem.getHiveOperation(); + HiveOperation op = ss.getHiveOperation(); Hive db = sem.getDb(); if (ss.isAuthorizationModeV2()) { doAuthorizationV2(ss, op, inputs, outputs); diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/ExplainTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/ExplainTask.java index 3ec3960..92545d8 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/ExplainTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/ExplainTask.java @@ -311,7 +311,7 @@ private JSONObject collectAuthRelatedEntities(PrintStream out, ExplainWork work) throws Exception { BaseSemanticAnalyzer analyzer = work.getAnalyzer(); - HiveOperation operation = analyzer.getHiveOperation(); + HiveOperation operation = SessionState.get().getHiveOperation(); JSONObject object = new JSONObject(); Object jsonInput = toJson("INPUTS", toString(analyzer.getInputs()), out, work); diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java index 75394f3..60d54b6 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java @@ -67,7 +67,6 @@ import org.apache.hadoop.hive.ql.metadata.Table; import org.apache.hadoop.hive.ql.optimizer.listbucketingpruner.ListBucketingPrunerUtils; import org.apache.hadoop.hive.ql.plan.ExprNodeDesc; -import org.apache.hadoop.hive.ql.plan.HiveOperation; import org.apache.hadoop.hive.ql.plan.ListBucketingCtx; import org.apache.hadoop.hive.ql.plan.PlanUtils; import org.apache.hadoop.hive.ql.session.SessionState; @@ -105,8 +104,6 @@ public static int HIVE_COLUMN_ORDER_ASC = 1; public static int HIVE_COLUMN_ORDER_DESC = 0; - protected HiveOperation hiveOperation; - /** * ReadEntitites that are passed to the hooks. */ @@ -145,14 +142,6 @@ protected static final String PARQUETFILE_OUTPUT = MapredParquetOutputFormat.class.getName(); protected static final String PARQUETFILE_SERDE = ParquetHiveSerDe.class.getName(); - public HiveOperation getHiveOperation() { - return hiveOperation; - } - - public void setHiveOperation(HiveOperation hiveOperation) { - this.hiveOperation = hiveOperation; - } - public boolean skipAuthorization() { return false; } diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java index 3c14af8..b6f3748 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java @@ -147,33 +147,10 @@ public static BaseSemanticAnalyzer get(HiveConf conf, ASTNode tree) throws SemanticException { - BaseSemanticAnalyzer analyzer = getAnalyzer(conf, tree); - - HiveOperation operation; - if (tree.getType() == HiveParser.TOK_ALTERTABLE_PARTITION) { - Integer type = tree.getChild(1).getType(); - if (tree.getChild(0).getChildCount() > 1) { - operation = tablePartitionCommandType.get(type)[1]; - } else { - operation = tablePartitionCommandType.get(type)[0]; - } - } else { - operation = commandType.get(tree.getType()); - } - analyzer.setHiveOperation(operation); - - if (SessionState.get() != null) { - SessionState.get().setCommandType(operation); - } - - return analyzer; - } - - private static BaseSemanticAnalyzer getAnalyzer(HiveConf conf, ASTNode tree) - throws SemanticException { if (tree.getToken() == null) { throw new RuntimeException("Empty Syntax Tree"); } else { + setSessionCommandType(commandType.get(tree.getToken().getType())); switch (tree.getToken().getType()) { case HiveParser.TOK_EXPLAIN: @@ -255,6 +232,14 @@ private static BaseSemanticAnalyzer getAnalyzer(HiveConf conf, ASTNode tree) return new DDLSemanticAnalyzer(conf); case HiveParser.TOK_ALTERTABLE_PARTITION: + HiveOperation commandType = null; + Integer type = ((ASTNode) tree.getChild(1)).getToken().getType(); + if (tree.getChild(0).getChildCount() > 1) { + commandType = tablePartitionCommandType.get(type)[1]; + } else { + commandType = tablePartitionCommandType.get(type)[0]; + } + setSessionCommandType(commandType); return new DDLSemanticAnalyzer(conf); case HiveParser.TOK_CREATEFUNCTION: @@ -273,6 +258,12 @@ private static BaseSemanticAnalyzer getAnalyzer(HiveConf conf, ASTNode tree) } } + private static void setSessionCommandType(HiveOperation commandType) { + if (SessionState.get() != null) { + SessionState.get().setCommandType(commandType); + } + } + private SemanticAnalyzerFactory() { // prevent instantiation }