use of org.apache.hive.service.cli.HiveSQLException in project cdap by caskdata.
the class BaseHiveExploreService method fetchStatus.
protected QueryStatus fetchStatus(OperationInfo operationInfo) throws ExploreException, HandleNotFoundException, HiveSQLException {
QueryStatus queryStatus;
try {
queryStatus = doFetchStatus(operationInfo.getOperationHandle());
if (QueryStatus.OpStatus.ERROR.equals(queryStatus.getStatus()) && queryStatus.getErrorMessage() == null) {
queryStatus = new QueryStatus("Operation failed. See the log for more details.", null);
}
} catch (HiveSQLException e) {
// it means that query execution failed, but we can successfully retrieve the status.
if (e.getSQLState() != null) {
queryStatus = new QueryStatus(e.getMessage(), e.getSQLState());
} else {
// this is an internal error - we are not able to retrieve the status
throw new ExploreException(e.getMessage(), e);
}
}
operationInfo.setStatus(queryStatus);
return queryStatus;
}
use of org.apache.hive.service.cli.HiveSQLException in project cdap by caskdata.
the class BaseHiveExploreService method getCatalogs.
@Override
public QueryHandle getCatalogs() throws ExploreException, SQLException {
startAndWait();
try {
SessionHandle sessionHandle = null;
OperationHandle operationHandle = null;
Map<String, String> sessionConf = startSession();
try {
sessionHandle = openHiveSession(sessionConf);
operationHandle = cliService.getCatalogs(sessionHandle);
QueryHandle handle = saveReadOnlyOperation(operationHandle, sessionHandle, sessionConf, "", "");
LOG.trace("Retrieving catalogs");
return handle;
} catch (Throwable e) {
closeInternal(getQueryHandle(sessionConf), new ReadOnlyOperationInfo(sessionHandle, operationHandle, sessionConf, "", ""));
throw e;
}
} catch (HiveSQLException e) {
throw getSqlException(e);
} catch (Throwable e) {
throw new ExploreException(e);
}
}
use of org.apache.hive.service.cli.HiveSQLException in project cdap by caskdata.
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