Search in sources :

Example 46 with OperationHandle

use of org.apache.hive.service.cli.OperationHandle in project hive by apache.

the class HiveSessionImpl method getColumns.

@Override
public OperationHandle getColumns(String catalogName, String schemaName, String tableName, String columnName) throws HiveSQLException {
    acquire(true, true);
    String addedJars = Utilities.getResourceFiles(sessionConf, SessionState.ResourceType.JAR);
    if (StringUtils.isNotBlank(addedJars)) {
        IMetaStoreClient metastoreClient = getSession().getMetaStoreClient();
        metastoreClient.setHiveAddedJars(addedJars);
    }
    OperationManager operationManager = getOperationManager();
    GetColumnsOperation operation = operationManager.newGetColumnsOperation(getSession(), catalogName, schemaName, tableName, columnName);
    OperationHandle opHandle = operation.getHandle();
    try {
        addOpHandle(opHandle);
        operation.run();
        return opHandle;
    } catch (HiveSQLException e) {
        removeOpHandle(opHandle);
        operationManager.closeOperation(opHandle);
        throw e;
    } finally {
        release(true, true);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) OperationManager(org.apache.hive.service.cli.operation.OperationManager) OperationHandle(org.apache.hive.service.cli.OperationHandle) GetColumnsOperation(org.apache.hive.service.cli.operation.GetColumnsOperation)

Example 47 with OperationHandle

use of org.apache.hive.service.cli.OperationHandle in project hive by apache.

the class HiveSessionImpl method getTableTypes.

@Override
public OperationHandle getTableTypes() throws HiveSQLException {
    acquire(true, true);
    OperationManager operationManager = getOperationManager();
    GetTableTypesOperation operation = operationManager.newGetTableTypesOperation(getSession());
    OperationHandle opHandle = operation.getHandle();
    try {
        addOpHandle(opHandle);
        operation.run();
        return opHandle;
    } catch (HiveSQLException e) {
        removeOpHandle(opHandle);
        operationManager.closeOperation(opHandle);
        throw e;
    } finally {
        release(true, true);
    }
}
Also used : GetTableTypesOperation(org.apache.hive.service.cli.operation.GetTableTypesOperation) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) OperationManager(org.apache.hive.service.cli.operation.OperationManager) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 48 with OperationHandle

use of org.apache.hive.service.cli.OperationHandle in project hive by apache.

the class HiveSessionImpl method getFunctions.

@Override
public OperationHandle getFunctions(String catalogName, String schemaName, String functionName) throws HiveSQLException {
    acquire(true, true);
    OperationManager operationManager = getOperationManager();
    GetFunctionsOperation operation = operationManager.newGetFunctionsOperation(getSession(), catalogName, schemaName, functionName);
    OperationHandle opHandle = operation.getHandle();
    try {
        addOpHandle(opHandle);
        operation.run();
        return opHandle;
    } catch (HiveSQLException e) {
        removeOpHandle(opHandle);
        operationManager.closeOperation(opHandle);
        throw e;
    } finally {
        release(true, true);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) GetFunctionsOperation(org.apache.hive.service.cli.operation.GetFunctionsOperation) OperationManager(org.apache.hive.service.cli.operation.OperationManager) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 49 with OperationHandle

use of org.apache.hive.service.cli.OperationHandle in project hive by apache.

the class TestQueryShutdownHooks method testAsync.

@Test
public void testAsync() throws Exception {
    int shutdownHooksBeforeQueries = ShutdownHookManagerInspector.getShutdownHookCount();
    String[] someQueries = { "select reflect(\"java.lang.Thread\", \"sleep\", bigint(1000))", "select reflect(\"java.lang.Thread\", \"sleep\", bigint(1000))", "select reflect(\"java.lang.Thread\", \"sleep\", bigint(1000))", "select reflect(\"java.lang.Thread\", \"sleep\", bigint(1000))" };
    List<OperationHandle> operationHandles = new ArrayList<>();
    for (String queryStr : someQueries) {
        OperationHandle opHandle = client.executeStatementAsync(sessionHandle, queryStr, confOverlay);
        assertNotNull(opHandle);
        operationHandles.add(opHandle);
    }
    boolean allComplete = false;
    final long step = 200;
    final long timeout = System.currentTimeMillis() + ASYNC_QUERY_TIMEOUT_MS;
    while (!allComplete) {
        allComplete = true;
        for (OperationHandle opHandle : operationHandles) {
            OperationStatus operationStatus = client.getOperationStatus(opHandle, false);
            if (operationStatus.getState() != OperationState.FINISHED) {
                if (System.currentTimeMillis() > timeout) {
                    fail("Queries did not complete timely");
                }
                allComplete = false;
                Thread.sleep(step);
                break;
            }
        }
    }
    ShutdownHookManagerInspector.assertShutdownHookCount(shutdownHooksBeforeQueries);
}
Also used : OperationStatus(org.apache.hive.service.cli.OperationStatus) ArrayList(java.util.ArrayList) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 50 with OperationHandle

use of org.apache.hive.service.cli.OperationHandle in project hive by apache.

the class TestSessionGlobalInitFile method verifyInitProperty.

private void verifyInitProperty(String key, String value, SessionHandle sessionHandle) throws Exception {
    OperationHandle operationHandle = client.executeStatement(sessionHandle, "set " + key, null);
    RowSet rowSet = client.fetchResults(operationHandle);
    Assert.assertEquals(1, rowSet.numRows());
    // we know rowSet has only one element
    Assert.assertEquals(key + "=" + value, rowSet.iterator().next()[0]);
    client.closeOperation(operationHandle);
}
Also used : RowSet(org.apache.hive.service.cli.RowSet) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Aggregations

OperationHandle (org.apache.hive.service.cli.OperationHandle)104 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)63 SessionHandle (org.apache.hive.service.cli.SessionHandle)47 Test (org.junit.Test)35 TException (org.apache.thrift.TException)31 RowSet (org.apache.hive.service.cli.RowSet)21 IOException (java.io.IOException)20 UnknownHostException (java.net.UnknownHostException)17 LoginException (javax.security.auth.login.LoginException)17 ServiceException (org.apache.hive.service.ServiceException)17 OperationManager (org.apache.hive.service.cli.operation.OperationManager)14 TProtocolVersion (org.apache.hive.service.rpc.thrift.TProtocolVersion)13 ExploreException (co.cask.cdap.explore.service.ExploreException)12 TOperationHandle (org.apache.hive.service.rpc.thrift.TOperationHandle)12 QueryHandle (co.cask.cdap.proto.QueryHandle)11 OperationStatus (org.apache.hive.service.cli.OperationStatus)8 HashMap (java.util.HashMap)7 CLIServiceClient (org.apache.hive.service.cli.CLIServiceClient)6 ArrayList (java.util.ArrayList)5 OperationState (org.apache.hive.service.cli.OperationState)5