Search in sources :

Example 51 with OperationHandle

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

the class TestSessionManagerMetrics method testActiveSessionMetrics.

@Test
public void testActiveSessionMetrics() throws Exception {
    final CyclicBarrier ready = new CyclicBarrier(2);
    CyclicBarrier completed = new CyclicBarrier(2);
    String json = metrics.dumpJson();
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_ACTIVE_SESSIONS, 0);
    SessionHandle handle = sm.openSession(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9, "user", "passw", "127.0.0.1", new HashMap<String, String>());
    final HiveSession session = sm.getSession(handle);
    OperationManager operationManager = mock(OperationManager.class);
    when(operationManager.newGetTablesOperation(session, "catalog", "schema", "table", null)).thenReturn(new BlockingOperation(session, OperationType.GET_TABLES, ready, completed));
    session.setOperationManager(operationManager);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Hive.set(session.getSessionHive());
                OperationHandle handle = session.getTables("catalog", "schema", "table", null);
                session.closeOperation(handle);
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                try {
                    ready.await();
                } catch (InterruptedException | BrokenBarrierException e) {
                // ignore
                }
            }
        }
    }).start();
    ready.await(2, TimeUnit.SECONDS);
    ready.reset();
    json = metrics.dumpJson();
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_ACTIVE_SESSIONS, 1);
    completed.await(2, TimeUnit.SECONDS);
    ready.await(2, TimeUnit.SECONDS);
    json = metrics.dumpJson();
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_ACTIVE_SESSIONS, 0);
}
Also used : BrokenBarrierException(java.util.concurrent.BrokenBarrierException) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) TimeoutException(java.util.concurrent.TimeoutException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) CyclicBarrier(java.util.concurrent.CyclicBarrier) OperationManager(org.apache.hive.service.cli.operation.OperationManager) Test(org.junit.Test)

Example 52 with OperationHandle

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

the class TestSessionCleanup method testTempSessionFileCleanup.

@Test
public // This is to test session temporary files are cleaned up after HIVE-11768
void testTempSessionFileCleanup() throws Exception {
    MyEmbeddedThriftBinaryCLIService service = new MyEmbeddedThriftBinaryCLIService();
    HiveConf hiveConf = new HiveConf();
    hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
    // NOTES: Apply a random tmp directory to avoid default location conflicting with other tests
    hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LOG_LOCATION, TEST_DATA_DIR + File.separator + "operation_logs");
    service.init(hiveConf);
    ThriftCLIServiceClient client = new ThriftCLIServiceClient(service);
    Set<String> existingPipeoutFiles = new HashSet<String>(Arrays.asList(getPipeoutFiles(hiveConf)));
    SessionHandle sessionHandle = client.openSession("user1", "foobar", Collections.<String, String>emptyMap());
    OperationHandle opHandle1 = client.executeStatement(sessionHandle, "set a=b", null);
    String queryId1 = service.getCliService().getQueryId(opHandle1.toTOperationHandle());
    Assert.assertNotNull(queryId1);
    OperationHandle opHandle2 = client.executeStatement(sessionHandle, "set b=c", null);
    String queryId2 = service.getCliService().getQueryId(opHandle2.toTOperationHandle());
    Assert.assertNotNull(queryId2);
    File operationLogRootDir = new File(hiveConf.getVar(HiveConf.ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LOG_LOCATION));
    Assert.assertNotEquals(0, operationLogRootDir.list().length);
    client.closeSession(sessionHandle);
    // Check if session files are removed
    Assert.assertEquals(0, operationLogRootDir.list().length);
    // Check if the pipeout files are removed
    Set<String> finalPipeoutFiles = new HashSet<String>(Arrays.asList(getPipeoutFiles(hiveConf)));
    finalPipeoutFiles.removeAll(existingPipeoutFiles);
    Assert.assertTrue(finalPipeoutFiles.isEmpty());
    // Verify both operationHandles are no longer held by the OperationManager
    Assert.assertEquals(0, service.getCliService().getSessionManager().getOperations().size());
    // Verify both queryIds are no longer held by the OperationManager
    Assert.assertNull(service.getCliService().getSessionManager().getOperationManager().getOperationByQueryId(queryId2));
    Assert.assertNull(service.getCliService().getSessionManager().getOperationManager().getOperationByQueryId(queryId1));
}
Also used : HiveConf(org.apache.hadoop.hive.conf.HiveConf) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) File(java.io.File) ThriftCLIServiceClient(org.apache.hive.service.cli.thrift.ThriftCLIServiceClient) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 53 with OperationHandle

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

the class ThriftCLIServiceTest method testExecuteStatement.

/**
 * Test synchronous query execution
 * @throws Exception
 */
@Test
public void testExecuteStatement() throws Exception {
    Map<String, String> opConf = new HashMap<String, String>();
    // Open a new client session
    SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, opConf);
    // Session handle should not be null
    assertNotNull("Session handle should not be null", sessHandle);
    // Change lock manager to embedded mode
    String queryString = "SET hive.lock.manager=" + "org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager";
    client.executeStatement(sessHandle, queryString, opConf);
    // Drop the table if it exists
    queryString = "DROP TABLE IF EXISTS TEST_EXEC_THRIFT";
    client.executeStatement(sessHandle, queryString, opConf);
    // Create a test table
    queryString = "CREATE TABLE TEST_EXEC_THRIFT(ID STRING)";
    client.executeStatement(sessHandle, queryString, opConf);
    // Execute another query
    queryString = "SELECT ID+1 FROM TEST_EXEC_THRIFT";
    OperationHandle opHandle = client.executeStatement(sessHandle, queryString, opConf);
    assertNotNull(opHandle);
    OperationStatus opStatus = client.getOperationStatus(opHandle, false);
    assertNotNull(opStatus);
    OperationState state = opStatus.getState();
    // Expect query to be completed now
    assertEquals("Query should be finished", OperationState.FINISHED, state);
    // Cleanup
    queryString = "DROP TABLE TEST_EXEC_THRIFT";
    client.executeStatement(sessHandle, queryString, opConf);
    client.closeSession(sessHandle);
}
Also used : HashMap(java.util.HashMap) OperationStatus(org.apache.hive.service.cli.OperationStatus) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) OperationState(org.apache.hive.service.cli.OperationState) Test(org.junit.Test)

Example 54 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 55 with OperationHandle

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

the class ThriftCliServiceTestWithCookie method testGetFunctions.

@Test
public void testGetFunctions() throws Exception {
    SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap<String, String>());
    assertNotNull("Session handle should not be null", sessHandle);
    String catalogName = null;
    String schemaName = null;
    String functionName = "*";
    OperationHandle opHandle = client.getFunctions(sessHandle, catalogName, schemaName, functionName);
    assertNotNull("Operation handle should not be null", opHandle);
    client.closeSession(sessHandle);
}
Also used : 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)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