use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class ThriftCliServiceTestWithCookie 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);
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class MiniHS2 method waitForStartup.
private void waitForStartup() throws Exception {
int waitTime = 0;
long startupTimeout = 1000L * 1000L;
CLIServiceClient hs2Client = getServiceClientInternal();
SessionHandle sessionHandle = null;
do {
Thread.sleep(500L);
waitTime += 500L;
if (waitTime > startupTimeout) {
throw new TimeoutException("Couldn't access new HiveServer2: " + getJdbcURL());
}
try {
Map<String, String> sessionConf = new HashMap<String, String>();
/**
* if (isUseMiniKdc()) {
* getMiniKdc().loginUser(getMiniKdc().getDefaultUserPrincipal());
* sessionConf.put("principal", serverPrincipal);
* }
*/
sessionHandle = hs2Client.openSession("foo", "bar", sessionConf);
} catch (Exception e) {
// service not started yet
continue;
}
hs2Client.closeSession(sessionHandle);
break;
} while (true);
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestHiveServer2SessionTimeout method testConnection.
@Test
public void testConnection() throws Exception {
CLIServiceClient serviceClient = miniHS2.getServiceClient();
SessionHandle sessHandle = serviceClient.openSession("foo", "bar");
OperationHandle handle = serviceClient.executeStatement(sessHandle, "SELECT 1", confOverlay);
Thread.sleep(7000);
try {
serviceClient.closeOperation(handle);
fail("Operation should have been closed by timeout!");
} catch (HiveSQLException e) {
assertTrue(StringUtils.stringifyException(e), e.getMessage().contains("Invalid OperationHandle"));
}
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class ThriftCLIService method GetFunctions.
@Override
public TGetFunctionsResp GetFunctions(TGetFunctionsReq req) throws TException {
TGetFunctionsResp resp = new TGetFunctionsResp();
try {
OperationHandle opHandle = cliService.getFunctions(new SessionHandle(req.getSessionHandle()), req.getCatalogName(), req.getSchemaName(), req.getFunctionName());
resp.setOperationHandle(opHandle.toTOperationHandle());
resp.setStatus(OK_STATUS);
} catch (Exception e) {
LOG.warn("Error getting functions: ", e);
resp.setStatus(HiveSQLException.toTStatus(e));
}
return resp;
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class ThriftCLIService method GetTables.
@Override
public TGetTablesResp GetTables(TGetTablesReq req) throws TException {
TGetTablesResp resp = new TGetTablesResp();
try {
OperationHandle opHandle = cliService.getTables(new SessionHandle(req.getSessionHandle()), req.getCatalogName(), req.getSchemaName(), req.getTableName(), req.getTableTypes());
resp.setOperationHandle(opHandle.toTOperationHandle());
resp.setStatus(OK_STATUS);
} catch (Exception e) {
LOG.warn("Error getting tables: ", e);
resp.setStatus(HiveSQLException.toTStatus(e));
}
return resp;
}
Aggregations