use of org.apache.hive.service.cli.OperationState in project hive by apache.
the class TestOperationLoggingAPIWithMr method testFetchResultsOfLogAsync.
@Test
public void testFetchResultsOfLogAsync() throws Exception {
// verify whether the sql operation log is generated and fetch correctly in async mode.
OperationHandle operationHandle = client.executeStatementAsync(sessionHandle, sql, null);
// Poll on the operation status till the query is completed
boolean isQueryRunning = true;
long pollTimeout = System.currentTimeMillis() + 100000;
OperationStatus opStatus;
OperationState state = null;
RowSet rowSetAccumulated = null;
StringBuilder logs = new StringBuilder();
while (isQueryRunning) {
// Break if polling times out
if (System.currentTimeMillis() > pollTimeout) {
break;
}
opStatus = client.getOperationStatus(operationHandle, false);
Assert.assertNotNull(opStatus);
state = opStatus.getState();
rowSetAccumulated = client.fetchResults(operationHandle, FetchOrientation.FETCH_NEXT, 2000, FetchType.LOG);
for (Object[] row : rowSetAccumulated) {
logs.append(row[0]);
}
if (state == OperationState.CANCELED || state == OperationState.CLOSED || state == OperationState.FINISHED || state == OperationState.ERROR) {
isQueryRunning = false;
}
Thread.sleep(10);
}
// The sql should be completed now.
Assert.assertEquals("Query should be finished", OperationState.FINISHED, state);
// Verify the accumulated logs
verifyFetchedLogPost(logs.toString(), expectedLogsVerbose, true);
// Verify the fetched logs from the beginning of the log file
RowSet rowSet = client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 2000, FetchType.LOG);
verifyFetchedLog(rowSet, expectedLogsVerbose);
}
use of org.apache.hive.service.cli.OperationState in project hive by apache.
the class OperationManager method cancelOperation.
/**
* Cancel the running operation unless it is already in a terminal state
* @param opHandle
* @throws HiveSQLException
*/
public void cancelOperation(OperationHandle opHandle) throws HiveSQLException {
Operation operation = getOperation(opHandle);
OperationState opState = operation.getStatus().getState();
if (opState.isTerminal()) {
// Cancel should be a no-op in either cases
LOG.debug(opHandle + ": Operation is already aborted in state - " + opState);
} else {
LOG.debug(opHandle + ": Attempting to cancel from state - " + opState);
operation.cancel(OperationState.CANCELED);
if (operation instanceof SQLOperation) {
removeSaveSqlOperationDisplay(opHandle);
}
}
}
use of org.apache.hive.service.cli.OperationState in project cdap by caskdata.
the class Hive12ExploreService method doFetchStatus.
@Override
protected QueryStatus doFetchStatus(OperationHandle operationHandle) throws HiveSQLException, ExploreException, HandleNotFoundException {
try {
// In Hive 12, CLIService.getOperationStatus returns OperationState.
// In Hive 13, CLIService.getOperationStatus returns OperationStatus.
// Since we use Hive 13 for dev, we need the following workaround to get Hive 12 working.
Class<? extends CLIService> cliServiceClass = getCliService().getClass();
Method m = cliServiceClass.getMethod("getOperationStatus", OperationHandle.class);
OperationState operationState = (OperationState) m.invoke(getCliService(), operationHandle);
return new QueryStatus(QueryStatus.OpStatus.valueOf(operationState.toString()), operationHandle.hasResultSet());
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
throw Throwables.propagate(e);
}
}
use of org.apache.hive.service.cli.OperationState in project hive by apache.
the class OperationManager method cancelOperation.
/**
* Cancel the running operation unless it is already in a terminal state
* @param opHandle operation handle
* @param errMsg error message
* @throws HiveSQLException
*/
public void cancelOperation(OperationHandle opHandle, String errMsg) throws HiveSQLException {
Operation operation = getOperation(opHandle);
OperationState opState = operation.getStatus().getState();
if (opState.isTerminal()) {
// Cancel should be a no-op in either cases
LOG.debug(opHandle + ": Operation is already aborted in state - " + opState);
} else {
LOG.debug(opHandle + ": Attempting to cancel from state - " + opState);
OperationState operationState = OperationState.CANCELED;
operationState.setErrorMessage(errMsg);
operation.cancel(operationState);
if (operation instanceof SQLOperation) {
removeSafeQueryInfo(opHandle);
}
}
}
use of org.apache.hive.service.cli.OperationState in project hive by apache.
the class SQLOperation method getNextRowSet.
@Override
public RowSet getNextRowSet(FetchOrientation orientation, long maxRows) throws HiveSQLException {
validateDefaultFetchOrientation(orientation);
assertState(new ArrayList<OperationState>(Arrays.asList(OperationState.FINISHED)));
FetchTask fetchTask = driver.getFetchTask();
boolean isBlobBased = false;
if (fetchTask != null && fetchTask.getWork().isUsingThriftJDBCBinarySerDe()) {
// Just fetch one blob if we've serialized thrift objects in final tasks
maxRows = 1;
isBlobBased = true;
}
driver.setMaxRows((int) maxRows);
RowSet rowSet = RowSetFactory.create(resultSchema, getProtocolVersion(), isBlobBased);
try {
/* if client is requesting fetch-from-start and its not the first time reading from this operation
* then reset the fetch position to beginning
*/
if (orientation.equals(FetchOrientation.FETCH_FIRST) && fetchStarted) {
driver.resetFetch();
}
fetchStarted = true;
driver.setMaxRows((int) maxRows);
if (driver.getResults(convey)) {
return decode(convey, rowSet);
}
return rowSet;
} catch (IOException e) {
throw new HiveSQLException(e);
} catch (Exception e) {
throw new HiveSQLException(e);
} finally {
convey.clear();
}
}
Aggregations