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);
}
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);
}
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;
}
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);
}
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;
}
Aggregations