@Test public void testOpenSession() throws Exception { SessionHandle sessionHandle = client.openSession( "tom", "password", Collections.<String, String>emptyMap()); assertNotNull(sessionHandle); client.closeSession(sessionHandle); sessionHandle = client.openSession("tom", "password"); assertNotNull(sessionHandle); client.closeSession(sessionHandle); }
@Test public void testGetInfo() throws Exception { SessionHandle sessionHandle = client.openSession( "tom", "password", Collections.<String, String>emptyMap()); assertNotNull(sessionHandle); GetInfoValue value = client.getInfo(sessionHandle, GetInfoType.CLI_DBMS_NAME); System.out.println(value.getStringValue()); value = client.getInfo(sessionHandle, GetInfoType.CLI_SERVER_NAME); System.out.println(value.getStringValue()); value = client.getInfo(sessionHandle, GetInfoType.CLI_DBMS_VER); System.out.println(value.getStringValue()); client.closeSession(sessionHandle); }
client.closeSession(sessionHandle);
client.closeSession(sessionHandle);
opHandle = client.executeStatement(sessionHandle, queryString, confOverlay); client.closeOperation(opHandle); client.closeSession(sessionHandle);
opHandle = client.executeStatement(sessionHandle, dropTable, null); client.closeOperation(opHandle); client.closeSession(sessionHandle);
client.closeSession(sessionHandle);
@Test public void testGetFunctions() throws Exception { SessionHandle sessionHandle = client.openSession("tom", "password"); assertNotNull(sessionHandle); OperationHandle opHandle = client.getFunctions(sessionHandle, null, null, "*"); TableSchema schema = client.getResultSetMetadata(opHandle); ColumnDescriptor columnDesc = schema.getColumnDescriptorAt(0); assertEquals("FUNCTION_CAT", columnDesc.getName()); assertEquals(Type.STRING_TYPE, columnDesc.getType()); columnDesc = schema.getColumnDescriptorAt(1); assertEquals("FUNCTION_SCHEM", columnDesc.getName()); assertEquals(Type.STRING_TYPE, columnDesc.getType()); columnDesc = schema.getColumnDescriptorAt(2); assertEquals("FUNCTION_NAME", columnDesc.getName()); assertEquals(Type.STRING_TYPE, columnDesc.getType()); columnDesc = schema.getColumnDescriptorAt(3); assertEquals("REMARKS", columnDesc.getName()); assertEquals(Type.STRING_TYPE, columnDesc.getType()); columnDesc = schema.getColumnDescriptorAt(4); assertEquals("FUNCTION_TYPE", columnDesc.getName()); assertEquals(Type.INT_TYPE, columnDesc.getType()); columnDesc = schema.getColumnDescriptorAt(5); assertEquals("SPECIFIC_NAME", columnDesc.getName()); assertEquals(Type.STRING_TYPE, columnDesc.getType()); // Cleanup client.closeOperation(opHandle); client.closeSession(sessionHandle); }
try { if (isSessionClosable(hiveSession)) { getClient().closeSession(hiveSession); log.info("Closed Hive session {} for lens session {}", hiveSession.getHandleIdentifier(), sessionDbKey);
try { if (isSessionClosable(hiveSession)) { getClient().closeSession(hiveSession); log.info("Closed Hive session {} for lens session {}", hiveSession.getHandleIdentifier(), sessionDbKey);
@Override public void closeQuery(QueryHandle handle) throws LensException { if (handle == null) { return; } log.info("CloseQuery: {}", handle); OperationHandle opHandle = hiveHandles.remove(handle); if (opHandle != null) { log.info("CloseQuery hiveHandle: {}", opHandle); try { fetchLogs(opHandle); getClient().closeOperation(opHandle); } catch (HiveSQLException e) { checkInvalidOperation(handle, e); throw new LensException("Unable to close query", e); } finally { SessionHandle hiveSession = opHandleToSession.remove(opHandle); if (null != hiveSession && !opHandleToSession.containsValue(hiveSession) && orphanedHiveSessions.contains(hiveSession)) { orphanedHiveSessions.remove(hiveSession); try { getClient().closeSession(hiveSession); log.info("Closed orphaned hive session : {}", hiveSession.getHandleIdentifier()); } catch (HiveSQLException e) { log.warn("Error closing orphan hive session : {} ", hiveSession.getHandleIdentifier(), e); } } } } }
@Override public void closeQuery(QueryHandle handle) throws LensException { if (handle == null) { return; } log.info("CloseQuery: {}", handle); OperationHandle opHandle = hiveHandles.remove(handle); if (opHandle != null) { log.info("CloseQuery hiveHandle: {}", opHandle); try { fetchLogs(opHandle); getClient().closeOperation(opHandle); } catch (HiveSQLException e) { checkInvalidOperation(handle, e); throw new LensException("Unable to close query", e); } finally { SessionHandle hiveSession = opHandleToSession.remove(opHandle); if (null != hiveSession && !opHandleToSession.containsValue(hiveSession) && orphanedHiveSessions.contains(hiveSession)) { orphanedHiveSessions.remove(hiveSession); try { getClient().closeSession(hiveSession); log.info("Closed orphaned hive session : {}", hiveSession.getHandleIdentifier()); } catch (HiveSQLException e) { log.warn("Error closing orphan hive session : {} ", hiveSession.getHandleIdentifier(), e); } } } } }
private void waitForStartup() throws Exception { int waitTime = 0; long startupTimeout = 1000L * 1000000000L; 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 { sessionHandle = hs2Client.openSession("foo", "bar"); } catch (Exception e) { // service not started yet continue; } hs2Client.closeSession(sessionHandle); break; } while (true); }