Search in sources :

Example 11 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 12 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 13 with RowSet

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

the class ThriftCLIService method FetchResults.

@Override
public TFetchResultsResp FetchResults(TFetchResultsReq req) throws TException {
    TFetchResultsResp resp = new TFetchResultsResp();
    final int maxFetchSize = hiveConf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_RESULTSET_MAX_FETCH_SIZE);
    if (req.getMaxRows() > maxFetchSize) {
        LOG.warn("Fetch Size greater than maximum allowed. Capping fetch size. [req={}, max={}]", req.getMaxRows(), maxFetchSize);
        req.setMaxRows(maxFetchSize);
    }
    try {
        RowSet rowSet = cliService.fetchResults(new OperationHandle(req.getOperationHandle()), FetchOrientation.getFetchOrientation(req.getOrientation()), req.getMaxRows(), FetchType.getFetchType(req.getFetchType()));
        resp.setResults(rowSet.toTRowSet());
        resp.setHasMoreRows(false);
        resp.setStatus(OK_STATUS);
    } catch (Exception e) {
        LOG.error("Failed fetch results [request: {}]", req, e);
        resp.setStatus(HiveSQLException.toTStatus(e));
    }
    return resp;
}
Also used : TFetchResultsResp(org.apache.hive.service.rpc.thrift.TFetchResultsResp) RowSet(org.apache.hive.service.cli.RowSet) OperationHandle(org.apache.hive.service.cli.OperationHandle) ServiceException(org.apache.hive.service.ServiceException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) LoginException(javax.security.auth.login.LoginException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException)

Example 14 with RowSet

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

the class TestSessionGlobalInitFile method verifyInitProperty.

private void verifyInitProperty(String key, String value, SessionHandle sessionHandle) throws Exception {
    OperationHandle operationHandle = client.executeStatement(sessionHandle, "set " + key, null);
    RowSet rowSet = client.fetchResults(operationHandle);
    Assert.assertEquals(1, rowSet.numRows());
    // we know rowSet has only one element
    Assert.assertEquals(key + "=" + value, rowSet.iterator().next()[0]);
    client.closeOperation(operationHandle);
}
Also used : RowSet(org.apache.hive.service.cli.RowSet) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 15 with RowSet

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

the class OperationManager method getOperationLogRowSet.

public RowSet getOperationLogRowSet(OperationHandle opHandle, FetchOrientation orientation, long maxRows, HiveConf hConf) throws HiveSQLException {
    TableSchema tableSchema = new TableSchema(getLogSchema());
    RowSet rowSet = RowSetFactory.create(tableSchema, getOperation(opHandle).getProtocolVersion(), false);
    if (hConf.getBoolVar(ConfVars.HIVE_SERVER2_LOGGING_OPERATION_ENABLED) == false) {
        LOG.warn("Try to get operation log when hive.server2.logging.operation.enabled is false, no log will be returned. ");
        return rowSet;
    }
    // get the OperationLog object from the operation
    OperationLog operationLog = getOperation(opHandle).getOperationLog();
    if (operationLog == null) {
        throw new HiveSQLException("Couldn't find log associated with operation handle: " + opHandle);
    }
    // read logs
    List<String> logs;
    try {
        logs = operationLog.readOperationLog(isFetchFirst(orientation), maxRows);
    } catch (SQLException e) {
        throw new HiveSQLException(e.getMessage(), e.getCause());
    }
    // convert logs to RowSet
    for (String log : logs) {
        rowSet.addRow(new String[] { log });
    }
    return rowSet;
}
Also used : TableSchema(org.apache.hive.service.cli.TableSchema) SQLException(java.sql.SQLException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) RowSet(org.apache.hive.service.cli.RowSet) OperationLog(org.apache.hadoop.hive.ql.session.OperationLog)

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