Search in sources :

Example 16 with RowSet

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

the class TestOperationLoggingLayout method testSwitchLogLayout.

@Test
public void testSwitchLogLayout() throws Exception {
    // verify whether the sql operation log is generated and fetch correctly.
    OperationHandle operationHandle = client.executeStatement(sessionHandle, sqlCntStar, null);
    RowSet rowSetLog = client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 1000, FetchType.LOG);
    String queryId = getQueryId(rowSetLog);
    Assert.assertNotNull("Could not find query id, perhaps a logging message changed", queryId);
    checkAppenderState("before operation close ", LogDivertAppender.QUERY_ROUTING_APPENDER, queryId, false);
    checkAppenderState("before operation close ", LogDivertAppenderForTest.TEST_QUERY_ROUTING_APPENDER, queryId, false);
    client.closeOperation(operationHandle);
    checkAppenderState("after operation close ", LogDivertAppender.QUERY_ROUTING_APPENDER, queryId, true);
    checkAppenderState("after operation close ", LogDivertAppenderForTest.TEST_QUERY_ROUTING_APPENDER, queryId, true);
}
Also used : RowSet(org.apache.hive.service.cli.RowSet) OperationHandle(org.apache.hive.service.cli.OperationHandle) LogDivertAppenderForTest(org.apache.hadoop.hive.ql.log.LogDivertAppenderForTest) Test(org.junit.Test)

Example 17 with RowSet

use of org.apache.hive.service.cli.RowSet in project cdap by caskdata.

the class Hive14ExploreService method doFetchNextResults.

@Override
protected List<QueryResult> doFetchNextResults(OperationHandle handle, FetchOrientation fetchOrientation, int size) throws Exception {
    RowSet rowSet = getCliService().fetchResults(handle, fetchOrientation, size, FetchType.QUERY_OUTPUT);
    ImmutableList.Builder<QueryResult> rowsBuilder = ImmutableList.builder();
    for (Object[] row : rowSet) {
        List<Object> cols = Lists.newArrayList(row);
        rowsBuilder.add(new QueryResult(cols));
    }
    return rowsBuilder.build();
}
Also used : QueryResult(co.cask.cdap.proto.QueryResult) ImmutableList(com.google.common.collect.ImmutableList) RowSet(org.apache.hive.service.cli.RowSet)

Example 18 with RowSet

use of org.apache.hive.service.cli.RowSet 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)

Example 19 with RowSet

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

the class TestHiveServer2 method testConnection.

/**
 * Open a new session and run a test query
 * @throws Exception
 */
@Test
public void testConnection() 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);
    OperationHandle opHandle = serviceClient.executeStatement(sessHandle, "SHOW TABLES", confOverlay);
    RowSet rowSet = serviceClient.fetchResults(opHandle);
    assertFalse(rowSet.numRows() == 0);
    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)

Example 20 with RowSet

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

the class TestHiveShell method executeStatement.

public List<Object[]> executeStatement(String statement) {
    Preconditions.checkState(session != null, "You have to start TestHiveShell and open a session first, before running a query.");
    try {
        OperationHandle handle = client.executeStatement(session.getSessionHandle(), statement, Collections.emptyMap());
        List<Object[]> resultSet = new ArrayList<>();
        if (handle.hasResultSet()) {
            RowSet rowSet;
            // keep fetching results until we can
            while ((rowSet = client.fetchResults(handle)) != null && rowSet.numRows() > 0) {
                for (Object[] row : rowSet) {
                    resultSet.add(row.clone());
                }
            }
        }
        return resultSet;
    } catch (HiveSQLException e) {
        throw new IllegalArgumentException("Failed to execute Hive query '" + statement + "': " + e.getMessage(), e);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) ArrayList(java.util.ArrayList) RowSet(org.apache.hive.service.cli.RowSet) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Aggregations

RowSet (org.apache.hive.service.cli.RowSet)27 OperationHandle (org.apache.hive.service.cli.OperationHandle)21 Test (org.junit.Test)14 SessionHandle (org.apache.hive.service.cli.SessionHandle)8 CLIServiceClient (org.apache.hive.service.cli.CLIServiceClient)5 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)5 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 QueryResult (co.cask.cdap.proto.QueryResult)2 ImmutableList (com.google.common.collect.ImmutableList)2 LogDivertAppenderForTest (org.apache.hadoop.hive.ql.log.LogDivertAppenderForTest)2 TFetchResultsResp (org.apache.hive.service.rpc.thrift.TFetchResultsResp)2 TException (org.apache.thrift.TException)2 File (java.io.File)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Method (java.lang.reflect.Method)1 UnknownHostException (java.net.UnknownHostException)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 SQLTimeoutException (java.sql.SQLTimeoutException)1