use of io.cdap.cdap.proto.QueryStatus in project cdap by caskdata.
the class CLITestBase method assertExploreQuerySuccess.
private void assertExploreQuerySuccess(ListenableFuture<ExploreExecutionResult> dbCreationFuture) throws Exception {
ExploreExecutionResult exploreExecutionResult = dbCreationFuture.get(10, TimeUnit.SECONDS);
QueryStatus status = exploreExecutionResult.getStatus();
Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
}
use of io.cdap.cdap.proto.QueryStatus in project cdap by cdapio.
the class CLITestBase method assertExploreQuerySuccess.
private void assertExploreQuerySuccess(ListenableFuture<ExploreExecutionResult> dbCreationFuture) throws Exception {
ExploreExecutionResult exploreExecutionResult = dbCreationFuture.get(10, TimeUnit.SECONDS);
QueryStatus status = exploreExecutionResult.getStatus();
Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
}
use of io.cdap.cdap.proto.QueryStatus in project cdap by cdapio.
the class BaseHiveExploreService method nextResults.
@Override
public List<QueryResult> nextResults(QueryHandle handle, int size) throws ExploreException, HandleNotFoundException, SQLException {
startAndWait();
InactiveOperationInfo inactiveOperationInfo = inactiveHandleCache.getIfPresent(handle);
if (inactiveOperationInfo != null) {
// Operation has been made inactive, so all results should have been fetched already - return empty list.
LOG.trace("Returning empty result for inactive handle {}", handle);
return ImmutableList.of();
}
try {
List<QueryResult> results = fetchNextResults(handle, size);
QueryStatus status = getStatus(handle);
if (results.isEmpty() && status.getStatus() == QueryStatus.OpStatus.FINISHED) {
// Since operation has fetched all the results, handle can be timed out aggressively.
timeoutAggressively(handle, getResultSchema(handle), status);
}
return results;
} catch (HiveSQLException e) {
throw getSqlException(e);
}
}
use of io.cdap.cdap.proto.QueryStatus in project cdap by cdapio.
the class BaseHiveExploreService method getStatus.
@Override
public QueryStatus getStatus(QueryHandle handle) throws ExploreException, HandleNotFoundException, SQLException {
startAndWait();
InactiveOperationInfo inactiveOperationInfo = inactiveHandleCache.getIfPresent(handle);
if (inactiveOperationInfo != null) {
// Operation has been made inactive, so return the saved status.
LOG.trace("Returning saved status for inactive handle {}", handle);
return inactiveOperationInfo.getStatus();
}
try {
// Fetch status from Hive
QueryStatus status = fetchStatus(getActiveOperationInfo(handle));
LOG.trace("Status of handle {} is {}", handle, status);
// No results or error, so can be timed out aggressively
if (status.getStatus() == QueryStatus.OpStatus.FINISHED && !status.hasResults()) {
// In case of a query that writes to a Dataset, we will always fall into this condition,
// and timing out aggressively will also close the transaction and make the writes visible
timeoutAggressively(handle, getResultSchema(handle), status);
} else if (status.getStatus() == QueryStatus.OpStatus.ERROR) {
// getResultSchema will fail if the query is in error
timeoutAggressively(handle, ImmutableList.<ColumnDesc>of(), status);
}
return status;
} catch (HiveSQLException e) {
throw getSqlException(e);
}
}
use of io.cdap.cdap.proto.QueryStatus in project cdap by cdapio.
the class BaseHiveExploreService method execute.
@Override
public QueryHandle execute(NamespaceId namespace, String[] statements) throws ExploreException, SQLException {
Preconditions.checkArgument(statements.length > 0, "There must be at least one statement");
startAndWait();
try {
SessionHandle sessionHandle = null;
OperationHandle operationHandle = null;
Map<String, String> sessionConf = startSession(namespace);
String database = getHiveDatabase(namespace.getNamespace());
try {
sessionHandle = openHiveSession(sessionConf);
// Switch database to the one being passed in.
setCurrentDatabase(database);
// synchronously execute all but the last statement
for (int i = 0; i < statements.length - 1; i++) {
String statement = statements[i];
LOG.trace("Executing statement synchronously: {}", statement);
operationHandle = executeSync(sessionHandle, statement);
QueryStatus status = doFetchStatus(operationHandle);
if (QueryStatus.OpStatus.ERROR == status.getStatus()) {
throw new HiveSQLException(status.getErrorMessage(), status.getSqlState());
}
if (QueryStatus.OpStatus.FINISHED != status.getStatus()) {
throw new ExploreException("Expected operation status FINISHED for statement '{}' but received " + status.getStatus());
}
}
String statement = statements[statements.length - 1];
operationHandle = executeAsync(sessionHandle, statement);
QueryHandle handle = saveReadWriteOperation(operationHandle, sessionHandle, sessionConf, statement, database);
LOG.trace("Executing statement: {} with handle {}", statement, handle);
return handle;
} catch (Throwable e) {
closeInternal(getQueryHandle(sessionConf), new ReadWriteOperationInfo(sessionHandle, operationHandle, sessionConf, "", database));
throw e;
}
} catch (HiveSQLException e) {
throw getSqlException(e);
} catch (Throwable e) {
throw new ExploreException(e);
}
}
Aggregations