Search in sources :

Example 11 with TProtocolVersion

use of org.apache.hive.service.rpc.thrift.TProtocolVersion in project hive by apache.

the class ThriftCLIServiceClient method getTables.

/* (non-Javadoc)
   * @see org.apache.hive.service.cli.ICLIService#getTables(org.apache.hive.service.cli.SessionHandle, java.lang.String, java.lang.String, java.lang.String, java.util.List)
   */
@Override
public OperationHandle getTables(SessionHandle sessionHandle, String catalogName, String schemaName, String tableName, List<String> tableTypes) throws HiveSQLException {
    try {
        TGetTablesReq req = new TGetTablesReq(sessionHandle.toTSessionHandle());
        req.setTableName(tableName);
        req.setTableTypes(tableTypes);
        req.setSchemaName(schemaName);
        TGetTablesResp resp = cliService.GetTables(req);
        checkStatus(resp.getStatus());
        TProtocolVersion protocol = sessionHandle.getProtocolVersion();
        return new OperationHandle(resp.getOperationHandle(), protocol);
    } catch (HiveSQLException e) {
        throw e;
    } catch (Exception e) {
        throw new HiveSQLException(e);
    }
}
Also used : TGetTablesResp(org.apache.hive.service.rpc.thrift.TGetTablesResp) TProtocolVersion(org.apache.hive.service.rpc.thrift.TProtocolVersion) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TGetTablesReq(org.apache.hive.service.rpc.thrift.TGetTablesReq) OperationHandle(org.apache.hive.service.cli.OperationHandle) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException)

Example 12 with TProtocolVersion

use of org.apache.hive.service.rpc.thrift.TProtocolVersion in project hive by apache.

the class ThriftCLIServiceClient method getColumns.

/* (non-Javadoc)
   * @see org.apache.hive.service.cli.ICLIService#getColumns(org.apache.hive.service.cli.SessionHandle)
   */
@Override
public OperationHandle getColumns(SessionHandle sessionHandle, String catalogName, String schemaName, String tableName, String columnName) throws HiveSQLException {
    try {
        TGetColumnsReq req = new TGetColumnsReq();
        req.setSessionHandle(sessionHandle.toTSessionHandle());
        req.setCatalogName(catalogName);
        req.setSchemaName(schemaName);
        req.setTableName(tableName);
        req.setColumnName(columnName);
        TGetColumnsResp resp = cliService.GetColumns(req);
        checkStatus(resp.getStatus());
        TProtocolVersion protocol = sessionHandle.getProtocolVersion();
        return new OperationHandle(resp.getOperationHandle(), protocol);
    } catch (HiveSQLException e) {
        throw e;
    } catch (Exception e) {
        throw new HiveSQLException(e);
    }
}
Also used : TProtocolVersion(org.apache.hive.service.rpc.thrift.TProtocolVersion) TGetColumnsReq(org.apache.hive.service.rpc.thrift.TGetColumnsReq) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) OperationHandle(org.apache.hive.service.cli.OperationHandle) TGetColumnsResp(org.apache.hive.service.rpc.thrift.TGetColumnsResp) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException)

Example 13 with TProtocolVersion

use of org.apache.hive.service.rpc.thrift.TProtocolVersion 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) {

        @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:" + e.getMessage());
        }
        //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)

Aggregations

TProtocolVersion (org.apache.hive.service.rpc.thrift.TProtocolVersion)13 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)11 OperationHandle (org.apache.hive.service.cli.OperationHandle)11 TException (org.apache.thrift.TException)10 HashMap (java.util.HashMap)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 SessionHandle (org.apache.hive.service.cli.SessionHandle)1 ExecuteStatementOperation (org.apache.hive.service.cli.operation.ExecuteStatementOperation)1 OperationManager (org.apache.hive.service.cli.operation.OperationManager)1 TExecuteStatementReq (org.apache.hive.service.rpc.thrift.TExecuteStatementReq)1 TExecuteStatementResp (org.apache.hive.service.rpc.thrift.TExecuteStatementResp)1 TGetCatalogsReq (org.apache.hive.service.rpc.thrift.TGetCatalogsReq)1 TGetCatalogsResp (org.apache.hive.service.rpc.thrift.TGetCatalogsResp)1 TGetColumnsReq (org.apache.hive.service.rpc.thrift.TGetColumnsReq)1 TGetColumnsResp (org.apache.hive.service.rpc.thrift.TGetColumnsResp)1 TGetCrossReferenceReq (org.apache.hive.service.rpc.thrift.TGetCrossReferenceReq)1 TGetCrossReferenceResp (org.apache.hive.service.rpc.thrift.TGetCrossReferenceResp)1 TGetFunctionsReq (org.apache.hive.service.rpc.thrift.TGetFunctionsReq)1 TGetFunctionsResp (org.apache.hive.service.rpc.thrift.TGetFunctionsResp)1 TGetPrimaryKeysReq (org.apache.hive.service.rpc.thrift.TGetPrimaryKeysReq)1