Search in sources :

Example 26 with SessionHandle

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

the class TestMiniHS2StateWithNoZookeeper method openSessionAndClose.

@Test
public void openSessionAndClose() throws Exception {
    CLIServiceClient client = miniHS2.getServiceClient();
    SessionHandle sessionHandle = client.openSession(null, null, null);
    client.closeSession(sessionHandle);
    Thread.sleep(100);
    Assert.assertEquals(Service.STATE.STARTED, miniHS2.getState());
}
Also used : CLIServiceClient(org.apache.hive.service.cli.CLIServiceClient) SessionHandle(org.apache.hive.service.cli.SessionHandle) Test(org.junit.Test)

Example 27 with SessionHandle

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

the class TestHiveServer2 method testGetVariableValue.

/**
   * Open a new session and execute a set command
   * @throws Exception
   */
@Test
public void testGetVariableValue() throws Exception {
    CLIServiceClient serviceClient = miniHS2.getServiceClient();
    SessionHandle sessHandle = serviceClient.openSession("foo", "bar");
    OperationHandle opHandle = serviceClient.executeStatement(sessHandle, "set system:os.name", confOverlay);
    RowSet rowSet = serviceClient.fetchResults(opHandle);
    assertEquals(1, rowSet.numRows());
    serviceClient.closeSession(sessHandle);
}
Also used : CLIServiceClient(org.apache.hive.service.cli.CLIServiceClient) RowSet(org.apache.hive.service.cli.RowSet) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 28 with SessionHandle

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

the class OperationLoggingAPITestBase 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 29 with SessionHandle

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

the class OperationLoggingAPITestBase method testFetchResultsOfLogCleanup.

@Test
public void testFetchResultsOfLogCleanup() throws Exception {
    // Verify cleanup functionality.
    // Open a new session, since this case needs to close the session in the end.
    SessionHandle sessionHandleCleanup = setupSession();
    // prepare
    OperationHandle operationHandle = client.executeStatement(sessionHandleCleanup, sql, null);
    RowSet rowSetLog = client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 1000, FetchType.LOG);
    verifyFetchedLog(rowSetLog, expectedLogsVerbose);
    File sessionLogDir = new File(hiveConf.getVar(HiveConf.ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LOG_LOCATION) + File.separator + sessionHandleCleanup.getHandleIdentifier());
    File operationLogFile = new File(sessionLogDir, operationHandle.getHandleIdentifier().toString());
    // check whether exception is thrown when fetching log from a closed operation.
    client.closeOperation(operationHandle);
    try {
        client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 1000, FetchType.LOG);
        Assert.fail("Fetch should fail");
    } catch (HiveSQLException e) {
        Assert.assertTrue(e.getMessage().contains("Invalid OperationHandle:"));
    }
    // check whether operation log file is deleted.
    if (operationLogFile.exists()) {
        Assert.fail("Operation log file should be deleted.");
    }
    // check whether session log dir is deleted after session is closed.
    client.closeSession(sessionHandleCleanup);
    if (sessionLogDir.exists()) {
        Assert.fail("Session log dir should be deleted.");
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) RowSet(org.apache.hive.service.cli.RowSet) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) File(java.io.File) Test(org.junit.Test)

Example 30 with SessionHandle

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

the class BeelineWithHS2ConnectionFileTestBase method createTable.

protected void createTable() throws HiveSQLException {
    CLIServiceClient serviceClient = miniHS2.getServiceClient();
    SessionHandle sessHandle = serviceClient.openSession("foo", "bar");
    serviceClient.executeStatement(sessHandle, "DROP TABLE IF EXISTS " + tableName, confOverlay);
    serviceClient.executeStatement(sessHandle, "CREATE TABLE " + tableName + " (id INT)", confOverlay);
    OperationHandle opHandle = serviceClient.executeStatement(sessHandle, "SHOW TABLES", confOverlay);
    RowSet rowSet = serviceClient.fetchResults(opHandle);
    assertFalse(rowSet.numRows() == 0);
}
Also used : CLIServiceClient(org.apache.hive.service.cli.CLIServiceClient) RowSet(org.apache.hive.service.cli.RowSet) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle)

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