Source:
<code>public GrillSessionHandle openSession(String username, String password, Map<String, String> configuration) throws GrillException { SessionHandle sessionHandle; doPasswdAuth(username, password, cliService.getHiveConf().getVar(ConfVars.HIVE_SERVER2_AUTHENTICATION)); try { Map<String, String> sessionConf = new HashMap<String, String>(); sessionConf.putAll(GrillSessionImpl.DEFAULT_HIVE_SESSION_CONF); if (configuration != null) { sessionConf.putAll(configuration); } String clusterUser = getClusterUser(username, sessionConf, cliService.getHiveConf()); <START> sessionConf.put(GrillConfConstants.GRILL_QUERY_LOGGED_IN_USER, username); <END> sessionConf.put(ConfVars.HIVEQUERYRUNASUSER.varname, clusterUser); password = "useless"; if ( cliService.getHiveConf().getVar(ConfVars.HIVE_SERVER2_AUTHENTICATION) .equals(HiveAuthFactory.AuthTypes.KERBEROS.toString()) && cliService.getHiveConf(). getBoolVar(ConfVars.HIVE_SERVER2_ENABLE_DOAS) ) { String delegationTokenStr = null; try { delegationTokenStr = cliService.getDelegationTokenFromMetaStore(username); } catch (UnsupportedOperationException e) { } sessionHandle = cliService.openSessionWithImpersonation(clusterUser, password, sessionConf, delegationTokenStr); } else { sessionHandle = cliService.openSession(clusterUser, password, sessionConf); } } catch (Exception e) { throw new GrillException (e); } GrillSessionHandle grillSession = new GrillSessionHandle( sessionHandle.getHandleIdentifier().getPublicId(), sessionHandle.getHandleIdentifier().getSecretId()); sessionMap.put(grillSession.getPublicId().toString(), grillSession); return grillSession; }</code><technical_language>add a method in GrillSessionImpl getLoggedinUser()? finished queried stats need persist logged in user. I added QueryContext also</technical_language>

Target:
public GrillSessionHandle openSession(String username, String password, Map<String, String> configuration) throws GrillException { SessionHandle sessionHandle; username = UtilityMethods.removeDomain(username); doPasswdAuth(username, password); try { Map<String, String> sessionConf = new HashMap<String, String>(); sessionConf.putAll(GrillSessionImpl.DEFAULT_HIVE_SESSION_CONF); if (configuration != null) { sessionConf.putAll(configuration); } Map<String, String> userConfig = UserConfigLoaderFactory.getUserConfig(username); UtilityMethods.mergeMaps(sessionConf, userConfig, false); sessionConf.put(GrillConfConstants.GRILL_SESSION_LOGGEDIN_USER, username); if(sessionConf.get(GrillConfConstants.GRILL_SESSION_CLUSTER_USER) == null) { LOG.info("Didn't get cluster user from user config loader. Setting same as logged in user: " + username); sessionConf.put(GrillConfConstants.GRILL_SESSION_CLUSTER_USER, username); } String clusterUser = sessionConf.get(GrillConfConstants.GRILL_SESSION_CLUSTER_USER); password = "useless"; if ( cliService.getHiveConf().getVar(ConfVars.HIVE_SERVER2_AUTHENTICATION) .equals(HiveAuthFactory.AuthTypes.KERBEROS.toString()) && cliService.getHiveConf(). getBoolVar(ConfVars.HIVE_SERVER2_ENABLE_DOAS) ) { String delegationTokenStr = null; try { delegationTokenStr = cliService.getDelegationTokenFromMetaStore(username); } catch (UnsupportedOperationException e) { } sessionHandle = cliService.openSessionWithImpersonation(clusterUser, password, sessionConf, delegationTokenStr); } else { sessionHandle = cliService.openSession(clusterUser, password, sessionConf); } } catch (Exception e) { throw new GrillException (e); } GrillSessionHandle grillSession = new GrillSessionHandle( sessionHandle.getHandleIdentifier().getPublicId(), sessionHandle.getHandleIdentifier().getSecretId()); sessionMap.put(grillSession.getPublicId().toString(), grillSession); return grillSession; }