Search in sources :

Example 1 with RowSet

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

the class Hive13ExploreService method doFetchNextResults.

@SuppressWarnings("unchecked")
@Override
protected List<QueryResult> doFetchNextResults(OperationHandle handle, FetchOrientation fetchOrientation, int size) throws Exception {
    Class cliServiceClass = Class.forName("org.apache.hive.service.cli.CLIService");
    Method fetchResultsMethod = cliServiceClass.getMethod("fetchResults", OperationHandle.class, FetchOrientation.class, Long.TYPE);
    RowSet rowSet = (RowSet) fetchResultsMethod.invoke(getCliService(), handle, fetchOrientation, size);
    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) Method(java.lang.reflect.Method)

Example 2 with RowSet

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

Example 3 with RowSet

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

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

the class TestOperationLoggingAPIWithMr method testFetchResultsOfLogWithOrientation.

@Test
public void testFetchResultsOfLogWithOrientation() throws Exception {
    // (FETCH_FIRST) execute a sql, and fetch its sql operation log as expected value
    OperationHandle operationHandle = client.executeStatement(sessionHandle, sql, null);
    RowSet rowSetLog = client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 1000, FetchType.LOG);
    int expectedLogLength = rowSetLog.numRows();
    // (FETCH_NEXT) execute the same sql again,
    // and fetch the sql operation log with FETCH_NEXT orientation
    OperationHandle operationHandleWithOrientation = client.executeStatement(sessionHandle, sql, null);
    RowSet rowSetLogWithOrientation;
    int logLength = 0;
    int maxRows = calculateProperMaxRows(expectedLogLength);
    do {
        rowSetLogWithOrientation = client.fetchResults(operationHandleWithOrientation, FetchOrientation.FETCH_NEXT, maxRows, FetchType.LOG);
        logLength += rowSetLogWithOrientation.numRows();
    } while (rowSetLogWithOrientation.numRows() == maxRows);
    Assert.assertEquals(expectedLogLength, logLength);
    // (FETCH_FIRST) fetch again from the same operation handle with FETCH_FIRST orientation
    rowSetLogWithOrientation = client.fetchResults(operationHandleWithOrientation, FetchOrientation.FETCH_FIRST, 1000, FetchType.LOG);
    verifyFetchedLog(rowSetLogWithOrientation, expectedLogsVerbose);
}
Also used : RowSet(org.apache.hive.service.cli.RowSet) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 5 with RowSet

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

the class TestOperationLoggingLayout 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)

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