hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sp...@apache.org
Subject hive git commit: HIVE-17048: Pass HiveOperation info to HiveSemanticAnalyzerHook through HiveSemanticAnalyzerHookContext (Aihua Xu, reviewed by Mohit Sabharwal)
Date Mon, 28 Aug 2017 17:42:18 GMT
Repository: hive
Updated Branches:
  refs/heads/branch-2.1 5a62503ff -> 714d7cf75


HIVE-17048: Pass HiveOperation info to HiveSemanticAnalyzerHook through HiveSemanticAnalyzerHookContext
(Aihua Xu, reviewed by Mohit Sabharwal)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/714d7cf7
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/714d7cf7
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/714d7cf7

Branch: refs/heads/branch-2.1
Commit: 714d7cf75c46f2c38ea4732be8653d1915e9a7cf
Parents: 5a62503
Author: Aihua Xu <aihuaxu@apache.org>
Authored: Wed Jul 5 17:38:36 2017 -0700
Committer: Sergio Pena <sergio.pena@cloudera.com>
Committed: Mon Aug 28 12:39:23 2017 -0500

----------------------------------------------------------------------
 .../hive/minikdc/TestHs2HooksWithMiniKdc.java   | 28 +++++++++++---------
 .../apache/hadoop/hive/hooks/TestHs2Hooks.java  | 27 ++++++++++++-------
 .../java/org/apache/hadoop/hive/ql/Driver.java  |  1 +
 .../parse/HiveSemanticAnalyzerHookContext.java  |  5 ++++
 .../HiveSemanticAnalyzerHookContextImpl.java    | 12 +++++++++
 5 files changed, 50 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/714d7cf7/itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestHs2HooksWithMiniKdc.java
----------------------------------------------------------------------
diff --git a/itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestHs2HooksWithMiniKdc.java
b/itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestHs2HooksWithMiniKdc.java
index 4fabe47..1cd0ee8 100644
--- a/itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestHs2HooksWithMiniKdc.java
+++ b/itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestHs2HooksWithMiniKdc.java
@@ -24,7 +24,7 @@ import java.sql.Statement;
 import java.util.HashMap;
 import java.util.Map;
 
-import junit.framework.Assert;
+import org.junit.Assert;
 
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
@@ -114,16 +114,16 @@ public class TestHs2HooksWithMiniKdc {
       throw error;
     }
 
-    Assert.assertNotNull(PostExecHook.ipAddress, "ipaddress is null");
-    Assert.assertNotNull(PostExecHook.userName, "userName is null");
-    Assert.assertNotNull(PostExecHook.operation , "operation is null");
+    Assert.assertNotNull("ipaddress is null", PostExecHook.ipAddress);
+    Assert.assertNotNull("userName is null", PostExecHook.userName);
+    Assert.assertNotNull("operation is null", PostExecHook.operation);
     Assert.assertEquals(MiniHiveKdc.HIVE_TEST_USER_1, PostExecHook.userName);
     Assert.assertTrue(PostExecHook.ipAddress, PostExecHook.ipAddress.contains("127.0.0.1"));
     Assert.assertEquals("SHOWTABLES", PostExecHook.operation);
 
-    Assert.assertNotNull(PreExecHook.ipAddress, "ipaddress is null");
-    Assert.assertNotNull(PreExecHook.userName, "userName is null");
-    Assert.assertNotNull(PreExecHook.operation , "operation is null");
+    Assert.assertNotNull("ipaddress is null", PreExecHook.ipAddress);
+    Assert.assertNotNull("userName is null", PreExecHook.userName);
+    Assert.assertNotNull("operation is null", PreExecHook.operation);
     Assert.assertEquals(MiniHiveKdc.HIVE_TEST_USER_1, PreExecHook.userName);
     Assert.assertTrue(PreExecHook.ipAddress, PreExecHook.ipAddress.contains("127.0.0.1"));
     Assert.assertEquals("SHOWTABLES", PreExecHook.operation);
@@ -137,12 +137,14 @@ public class TestHs2HooksWithMiniKdc {
       throw error;
     }
 
-    Assert.assertNotNull(SemanticAnalysisHook.ipAddress,
-        "semantic hook context ipaddress is null");
-    Assert.assertNotNull(SemanticAnalysisHook.userName,
-        "semantic hook context userName is null");
-    Assert.assertNotNull(SemanticAnalysisHook.command ,
-        "semantic hook context command is null");
+    Assert.assertNotNull("semantic hook context ipaddress is null",
+        SemanticAnalysisHook.ipAddress);
+    Assert.assertNotNull("semantic hook context userName is null",
+        SemanticAnalysisHook.userName);
+    Assert.assertNotNull("semantic hook context command is null",
+        SemanticAnalysisHook.command);
+    Assert.assertNotNull("semantic hook context commandType is null",
+        SemanticAnalysisHook.commandType);
     Assert.assertTrue(SemanticAnalysisHook.ipAddress,
         SemanticAnalysisHook.ipAddress.contains("127.0.0.1"));
     Assert.assertEquals("show tables", SemanticAnalysisHook.command);

http://git-wip-us.apache.org/repos/asf/hive/blob/714d7cf7/itests/hive-unit/src/test/java/org/apache/hadoop/hive/hooks/TestHs2Hooks.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/hooks/TestHs2Hooks.java
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/hooks/TestHs2Hooks.java
index 6f3e779..dad516c 100644
--- a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/hooks/TestHs2Hooks.java
+++ b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/hooks/TestHs2Hooks.java
@@ -25,7 +25,7 @@ import java.sql.Statement;
 import java.util.List;
 import java.util.Properties;
 
-import junit.framework.Assert;
+import org.junit.Assert;
 
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
@@ -36,6 +36,7 @@ import org.apache.hadoop.hive.ql.parse.ASTNode;
 import org.apache.hadoop.hive.ql.parse.HiveSemanticAnalyzerHook;
 import org.apache.hadoop.hive.ql.parse.HiveSemanticAnalyzerHookContext;
 import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.ql.plan.HiveOperation;
 import org.apache.hadoop.hive.ql.exec.Task;
 import org.apache.hive.jdbc.HiveConnection;
 import org.apache.hive.service.server.HiveServer2;
@@ -98,6 +99,7 @@ public class TestHs2Hooks {
   public static class SemanticAnalysisHook implements HiveSemanticAnalyzerHook {
     public static String userName;
     public static String command;
+    public static HiveOperation commandType;
     public static String ipAddress;
     public static Throwable preAnalyzeError;
     public static Throwable postAnalyzeError;
@@ -109,6 +111,7 @@ public class TestHs2Hooks {
         userName = context.getUserName();
         ipAddress = context.getIpAddress();
         command = context.getCommand();
+        commandType = context.getHiveOperation();
       } catch (Throwable t) {
         LOG.error("Error in semantic analysis hook preAnalyze: " + t, t);
         preAnalyzeError = t;
@@ -123,6 +126,7 @@ public class TestHs2Hooks {
         userName = context.getUserName();
         ipAddress = context.getIpAddress();
         command = context.getCommand();
+        commandType = context.getHiveOperation();
       } catch (Throwable t) {
         LOG.error("Error in semantic analysis hook postAnalyze: " + t, t);
         postAnalyzeError = t;
@@ -170,6 +174,7 @@ public class TestHs2Hooks {
     SemanticAnalysisHook.userName = null;
     SemanticAnalysisHook.ipAddress = null;
     SemanticAnalysisHook.command = null;
+    SemanticAnalysisHook.commandType = null;
     SemanticAnalysisHook.preAnalyzeError = null;
     SemanticAnalysisHook.postAnalyzeError = null;
   }
@@ -203,9 +208,9 @@ public class TestHs2Hooks {
     Assert.assertEquals("SHOWTABLES", PostExecHook.operation);
 
     Assert.assertEquals(System.getProperty("user.name"), PreExecHook.userName);
-    Assert.assertNotNull(PreExecHook.ipAddress, "ipaddress is null");
-    Assert.assertNotNull(PreExecHook.userName, "userName is null");
-    Assert.assertNotNull(PreExecHook.operation , "operation is null");
+    Assert.assertNotNull("ipaddress is null", PreExecHook.ipAddress);
+    Assert.assertNotNull("userName is null", PreExecHook.userName);
+    Assert.assertNotNull("operation is null", PreExecHook.operation);
     Assert.assertTrue(PreExecHook.ipAddress, PreExecHook.ipAddress.contains("127.0.0.1"));
     Assert.assertEquals("SHOWTABLES", PreExecHook.operation);
 
@@ -218,12 +223,14 @@ public class TestHs2Hooks {
       throw error;
     }
 
-    Assert.assertNotNull(SemanticAnalysisHook.ipAddress,
-        "semantic hook context ipaddress is null");
-    Assert.assertNotNull(SemanticAnalysisHook.userName,
-        "semantic hook context userName is null");
-    Assert.assertNotNull(SemanticAnalysisHook.command ,
-        "semantic hook context command is null");
+    Assert.assertNotNull("semantic hook context ipaddress is null",
+        SemanticAnalysisHook.ipAddress);
+    Assert.assertNotNull("semantic hook context userName is null",
+        SemanticAnalysisHook.userName);
+    Assert.assertNotNull("semantic hook context command is null",
+        SemanticAnalysisHook.command);
+    Assert.assertNotNull("semantic hook context commandType is null",
+        SemanticAnalysisHook.commandType);
     Assert.assertTrue(SemanticAnalysisHook.ipAddress,
         SemanticAnalysisHook.ipAddress.contains("127.0.0.1"));
     Assert.assertEquals("show tables", SemanticAnalysisHook.command);

http://git-wip-us.apache.org/repos/asf/hive/blob/714d7cf7/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 895ee84..6702481 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java
@@ -465,6 +465,7 @@ public class Driver implements CommandProcessor {
         hookCtx.setUserName(userName);
         hookCtx.setIpAddress(SessionState.get().getUserIpAddress());
         hookCtx.setCommand(command);
+        hookCtx.setHiveOperation(queryState.getHiveOperation());
         for (HiveSemanticAnalyzerHook hook : saHooks) {
           tree = hook.preAnalyze(hookCtx, tree);
         }

http://git-wip-us.apache.org/repos/asf/hive/blob/714d7cf7/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveSemanticAnalyzerHookContext.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveSemanticAnalyzerHookContext.java
b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveSemanticAnalyzerHookContext.java
index b78ce90..166375c 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveSemanticAnalyzerHookContext.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveSemanticAnalyzerHookContext.java
@@ -25,6 +25,7 @@ import org.apache.hadoop.hive.ql.hooks.ReadEntity;
 import org.apache.hadoop.hive.ql.hooks.WriteEntity;
 import org.apache.hadoop.hive.ql.metadata.Hive;
 import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.plan.HiveOperation;
 
 /**
  * Context information provided by Hive to implementations of
@@ -65,4 +66,8 @@ public interface HiveSemanticAnalyzerHookContext extends Configurable{
   public String getCommand();
 
   public void setCommand(String command);
+
+  public HiveOperation getHiveOperation();
+
+  public void setHiveOperation(HiveOperation commandType);
 }

http://git-wip-us.apache.org/repos/asf/hive/blob/714d7cf7/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveSemanticAnalyzerHookContextImpl.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveSemanticAnalyzerHookContextImpl.java
b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveSemanticAnalyzerHookContextImpl.java
index 4ce705b..1cc38a8 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveSemanticAnalyzerHookContextImpl.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveSemanticAnalyzerHookContextImpl.java
@@ -26,6 +26,7 @@ import org.apache.hadoop.hive.ql.hooks.ReadEntity;
 import org.apache.hadoop.hive.ql.hooks.WriteEntity;
 import org.apache.hadoop.hive.ql.metadata.Hive;
 import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.plan.HiveOperation;
 
 public class HiveSemanticAnalyzerHookContextImpl implements HiveSemanticAnalyzerHookContext
{
 
@@ -35,6 +36,7 @@ public class HiveSemanticAnalyzerHookContextImpl implements HiveSemanticAnalyzer
   private String userName;
   private String ipAddress;
   private String command;
+  private HiveOperation commandType;
 
   @Override
   public Hive getHive() throws HiveException {
@@ -95,4 +97,14 @@ public class HiveSemanticAnalyzerHookContextImpl implements HiveSemanticAnalyzer
   public void setCommand(String command) {
     this.command = command;
   }
+
+  @Override
+  public HiveOperation getHiveOperation() {
+    return commandType;
+  }
+
+  @Override
+  public void setHiveOperation(HiveOperation commandType) {
+    this.commandType = commandType;
+  }
 }


Mime
View raw message