public void testExecuteStatement() throws Exception { HashMap<String, String> confOverlay = new HashMap<String, String>(); SessionHandle sessionHandle = client.openSession( "tom", "password", new HashMap<String, String>()); assertNotNull(sessionHandle); opHandle = client.executeStatement(sessionHandle, queryString, confOverlay); client.closeOperation(opHandle); opHandle = client.executeStatement(sessionHandle, queryString, confOverlay); client.closeOperation(opHandle); opHandle = client.executeStatement(sessionHandle, queryString, confOverlay); client.closeOperation(opHandle); opHandle = client.executeStatement(sessionHandle, queryString, confOverlay); OperationStatus opStatus = client.getOperationStatus(opHandle, false); checkOperationTimes(opHandle, opStatus); OperationState.FINISHED, client.getOperationStatus(opHandle, false).getState()); client.closeOperation(opHandle); opHandle = client.executeStatement(sessionHandle, queryString, confOverlay); client.closeOperation(opHandle); client.closeSession(sessionHandle);
@Override public RowSet fetchResults(OperationHandle opHandle) throws HiveSQLException { return fetchResults(opHandle, FetchOrientation.FETCH_NEXT, defaultFetchRows, FetchType.QUERY_OUTPUT); }
@Override public Void call() throws Exception { if (syncThreadStart) { syncThreadStart(cdlIn, cdlOut); } SessionHandle sessionHandle = openSession(confOverlay); OperationHandle[] hs = new OperationHandle[queryCount]; for (int i = 0; i < hs.length; ++i) { String queryString = String.format(queryStringFormat, i); LOG.info("Submitting " + i); hs[i] = client.executeStatementAsync(sessionHandle, queryString, confOverlay); } for (int i = hs.length - 1; i >= 0; --i) { waitForAsyncQuery(hs[i], expectedOperationState, longPollingTimeout); } return null; } };
@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); }
public SessionHandle openSession(String username, String password) throws HiveSQLException { return openSession(username, password, Collections.<String, String>emptyMap()); }
@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); }
opHandle = client.executeStatement(sessionHandle, queryString, confOverlay); client.closeOperation(opHandle); opHandle = client.executeStatementAsync(sessionHandle, queryString, confOverlay); System.out.println("Cancelling " + opHandle); client.cancelOperation(opHandle); OperationStatus operationStatus = client.getOperationStatus(opHandle, false); checkOperationTimes(opHandle, operationStatus); state = client.getOperationStatus(opHandle, false).getState(); System.out.println(opHandle + " after cancelling, state= " + state); assertEquals("Query should be cancelled", OperationState.CANCELED, state); client.executeStatement(sessionHandle, queryString, confOverlay); client.closeSession(sessionHandle);
private SessionHandle openSession(Map<String, String> confOverlay) throws HiveSQLException { SessionHandle sessionHandle = client.openSession("tom", "password", confOverlay); assertNotNull(sessionHandle); SessionState.get().setIsHiveServerQuery(true); // Pretend we are in HS2. String queryString = "SET " + HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname + " = false"; client.executeStatement(sessionHandle, queryString, confOverlay); return sessionHandle; }
@Override public boolean hasNext() throws LensException { if (fetchedRowsItr == null || !fetchedRowsItr.hasNext()) { try { rowSet = client.fetchResults(opHandle, orientation, fetchSize, FetchType.QUERY_OUTPUT); orientation = FetchOrientation.FETCH_NEXT; noMoreResults = rowSet.numRows() == 0; if (noMoreResults) { if (closeAfterFecth) { log.info("No more results closing the query"); client.closeOperation(opHandle); } return false; } fetchedRowsItr = rowSet.iterator(); } catch (Exception e) { throw new LensException(e); } } return fetchedRowsItr.hasNext(); }
client.executeStatement(sessionHandle, "DROP TABLE " + tableName, confOverlay); client.closeSession(sessionHandle);
@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); } } } } }
qdconf.set("mapred.job.name", ctx.getQueryHandle().toString()); SessionHandle sessionHandle = getSession(ctx); op = getClient().executeStatement(sessionHandle, ctx.getSelectedDriverQuery(), qdconf.getValByRegex(".*")); log.info("The hive operation handle: {}", op); ctx.setDriverOpHandle(op.toString()); opHandleToSession.put(op, sessionHandle); updateStatus(ctx); OperationStatus status = getClient().getOperationStatus(op); if (status.getState() == OperationState.ERROR) { throw new LensException("Unknown error while running query " + ctx.getUserQuery());
opStatus = client.getOperationStatus(opHandle, false); state = opStatus.getState(); longPollingEnd = System.currentTimeMillis(); assertEquals(expectedState, client.getOperationStatus(opHandle, false).getState()); client.closeOperation(opHandle); return opStatus;
+ "(SELECT ID + ' ' `ID` FROM TEST_EXEC_ASYNC) b on a.ID=b.ID"; OperationHandle ophandle = client.executeStatementAsync(sessionHandle, select, confOverlay); status = client.getOperationStatus(ophandle, false); checkOperationTimes(ophandle, status); OperationState state = status.getState();
try { if (isSessionClosable(hiveSession)) { getClient().closeSession(hiveSession); log.info("Closed Hive session {} for lens session {}", hiveSession.getHandleIdentifier(), sessionDbKey);
@Override public boolean cancelQuery(QueryHandle handle) throws LensException { log.info("CancelQuery: {}", handle); OperationHandle hiveHandle = getHiveHandle(handle); opHandleToSession.remove(hiveHandle); try { log.info("CancelQuery hiveHandle: {}", hiveHandle); getClient().cancelOperation(hiveHandle); return true; } catch (HiveSQLException e) { checkInvalidOperation(handle, e); throw new LensException(); } }
private void createTestTable(String tableName, String columnDefinitions, Map<String, String> confOverlay, SessionHandle sessionHandle) throws HiveSQLException { String queryString; // Drop the table if it exists queryString = "DROP TABLE IF EXISTS " + tableName; client.executeStatement(sessionHandle, queryString, confOverlay); // Create a test table queryString = "CREATE TABLE " + tableName + columnDefinitions; client.executeStatement(sessionHandle, queryString, confOverlay); }
public SessionHandle openSession(String username, String password) throws HiveSQLException { return openSession(username, password, Collections.<String, String>emptyMap()); }
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); }