/** * Opens a new session and creates a session handle. The username passed to this method is the * effective username. If withImpersonation is true (==doAs true) we wrap all the calls in * HiveSession within a UGI.doAs, where UGI corresponds to the effective user. * * @see org.apache.hive.service.cli.thrift.ThriftCLIService#getUserName() * @param protocol * @param username * @param password * @param ipAddress * @param sessionConf * @param withImpersonation * @param delegationToken * @return * @throws HiveSQLException */ public SessionHandle openSession( TProtocolVersion protocol, String username, String password, String ipAddress, Map<String, String> sessionConf, boolean withImpersonation, String delegationToken) throws HiveSQLException { HiveSession session; // If doAs is set to true for HiveServer2, we will create a proxy object for the session impl. // Within the proxy object, we wrap the method call in a UserGroupInformation#doAs if (withImpersonation) { HiveSessionImplwithUGI sessionWithUGI = new HiveSessionImplwithUGI( protocol, username, password, hiveConf, ipAddress, delegationToken); session = HiveSessionProxy.getProxy(sessionWithUGI, sessionWithUGI.getSessionUgi()); sessionWithUGI.setProxySession(session); } else { session = new HiveSessionImpl(protocol, username, password, hiveConf, ipAddress); } session.setSessionManager(this); session.setOperationManager(operationManager); try { session.initialize(sessionConf); if (isOperationLogEnabled) { session.setOperationLogSessionDir(operationLogRootDir); } session.open(); } catch (Exception e) { throw new HiveSQLException("Failed to open new session", e); } try { executeSessionHooks(session); } catch (Exception e) { throw new HiveSQLException("Failed to execute session hooks", e); } handleToSession.put(session.getSessionHandle(), session); return session.getSessionHandle(); }