Search in sources :

Example 21 with OperationHandle

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

the class HiveSessionImpl method close.

@Override
public void close() throws HiveSQLException {
    try {
        acquire(true, false);
        // Iterate through the opHandles and close their operations
        List<OperationHandle> ops = null;
        synchronized (opHandleSet) {
            ops = new ArrayList<>(opHandleSet);
            opHandleSet.clear();
        }
        for (OperationHandle opHandle : ops) {
            operationManager.closeOperation(opHandle);
        }
        // Cleanup session log directory.
        cleanupSessionLogDir();
        HiveHistory hiveHist = sessionState.getHiveHistory();
        if (null != hiveHist) {
            hiveHist.closeStream();
        }
        try {
            sessionState.resetThreadName();
            sessionState.close();
        } finally {
            sessionState = null;
        }
    } catch (IOException ioe) {
        throw new HiveSQLException("Failure to close", ioe);
    } finally {
        if (sessionState != null) {
            try {
                sessionState.resetThreadName();
                sessionState.close();
            } catch (Throwable t) {
                LOG.warn("Error closing session", t);
            }
            sessionState = null;
        }
        if (sessionHive != null) {
            try {
                Hive.closeCurrent();
            } catch (Throwable t) {
                LOG.warn("Error closing sessionHive", t);
            }
            sessionHive = null;
        }
        release(true, false);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) HiveHistory(org.apache.hadoop.hive.ql.history.HiveHistory) IOException(java.io.IOException) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 22 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 {
        operation.run();
        addOpHandle(opHandle);
        return opHandle;
    } catch (HiveSQLException e) {
        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 23 with OperationHandle

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

the class OperationManager method removeExpiredOperations.

public List<Operation> removeExpiredOperations(OperationHandle[] handles) {
    List<Operation> removed = new ArrayList<Operation>();
    for (OperationHandle handle : handles) {
        Operation operation = removeTimedOutOperation(handle);
        if (operation != null) {
            LOG.warn("Operation " + handle + " is timed-out and will be closed");
            removed.add(operation);
        }
    }
    return removed;
}
Also used : ArrayList(java.util.ArrayList) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 24 with OperationHandle

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

the class TestOperationLoggingLayout method setupSession.

private SessionHandle setupSession() throws Exception {
    // Open a session
    SessionHandle sessionHandle = client.openSession(null, null, null);
    // Change lock manager to embedded mode
    String queryString = "SET hive.lock.manager=" + "org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager";
    client.executeStatement(sessionHandle, queryString, null);
    // Drop the table if it exists
    queryString = "DROP TABLE IF EXISTS " + tableName;
    client.executeStatement(sessionHandle, queryString, null);
    // Create a test table
    queryString = "create table " + tableName + " (key int, value string)";
    client.executeStatement(sessionHandle, queryString, null);
    // Load data
    queryString = "load data local inpath '" + dataFile + "' into table " + tableName;
    client.executeStatement(sessionHandle, queryString, null);
    // Precondition check: verify whether the table is created and data is fetched correctly.
    OperationHandle operationHandle = client.executeStatement(sessionHandle, sql, null);
    RowSet rowSetResult = client.fetchResults(operationHandle);
    Assert.assertEquals(500, rowSetResult.numRows());
    Assert.assertEquals(238, rowSetResult.iterator().next()[0]);
    Assert.assertEquals("val_238", rowSetResult.iterator().next()[1]);
    return sessionHandle;
}
Also used : RowSet(org.apache.hive.service.cli.RowSet) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 25 with OperationHandle

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

the class TestQueryDisplay method testQueryDisplay.

/**
   * Test if query display captures information on current/historic SQL operations.
   */
@Test
public void testQueryDisplay() throws Exception {
    HiveSession session = sessionManager.createSession(new SessionHandle(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8), TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8, "testuser", "", "", new HashMap<String, String>(), false, "");
    SessionState.start(conf);
    OperationHandle opHandle1 = session.executeStatement("show databases", null);
    SessionState.start(conf);
    OperationHandle opHandle2 = session.executeStatement("show tables", null);
    List<SQLOperationDisplay> liveSqlOperations, historicSqlOperations;
    liveSqlOperations = sessionManager.getOperationManager().getLiveSqlOperations();
    historicSqlOperations = sessionManager.getOperationManager().getHistoricalSQLOperations();
    Assert.assertEquals(liveSqlOperations.size(), 2);
    Assert.assertEquals(historicSqlOperations.size(), 0);
    verifyDDL(liveSqlOperations.get(0), "show databases", opHandle1.getHandleIdentifier().toString(), false);
    verifyDDL(liveSqlOperations.get(1), "show tables", opHandle2.getHandleIdentifier().toString(), false);
    session.closeOperation(opHandle1);
    liveSqlOperations = sessionManager.getOperationManager().getLiveSqlOperations();
    historicSqlOperations = sessionManager.getOperationManager().getHistoricalSQLOperations();
    Assert.assertEquals(liveSqlOperations.size(), 1);
    Assert.assertEquals(historicSqlOperations.size(), 1);
    verifyDDL(historicSqlOperations.get(0), "show databases", opHandle1.getHandleIdentifier().toString(), true);
    verifyDDL(liveSqlOperations.get(0), "show tables", opHandle2.getHandleIdentifier().toString(), false);
    session.closeOperation(opHandle2);
    liveSqlOperations = sessionManager.getOperationManager().getLiveSqlOperations();
    historicSqlOperations = sessionManager.getOperationManager().getHistoricalSQLOperations();
    Assert.assertEquals(liveSqlOperations.size(), 0);
    Assert.assertEquals(historicSqlOperations.size(), 2);
    verifyDDL(historicSqlOperations.get(1), "show databases", opHandle1.getHandleIdentifier().toString(), true);
    verifyDDL(historicSqlOperations.get(0), "show tables", opHandle2.getHandleIdentifier().toString(), true);
    session.close();
}
Also used : SQLOperationDisplay(org.apache.hive.service.cli.operation.SQLOperationDisplay) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Aggregations

OperationHandle (org.apache.hive.service.cli.OperationHandle)77 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)54 SessionHandle (org.apache.hive.service.cli.SessionHandle)38 TException (org.apache.thrift.TException)27 Test (org.junit.Test)22 IOException (java.io.IOException)18 RowSet (org.apache.hive.service.cli.RowSet)16 UnknownHostException (java.net.UnknownHostException)15 LoginException (javax.security.auth.login.LoginException)15 ServiceException (org.apache.hive.service.ServiceException)15 ExploreException (co.cask.cdap.explore.service.ExploreException)12 OperationManager (org.apache.hive.service.cli.operation.OperationManager)12 QueryHandle (co.cask.cdap.proto.QueryHandle)11 TProtocolVersion (org.apache.hive.service.rpc.thrift.TProtocolVersion)11 OperationStatus (org.apache.hive.service.cli.OperationStatus)5 HashMap (java.util.HashMap)4 CLIServiceClient (org.apache.hive.service.cli.CLIServiceClient)4 OperationState (org.apache.hive.service.cli.OperationState)4 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)2 HandleNotFoundException (co.cask.cdap.explore.service.HandleNotFoundException)2