Search in sources :

Example 6 with SessionHandle

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

the class TestSessionHooks method testSessionHook.

@Test
public void testSessionHook() throws Exception {
    // create session, test if the hook got fired by checking the expected property
    SessionHandle sessionHandle = client.openSession(sessionUserName, "foobar", Collections.<String, String>emptyMap());
    Assert.assertEquals(1, SessionHookTest.runCount.get());
    client.closeSession(sessionHandle);
}
Also used : SessionHandle(org.apache.hive.service.cli.SessionHandle) Test(org.junit.Test)

Example 7 with SessionHandle

use of org.apache.hive.service.cli.SessionHandle 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 {
                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 8 with SessionHandle

use of org.apache.hive.service.cli.SessionHandle 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 9 with SessionHandle

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

the class ThriftCliServiceTestWithCookie 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 10 with SessionHandle

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

the class ThriftCliServiceTestWithCookie method testOpenSession.

@Test
public void testOpenSession() throws Exception {
    // Open a new client session
    SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap<String, String>());
    // Session handle should not be null
    assertNotNull("Session handle should not be null", sessHandle);
    // Close client session
    client.closeSession(sessHandle);
}
Also used : SessionHandle(org.apache.hive.service.cli.SessionHandle) Test(org.junit.Test)

Aggregations

SessionHandle (org.apache.hive.service.cli.SessionHandle)66 OperationHandle (org.apache.hive.service.cli.OperationHandle)38 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)35 Test (org.junit.Test)27 IOException (java.io.IOException)15 TException (org.apache.thrift.TException)15 UnknownHostException (java.net.UnknownHostException)13 LoginException (javax.security.auth.login.LoginException)13 ServiceException (org.apache.hive.service.ServiceException)13 ExploreException (co.cask.cdap.explore.service.ExploreException)12 QueryHandle (co.cask.cdap.proto.QueryHandle)11 HashMap (java.util.HashMap)8 CLIServiceClient (org.apache.hive.service.cli.CLIServiceClient)8 RowSet (org.apache.hive.service.cli.RowSet)6 TimeoutException (java.util.concurrent.TimeoutException)4 HiveConf (org.apache.hadoop.hive.conf.HiveConf)4 ThriftCLIServiceClient (org.apache.hive.service.cli.thrift.ThriftCLIServiceClient)4 CLIService (org.apache.hive.service.cli.CLIService)3 OperationState (org.apache.hive.service.cli.OperationState)3 OperationStatus (org.apache.hive.service.cli.OperationStatus)3