use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestQueryDisplay method testQueryDisplay.
/**
* Test if query display captures information on current/historic SQL operations.
*/
@Test
public void testQueryDisplay() throws Exception {
HiveSession session = sessionManager.createSession(new SessionHandle(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8), TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8, "testuser", "", "", new HashMap<String, String>(), false, "");
SessionState.start(conf);
OperationHandle opHandle1 = session.executeStatement("show databases", null);
SessionState.start(conf);
OperationHandle opHandle2 = session.executeStatement("show tables", null);
List<QueryInfo> liveSqlOperations, historicSqlOperations;
liveSqlOperations = sessionManager.getOperationManager().getLiveQueryInfos();
historicSqlOperations = sessionManager.getOperationManager().getHistoricalQueryInfos();
Assert.assertEquals(liveSqlOperations.size(), 2);
Assert.assertEquals(historicSqlOperations.size(), 0);
verifyDDL(liveSqlOperations.get(0), "show databases", opHandle1.getHandleIdentifier().toString(), false);
verifyDDL(liveSqlOperations.get(1), "show tables", opHandle2.getHandleIdentifier().toString(), false);
session.closeOperation(opHandle1);
liveSqlOperations = sessionManager.getOperationManager().getLiveQueryInfos();
historicSqlOperations = sessionManager.getOperationManager().getHistoricalQueryInfos();
Assert.assertEquals(liveSqlOperations.size(), 1);
Assert.assertEquals(historicSqlOperations.size(), 1);
verifyDDL(historicSqlOperations.get(0), "show databases", opHandle1.getHandleIdentifier().toString(), true);
verifyDDL(liveSqlOperations.get(0), "show tables", opHandle2.getHandleIdentifier().toString(), false);
session.closeOperation(opHandle2);
liveSqlOperations = sessionManager.getOperationManager().getLiveQueryInfos();
historicSqlOperations = sessionManager.getOperationManager().getHistoricalQueryInfos();
Assert.assertEquals(liveSqlOperations.size(), 0);
Assert.assertEquals(historicSqlOperations.size(), 2);
verifyDDL(historicSqlOperations.get(1), "show databases", opHandle1.getHandleIdentifier().toString(), true);
verifyDDL(historicSqlOperations.get(0), "show tables", opHandle2.getHandleIdentifier().toString(), true);
session.close();
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class ThriftCLIService method getSessionHandle.
/**
* Create a session handle
* @param req
* @param res
* @return
* @throws HiveSQLException
* @throws LoginException
* @throws IOException
*/
SessionHandle getSessionHandle(TOpenSessionReq req, TOpenSessionResp res) throws HiveSQLException, LoginException, IOException {
String userName = getUserName(req);
String ipAddress = getIpAddress();
TProtocolVersion protocol = getMinVersion(CLIService.SERVER_VERSION, req.getClient_protocol());
SessionHandle sessionHandle;
if (cliService.getHiveConf().getBoolVar(ConfVars.HIVE_SERVER2_ENABLE_DOAS) && (userName != null)) {
String delegationTokenStr = getDelegationToken(userName);
sessionHandle = cliService.openSessionWithImpersonation(protocol, userName, req.getPassword(), ipAddress, req.getConfiguration(), delegationTokenStr);
} else {
sessionHandle = cliService.openSession(protocol, userName, req.getPassword(), ipAddress, req.getConfiguration());
}
res.setServerProtocolVersion(protocol);
return sessionHandle;
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestSessionGlobalInitFile method doTestSessionGlobalInitFile.
/**
* create session, and fetch the property set in global init file. Test if
* the global init file .hiverc is loaded correctly by checking the expected
* setting property.
*/
private void doTestSessionGlobalInitFile() throws Exception {
OperationManager operationManager = service.getService().getSessionManager().getOperationManager();
SessionHandle sessionHandle = client.openSession(null, null, null);
// ensure there is no operation related object leak
Assert.assertEquals("Verifying all operations used for init file are closed", 0, operationManager.getOperations().size());
verifyInitProperty("a", "1", sessionHandle);
verifyInitProperty("b", "1", sessionHandle);
verifyInitProperty("c", "1", sessionHandle);
verifyInitProperty("hivevar:c", "1", sessionHandle);
verifyInitProperty("d", "1", sessionHandle);
/**
* TODO: client.executeStatement do not support listing resources command
* (beeline> list jar)
*/
// Assert.assertEquals("expected uri", api.getAddedResource("jar"));
Assert.assertEquals("Verifying all operations used for checks are closed", 0, operationManager.getOperations().size());
client.closeSession(sessionHandle);
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestSessionGlobalInitFile method testSessionGlobalInitFileWithUser.
@Test
public void testSessionGlobalInitFileWithUser() throws Exception {
// Test when the session is opened by a user. (HiveSessionImplwithUGI)
SessionHandle sessionHandle = client.openSession("hive", "password", null);
verifyInitProperty("a", "1", sessionHandle);
client.closeSession(sessionHandle);
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class ThriftCLIServiceTest method testExecuteStatement.
/**
* Test synchronous query execution
* @throws Exception
*/
@Test
public void testExecuteStatement() throws Exception {
Map<String, String> opConf = new HashMap<String, String>();
// Open a new client session
SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, opConf);
// Session handle should not be null
assertNotNull("Session handle should not be null", sessHandle);
// Change lock manager to embedded mode
String queryString = "SET hive.lock.manager=" + "org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager";
client.executeStatement(sessHandle, queryString, opConf);
// Drop the table if it exists
queryString = "DROP TABLE IF EXISTS TEST_EXEC_THRIFT";
client.executeStatement(sessHandle, queryString, opConf);
// Create a test table
queryString = "CREATE TABLE TEST_EXEC_THRIFT(ID STRING)";
client.executeStatement(sessHandle, queryString, opConf);
// Execute another query
queryString = "SELECT ID+1 FROM TEST_EXEC_THRIFT";
OperationHandle opHandle = client.executeStatement(sessHandle, queryString, opConf);
assertNotNull(opHandle);
OperationStatus opStatus = client.getOperationStatus(opHandle, false);
assertNotNull(opStatus);
OperationState state = opStatus.getState();
// Expect query to be completed now
assertEquals("Query should be finished", OperationState.FINISHED, state);
// Cleanup
queryString = "DROP TABLE TEST_EXEC_THRIFT";
client.executeStatement(sessHandle, queryString, opConf);
client.closeSession(sessHandle);
}
Aggregations