use of org.apache.hive.service.cli.HiveSQLException in project cdap by caskdata.
the class Hive12CDH5ExploreService method doFetchStatus.
@Override
protected QueryStatus doFetchStatus(OperationHandle handle) throws HiveSQLException, ExploreException, HandleNotFoundException {
OperationStatus operationStatus = getCliService().getOperationStatus(handle);
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") HiveSQLException hiveExn = operationStatus.getOperationException();
if (hiveExn != null) {
return new QueryStatus(hiveExn.getMessage(), hiveExn.getSQLState());
}
return new QueryStatus(QueryStatus.OpStatus.valueOf(operationStatus.getState().toString()), handle.hasResultSet());
}
use of org.apache.hive.service.cli.HiveSQLException in project cdap by caskdata.
the class Hive13ExploreService method doFetchStatus.
@Override
protected QueryStatus doFetchStatus(OperationHandle operationHandle) throws HiveSQLException, ExploreException, HandleNotFoundException {
OperationStatus operationStatus = getCliService().getOperationStatus(operationHandle);
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") HiveSQLException hiveExn = operationStatus.getOperationException();
if (hiveExn != null) {
return new QueryStatus(hiveExn.getMessage(), hiveExn.getSQLState());
}
return new QueryStatus(QueryStatus.OpStatus.valueOf(operationStatus.getState().toString()), operationHandle.hasResultSet());
}
use of org.apache.hive.service.cli.HiveSQLException in project cdap by caskdata.
the class BaseHiveExploreService method getColumns.
@Override
public QueryHandle getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws ExploreException, SQLException {
startAndWait();
try {
SessionHandle sessionHandle = null;
OperationHandle operationHandle = null;
Map<String, String> sessionConf = startSession();
String database = getHiveDatabase(schemaPattern);
try {
sessionHandle = openHiveSession(sessionConf);
operationHandle = cliService.getColumns(sessionHandle, catalog, database, tableNamePattern, columnNamePattern);
QueryHandle handle = saveReadOnlyOperation(operationHandle, sessionHandle, sessionConf, "", database);
LOG.trace("Retrieving columns: catalog {}, schemaPattern {}, tableNamePattern {}, columnNamePattern {}", catalog, database, tableNamePattern, columnNamePattern);
return handle;
} catch (Throwable e) {
closeInternal(getQueryHandle(sessionConf), new ReadOnlyOperationInfo(sessionHandle, operationHandle, sessionConf, "", database));
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 hive by apache.
the class TestHiveSessionImpl method testLeakOperationHandle.
/**
* Verifying OperationManager.closeOperation(opHandle) is invoked when
* get HiveSQLException during sync query
* @throws HiveSQLException
*/
@Test
public void testLeakOperationHandle() throws HiveSQLException {
// create HiveSessionImpl object
TProtocolVersion protocol = TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V2;
String username = "";
String password = "";
HiveConf serverhiveConf = new HiveConf();
String ipAddress = null;
HiveSessionImpl session = new HiveSessionImpl(null, protocol, username, password, serverhiveConf, ipAddress, null) {
@Override
protected synchronized void acquire(boolean userAccess, boolean isOperation) {
}
@Override
protected synchronized void release(boolean userAccess, boolean isOperation) {
}
};
// mock operationManager for session
OperationManager operationManager = Mockito.mock(OperationManager.class);
session.setOperationManager(operationManager);
// mock operation and opHandle for operationManager
ExecuteStatementOperation operation = Mockito.mock(ExecuteStatementOperation.class);
OperationHandle opHandle = Mockito.mock(OperationHandle.class);
Mockito.when(operation.getHandle()).thenReturn(opHandle);
Map<String, String> confOverlay = new HashMap<String, String>();
String hql = "drop table if exists table_not_exists";
Mockito.when(operationManager.newExecuteStatementOperation(same(session), eq(hql), (Map<String, String>) Mockito.any(), eq(true), eq(0L))).thenReturn(operation);
try {
// Running a normal async query with no exceptions,then no need to close opHandle
session.open(new HashMap<String, String>());
session.executeStatementAsync(hql, confOverlay);
Mockito.verify(operationManager, Mockito.times(0)).closeOperation(opHandle);
// Throw an HiveSqlException when do async calls
Mockito.doThrow(new HiveSQLException("Fail for clean up test")).when(operation).run();
session.executeStatementAsync(hql, confOverlay);
Assert.fail("HiveSqlException expected.");
} catch (HiveSQLException e) {
if (!"Fail for clean up test".equals(e.getMessage())) {
Assert.fail("unexpected exception:" + Arrays.toString(e.getStackTrace()));
}
// operationManager.closeOperation() is expected to be invoked once
Mockito.verify(operationManager, Mockito.times(1)).closeOperation(opHandle);
}
}
use of org.apache.hive.service.cli.HiveSQLException in project hive by apache.
the class ExecuteStatementOperation method newExecuteStatementOperation.
public static ExecuteStatementOperation newExecuteStatementOperation(HiveSession parentSession, String statement, Map<String, String> confOverlay, boolean runAsync, long queryTimeout) throws HiveSQLException {
String cleanStatement = HiveStringUtils.removeComments(statement);
String[] tokens = cleanStatement.trim().split("\\s+");
CommandProcessor processor = null;
try {
processor = CommandProcessorFactory.getForHiveCommand(tokens, parentSession.getHiveConf());
} catch (SQLException e) {
throw new HiveSQLException(e.getMessage(), e.getSQLState(), e);
}
if (processor == null) {
// Pass the original statement to SQLOperation as sql parser can remove comments by itself
return new SQLOperation(parentSession, statement, confOverlay, runAsync, queryTimeout);
}
return new HiveCommandOperation(parentSession, cleanStatement, processor, confOverlay);
}
Aggregations