HIVE-12456: QueryId can't be stored in the configuration of the SessionState 
since multiple queries can run in a single session (Aihua Xu, reviewed by Mohit)


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

Branch: refs/heads/master-fixed
Commit: f15d4e108103fd2b1c42345634e167e41ded42f9
Parents: 5f726d5
Author: Aihua Xu <aihu...@apache.org>
Authored: Mon Nov 23 12:20:39 2015 -0500
Committer: Owen O'Malley <omal...@apache.org>
Committed: Tue Nov 24 12:10:09 2015 -0800

----------------------------------------------------------------------
 .../cli/operation/ExecuteStatementOperation.java | 15 +--------------
 .../hive/service/cli/operation/Operation.java    | 19 +++++++++++++++----
 .../hive/service/cli/operation/SQLOperation.java |  4 ++--
 .../service/cli/session/HiveSessionImpl.java     |  1 -
 4 files changed, 18 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/f15d4e10/service/src/java/org/apache/hive/service/cli/operation/ExecuteStatementOperation.java
----------------------------------------------------------------------
diff --git 
a/service/src/java/org/apache/hive/service/cli/operation/ExecuteStatementOperation.java
 
b/service/src/java/org/apache/hive/service/cli/operation/ExecuteStatementOperation.java
index 3f2de10..b3d9b52 100644
--- 
a/service/src/java/org/apache/hive/service/cli/operation/ExecuteStatementOperation.java
+++ 
b/service/src/java/org/apache/hive/service/cli/operation/ExecuteStatementOperation.java
@@ -18,7 +18,6 @@
 package org.apache.hive.service.cli.operation;
 
 import java.sql.SQLException;
-import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.hadoop.hive.ql.processors.CommandProcessor;
@@ -29,13 +28,11 @@ import org.apache.hive.service.cli.session.HiveSession;
 
 public abstract class ExecuteStatementOperation extends Operation {
   protected String statement = null;
-  protected Map<String, String> confOverlay = new HashMap<String, String>();
 
   public ExecuteStatementOperation(HiveSession parentSession, String statement,
       Map<String, String> confOverlay, boolean runInBackground) {
-    super(parentSession, OperationType.EXECUTE_STATEMENT, runInBackground);
+    super(parentSession, confOverlay, OperationType.EXECUTE_STATEMENT, 
runInBackground);
     this.statement = statement;
-    setConfOverlay(confOverlay);
   }
 
   public String getStatement() {
@@ -57,14 +54,4 @@ public abstract class ExecuteStatementOperation extends 
Operation {
     }
     return new HiveCommandOperation(parentSession, statement, processor, 
confOverlay);
   }
-
-  protected Map<String, String> getConfOverlay() {
-    return confOverlay;
-  }
-
-  protected void setConfOverlay(Map<String, String> confOverlay) {
-    if (confOverlay != null) {
-      this.confOverlay = confOverlay;
-    }
-  }
 }

http://git-wip-us.apache.org/repos/asf/hive/blob/f15d4e10/service/src/java/org/apache/hive/service/cli/operation/Operation.java
----------------------------------------------------------------------
diff --git 
a/service/src/java/org/apache/hive/service/cli/operation/Operation.java 
b/service/src/java/org/apache/hive/service/cli/operation/Operation.java
index d13415e..25cefc2 100644
--- a/service/src/java/org/apache/hive/service/cli/operation/Operation.java
+++ b/service/src/java/org/apache/hive/service/cli/operation/Operation.java
@@ -21,11 +21,14 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
 import com.google.common.collect.Sets;
+
 import org.apache.hadoop.hive.common.metrics.common.Metrics;
 import org.apache.hadoop.hive.common.metrics.common.MetricsConstant;
 import org.apache.hadoop.hive.common.metrics.common.MetricsFactory;
@@ -50,8 +53,8 @@ import org.apache.logging.log4j.ThreadContext;
 
 public abstract class Operation {
   // Constants of the key strings for the log4j ThreadContext.
-  private static final String QUERYID = "QueryId";
-  private static final String SESSIONID = "SessionId";
+  public static final String SESSIONID_LOG_KEY = "sessionId";
+  public static final String QUERYID_LOG_KEY = "queryId";
 
   protected final HiveSession parentSession;
   private OperationState state = OperationState.INITIALIZED;
@@ -67,6 +70,7 @@ public abstract class Operation {
   protected volatile Future<?> backgroundHandle;
   protected OperationLog operationLog;
   protected boolean isOperationLogEnabled;
+  protected Map<String, String> confOverlay = new HashMap<String, String>();
 
   private long operationTimeout;
   private long lastAccessTime;
@@ -75,7 +79,14 @@ public abstract class Operation {
       EnumSet.of(FetchOrientation.FETCH_NEXT,FetchOrientation.FETCH_FIRST);
 
   protected Operation(HiveSession parentSession, OperationType opType, boolean 
runInBackground) {
+    this(parentSession, null, opType, runInBackground);
+ }
+
+  protected Operation(HiveSession parentSession, Map<String, String> 
confOverlay, OperationType opType, boolean runInBackground) {
     this.parentSession = parentSession;
+    if (confOverlay != null) {
+      this.confOverlay = confOverlay;
+    }
     this.runAsync = runInBackground;
     this.opHandle = new OperationHandle(opType, 
parentSession.getProtocolVersion());
     lastAccessTime = System.currentTimeMillis();
@@ -258,8 +269,8 @@ public abstract class Operation {
    * Register logging context so that Log4J can print QueryId and/or SessionId 
for each message
    */
   protected void registerLoggingContext() {
-    ThreadContext.put(QUERYID, SessionState.get().getQueryId());
-    ThreadContext.put(SESSIONID, SessionState.get().getSessionId());
+    ThreadContext.put(SESSIONID_LOG_KEY, SessionState.get().getSessionId());
+    ThreadContext.put(QUERYID_LOG_KEY, 
confOverlay.get(HiveConf.ConfVars.HIVEQUERYID.varname));
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hive/blob/f15d4e10/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
----------------------------------------------------------------------
diff --git 
a/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java 
b/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
index 8b42265..1331a99 100644
--- a/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
+++ b/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
@@ -466,12 +466,12 @@ public class SQLOperation extends 
ExecuteStatementOperation {
    */
   private HiveConf getConfigForOperation() throws HiveSQLException {
     HiveConf sqlOperationConf = getParentSession().getHiveConf();
-    if (!getConfOverlay().isEmpty() || shouldRunAsync()) {
+    if (!confOverlay.isEmpty() || shouldRunAsync()) {
       // clone the partent session config for this query
       sqlOperationConf = new HiveConf(sqlOperationConf);
 
       // apply overlay query specific settings, if any
-      for (Map.Entry<String, String> confEntry : getConfOverlay().entrySet()) {
+      for (Map.Entry<String, String> confEntry : confOverlay.entrySet()) {
         try {
           sqlOperationConf.verifyAndSet(confEntry.getKey(), 
confEntry.getValue());
         } catch (IllegalArgumentException e) {

http://git-wip-us.apache.org/repos/asf/hive/blob/f15d4e10/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java
----------------------------------------------------------------------
diff --git 
a/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java 
b/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java
index 2d784f0..a14908b 100644
--- a/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java
+++ b/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java
@@ -443,7 +443,6 @@ public class HiveSessionImpl implements HiveSession {
     if (queryId == null || queryId.isEmpty()) {
       queryId = QueryPlan.makeQueryId();
       confOverlay.put(HiveConf.ConfVars.HIVEQUERYID.varname, queryId);
-      sessionState.getConf().setVar(HiveConf.ConfVars.HIVEQUERYID, queryId);
     }
 
     OperationManager operationManager = getOperationManager();

Reply via email to