use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestMiniHS2StateWithNoZookeeper method openSessionAndClose.
@Test
public void openSessionAndClose() throws Exception {
CLIServiceClient client = miniHS2.getServiceClient();
SessionHandle sessionHandle = client.openSession(null, null, null);
client.closeSession(sessionHandle);
Thread.sleep(100);
Assert.assertEquals(Service.STATE.STARTED, miniHS2.getState());
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestHiveServer2 method testGetVariableValue.
/**
* Open a new session and execute a set command
* @throws Exception
*/
@Test
public void testGetVariableValue() throws Exception {
CLIServiceClient serviceClient = miniHS2.getServiceClient();
SessionHandle sessHandle = serviceClient.openSession("foo", "bar");
OperationHandle opHandle = serviceClient.executeStatement(sessHandle, "set system:os.name", confOverlay);
RowSet rowSet = serviceClient.fetchResults(opHandle);
assertEquals(1, rowSet.numRows());
serviceClient.closeSession(sessHandle);
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class OperationLoggingAPITestBase method setupSession.
private SessionHandle setupSession() throws Exception {
// Open a session
SessionHandle sessionHandle = client.openSession(null, null, null);
// Change lock manager to embedded mode
String queryString = "SET hive.lock.manager=" + "org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager";
client.executeStatement(sessionHandle, queryString, null);
// Drop the table if it exists
queryString = "DROP TABLE IF EXISTS " + tableName;
client.executeStatement(sessionHandle, queryString, null);
// Create a test table
queryString = "create table " + tableName + " (key int, value string)";
client.executeStatement(sessionHandle, queryString, null);
// Load data
queryString = "load data local inpath '" + dataFile + "' into table " + tableName;
client.executeStatement(sessionHandle, queryString, null);
// Precondition check: verify whether the table is created and data is fetched correctly.
OperationHandle operationHandle = client.executeStatement(sessionHandle, sql, null);
RowSet rowSetResult = client.fetchResults(operationHandle);
Assert.assertEquals(500, rowSetResult.numRows());
Assert.assertEquals(238, rowSetResult.iterator().next()[0]);
Assert.assertEquals("val_238", rowSetResult.iterator().next()[1]);
return sessionHandle;
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class OperationLoggingAPITestBase method testFetchResultsOfLogCleanup.
@Test
public void testFetchResultsOfLogCleanup() throws Exception {
// Verify cleanup functionality.
// Open a new session, since this case needs to close the session in the end.
SessionHandle sessionHandleCleanup = setupSession();
// prepare
OperationHandle operationHandle = client.executeStatement(sessionHandleCleanup, sql, null);
RowSet rowSetLog = client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 1000, FetchType.LOG);
verifyFetchedLog(rowSetLog, expectedLogsVerbose);
File sessionLogDir = new File(hiveConf.getVar(HiveConf.ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LOG_LOCATION) + File.separator + sessionHandleCleanup.getHandleIdentifier());
File operationLogFile = new File(sessionLogDir, operationHandle.getHandleIdentifier().toString());
// check whether exception is thrown when fetching log from a closed operation.
client.closeOperation(operationHandle);
try {
client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 1000, FetchType.LOG);
Assert.fail("Fetch should fail");
} catch (HiveSQLException e) {
Assert.assertTrue(e.getMessage().contains("Invalid OperationHandle:"));
}
// check whether operation log file is deleted.
if (operationLogFile.exists()) {
Assert.fail("Operation log file should be deleted.");
}
// check whether session log dir is deleted after session is closed.
client.closeSession(sessionHandleCleanup);
if (sessionLogDir.exists()) {
Assert.fail("Session log dir should be deleted.");
}
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class BeelineWithHS2ConnectionFileTestBase method createTable.
protected void createTable() throws HiveSQLException {
CLIServiceClient serviceClient = miniHS2.getServiceClient();
SessionHandle sessHandle = serviceClient.openSession("foo", "bar");
serviceClient.executeStatement(sessHandle, "DROP TABLE IF EXISTS " + tableName, confOverlay);
serviceClient.executeStatement(sessHandle, "CREATE TABLE " + tableName + " (id INT)", confOverlay);
OperationHandle opHandle = serviceClient.executeStatement(sessHandle, "SHOW TABLES", confOverlay);
RowSet rowSet = serviceClient.fetchResults(opHandle);
assertFalse(rowSet.numRows() == 0);
}
Aggregations