Search in sources :

Example 66 with HiveSQLException

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());
}
Also used : OperationStatus(org.apache.hive.service.cli.OperationStatus) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) QueryStatus(co.cask.cdap.proto.QueryStatus)

Example 67 with HiveSQLException

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());
}
Also used : OperationStatus(org.apache.hive.service.cli.OperationStatus) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) QueryStatus(co.cask.cdap.proto.QueryStatus)

Example 68 with HiveSQLException

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);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) SessionHandle(org.apache.hive.service.cli.SessionHandle) QueryHandle(co.cask.cdap.proto.QueryHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) ExploreException(co.cask.cdap.explore.service.ExploreException)

Example 69 with HiveSQLException

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);
    }
}
Also used : ExecuteStatementOperation(org.apache.hive.service.cli.operation.ExecuteStatementOperation) TProtocolVersion(org.apache.hive.service.rpc.thrift.TProtocolVersion) HashMap(java.util.HashMap) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) HiveConf(org.apache.hadoop.hive.conf.HiveConf) OperationManager(org.apache.hive.service.cli.operation.OperationManager) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 70 with HiveSQLException

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);
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) SQLException(java.sql.SQLException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) CommandProcessor(org.apache.hadoop.hive.ql.processors.CommandProcessor)

Aggregations

HiveSQLException (org.apache.hive.service.cli.HiveSQLException)88 OperationHandle (org.apache.hive.service.cli.OperationHandle)39 TException (org.apache.thrift.TException)26 SessionHandle (org.apache.hive.service.cli.SessionHandle)20 ExploreException (co.cask.cdap.explore.service.ExploreException)14 IOException (java.io.IOException)12 QueryHandle (co.cask.cdap.proto.QueryHandle)11 TProtocolVersion (org.apache.hive.service.rpc.thrift.TProtocolVersion)11 OperationManager (org.apache.hive.service.cli.operation.OperationManager)10 TOperationHandle (org.apache.hive.service.rpc.thrift.TOperationHandle)10 QueryStatus (co.cask.cdap.proto.QueryStatus)7 SQLException (java.sql.SQLException)7 IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)7 OperationStatus (org.apache.hive.service.cli.OperationStatus)5 TableSchema (org.apache.hive.service.cli.TableSchema)5 Test (org.junit.Test)5 FileNotFoundException (java.io.FileNotFoundException)4 ArrayList (java.util.ArrayList)4 Metrics (org.apache.hadoop.hive.common.metrics.common.Metrics)3 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)3