Search in sources :

Example 11 with CLIServiceClient

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

the class TestHiveServer2Acid method testAsyncConcurrent.

/**
 * Test overlapping async queries in one session.
 * Since TxnManager is shared in the session this can cause all kind of trouble.
 * @throws Exception ex
 */
@Test
public void testAsyncConcurrent() throws Exception {
    String tableName = "TestHiveServer2TestConnection";
    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);
    serviceClient.executeStatement(sessHandle, "insert into " + tableName + " values(5)", confOverlay);
    OperationHandle opHandle = serviceClient.executeStatementAsync(sessHandle, "select * from " + tableName, confOverlay);
    assertOperationFinished(serviceClient, opHandle);
    RowSet rowSet = serviceClient.fetchResults(opHandle);
    serviceClient.executeStatement(sessHandle, "create temporary function sleepMsUDF as '" + TestHiveServer2Acid.SleepMsUDF.class.getName() + "'", confOverlay);
    // Start a second "slow" query
    OperationHandle opHandle2 = serviceClient.executeStatementAsync(sessHandle, "select sleepMsUDF(id, 1000), id from " + tableName, confOverlay);
    // Close the first operation (this will destroy the Driver and TxnManager)
    serviceClient.closeOperation(opHandle);
    assertEquals(1, rowSet.numRows());
    assertOperationFinished(serviceClient, opHandle2);
    rowSet = serviceClient.fetchResults(opHandle2);
    assertEquals(1, rowSet.numRows());
    serviceClient.executeStatement(sessHandle, "DROP TABLE IF EXISTS " + tableName, confOverlay);
    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) UtilsForTest(org.apache.hadoop.hive.UtilsForTest)

Aggregations

CLIServiceClient (org.apache.hive.service.cli.CLIServiceClient)11 SessionHandle (org.apache.hive.service.cli.SessionHandle)11 Test (org.junit.Test)8 OperationHandle (org.apache.hive.service.cli.OperationHandle)6 RowSet (org.apache.hive.service.cli.RowSet)5 IOException (java.io.IOException)2 TimeoutException (java.util.concurrent.TimeoutException)2 CodahaleMetrics (org.apache.hadoop.hive.common.metrics.metrics2.CodahaleMetrics)2 ThriftCLIServiceClient (org.apache.hive.service.cli.thrift.ThriftCLIServiceClient)2 FileNotFoundException (java.io.FileNotFoundException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UtilsForTest (org.apache.hadoop.hive.UtilsForTest)1 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)1 HivePrivilegeObject (org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject)1 BeeLine (org.apache.hive.beeline.BeeLine)1 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)1