Search in sources :

Example 1 with HiveSession

use of org.apache.hive.service.cli.session.HiveSession in project hive by apache.

the class CLIService method executeStatementAsync.

/**
   * Execute statement asynchronously on the server with a timeout. This is a non-blocking call
   */
@Override
public OperationHandle executeStatementAsync(SessionHandle sessionHandle, String statement, Map<String, String> confOverlay, long queryTimeout) throws HiveSQLException {
    HiveSession session = sessionManager.getSession(sessionHandle);
    // need to reset the monitor, as operation handle is not available down stream, Ideally the
    // monitor should be associated with the operation handle.
    session.getSessionState().updateProgressMonitor(null);
    OperationHandle opHandle = session.executeStatementAsync(statement, confOverlay, queryTimeout);
    LOG.debug(sessionHandle + ": executeStatementAsync()");
    return opHandle;
}
Also used : HiveSession(org.apache.hive.service.cli.session.HiveSession)

Example 2 with HiveSession

use of org.apache.hive.service.cli.session.HiveSession in project hive by apache.

the class CLIService method executeStatement.

/**
   * Execute statement on the server. This is a blocking call.
   */
@Override
public OperationHandle executeStatement(SessionHandle sessionHandle, String statement, Map<String, String> confOverlay) throws HiveSQLException {
    HiveSession session = sessionManager.getSession(sessionHandle);
    // need to reset the monitor, as operation handle is not available down stream, Ideally the
    // monitor should be associated with the operation handle.
    session.getSessionState().updateProgressMonitor(null);
    OperationHandle opHandle = session.executeStatement(statement, confOverlay);
    LOG.debug(sessionHandle + ": executeStatement()");
    return opHandle;
}
Also used : HiveSession(org.apache.hive.service.cli.session.HiveSession)

Example 3 with HiveSession

use of org.apache.hive.service.cli.session.HiveSession in project hive by apache.

the class CLIService method executeStatement.

/**
   * Execute statement on the server with a timeout. This is a blocking call.
   */
@Override
public OperationHandle executeStatement(SessionHandle sessionHandle, String statement, Map<String, String> confOverlay, long queryTimeout) throws HiveSQLException {
    HiveSession session = sessionManager.getSession(sessionHandle);
    // need to reset the monitor, as operation handle is not available down stream, Ideally the
    // monitor should be associated with the operation handle.
    session.getSessionState().updateProgressMonitor(null);
    OperationHandle opHandle = session.executeStatement(statement, confOverlay, queryTimeout);
    LOG.debug(sessionHandle + ": executeStatement()");
    return opHandle;
}
Also used : HiveSession(org.apache.hive.service.cli.session.HiveSession)

Example 4 with HiveSession

use of org.apache.hive.service.cli.session.HiveSession in project hive by apache.

the class TestRetryingThriftCLIServiceClient method testSessionLifeAfterTransportClose.

@Test
public void testSessionLifeAfterTransportClose() throws InterruptedException, HiveSQLException {
    try {
        startHiveServer();
        CLIService service = null;
        for (Service s : server.getServices()) {
            if (s instanceof CLIService) {
                service = (CLIService) s;
            }
        }
        if (service == null) {
            service = new CLIService(server);
        }
        RetryingThriftCLIServiceClient.CLIServiceClientWrapper client = RetryingThriftCLIServiceClientTest.newRetryingCLIServiceClient(hiveConf);
        Map<String, String> conf = new HashMap<>();
        conf.put(HiveConf.ConfVars.HIVE_SERVER2_CLOSE_SESSION_ON_DISCONNECT.varname, "false");
        SessionHandle sessionHandle = client.openSession("anonymous", "anonymous", conf);
        assertNotNull(sessionHandle);
        HiveSession session = service.getSessionManager().getSession(sessionHandle);
        OperationHandle op1 = session.executeStatementAsync("show databases", null);
        assertNotNull(op1);
        client.closeTransport();
        // Verify that session wasn't closed on transport close.
        assertEquals(session, service.getSessionManager().getSession(sessionHandle));
        // Should be able to execute without failure in the session whose transport has been closed.
        OperationHandle op2 = session.executeStatementAsync("show databases", null);
        assertNotNull(op2);
        // Make new client, since transport was closed for the last one.
        client = RetryingThriftCLIServiceClientTest.newRetryingCLIServiceClient(hiveConf);
        client.closeSession(sessionHandle);
        // operations will be lost once owning session is closed.
        for (OperationHandle op : new OperationHandle[] { op1, op2 }) {
            try {
                client.getOperationStatus(op, false);
                fail("Should have failed.");
            } catch (HiveSQLException ignored) {
            }
        }
    } finally {
        stopHiveServer();
    }
}
Also used : RetryingThriftCLIServiceClient(org.apache.hive.service.cli.thrift.RetryingThriftCLIServiceClient) HashMap(java.util.HashMap) ThriftCLIService(org.apache.hive.service.cli.thrift.ThriftCLIService) Service(org.apache.hive.service.Service) HiveSession(org.apache.hive.service.cli.session.HiveSession) ThriftCLIService(org.apache.hive.service.cli.thrift.ThriftCLIService) Test(org.junit.Test)

Example 5 with HiveSession

use of org.apache.hive.service.cli.session.HiveSession in project hive by apache.

the class TestSQLOperationMetrics method setup.

@Before
public void setup() throws Exception {
    HiveConf conf = new HiveConf();
    conf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_METRICS_ENABLED, true);
    MetricsFactory.init(conf);
    HiveSession session = mock(HiveSession.class);
    when(session.getHiveConf()).thenReturn(conf);
    when(session.getSessionState()).thenReturn(mock(SessionState.class));
    when(session.getUserName()).thenReturn("userName");
    operation = new SQLOperation(session, "select * from dummy", Maps.<String, String>newHashMap(), false, 0L);
    metrics = (CodahaleMetrics) MetricsFactory.getInstance();
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) HiveConf(org.apache.hadoop.hive.conf.HiveConf) HiveSession(org.apache.hive.service.cli.session.HiveSession) Before(org.junit.Before)

Aggregations

HiveSession (org.apache.hive.service.cli.session.HiveSession)6 HashMap (java.util.HashMap)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 SessionState (org.apache.hadoop.hive.ql.session.SessionState)1 Service (org.apache.hive.service.Service)1 RetryingThriftCLIServiceClient (org.apache.hive.service.cli.thrift.RetryingThriftCLIServiceClient)1 ThriftCLIService (org.apache.hive.service.cli.thrift.ThriftCLIService)1 Before (org.junit.Before)1 Test (org.junit.Test)1