use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class TestHiveServer2SessionTimeout method testConnection.
@Test
public void testConnection() throws Exception {
CLIServiceClient serviceClient = miniHS2.getServiceClient();
SessionHandle sessHandle = serviceClient.openSession("foo", "bar");
OperationHandle handle = serviceClient.executeStatement(sessHandle, "SELECT 1", confOverlay);
Thread.sleep(7000);
try {
serviceClient.closeOperation(handle);
fail("Operation should have been closed by timeout!");
} catch (HiveSQLException e) {
assertTrue(StringUtils.stringifyException(e), e.getMessage().contains("Invalid OperationHandle"));
}
}
use of org.apache.hive.service.cli.OperationHandle 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);
}
}
use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class TestOperationLoggingLayout method testHushableRandomAccessFileAppender.
@Test
public /**
* Test to make sure that appending log event to HushableRandomAccessFileAppender even after
* closing the corresponding operation would not throw an exception.
*/
void testHushableRandomAccessFileAppender() 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);
Appender queryAppender;
Appender testQueryAppender;
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);
queryAppender = getAppender(LogDivertAppender.QUERY_ROUTING_APPENDER, queryId);
checkAppenderState("before operation close ", LogDivertAppenderForTest.TEST_QUERY_ROUTING_APPENDER, queryId, false);
testQueryAppender = getAppender(LogDivertAppenderForTest.TEST_QUERY_ROUTING_APPENDER, queryId);
client.closeOperation(operationHandle);
appendHushableRandomAccessFileAppender(queryAppender);
appendHushableRandomAccessFileAppender(testQueryAppender);
}
use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class TestOperationLoggingAPIWithMr method testFetchResultsOfLogAsync.
@Test
public void testFetchResultsOfLogAsync() throws Exception {
// verify whether the sql operation log is generated and fetch correctly in async mode.
OperationHandle operationHandle = client.executeStatementAsync(sessionHandle, sql, null);
// Poll on the operation status till the query is completed
boolean isQueryRunning = true;
long pollTimeout = System.currentTimeMillis() + 100000;
OperationStatus opStatus;
OperationState state = null;
RowSet rowSetAccumulated = null;
StringBuilder logs = new StringBuilder();
while (isQueryRunning) {
// Break if polling times out
if (System.currentTimeMillis() > pollTimeout) {
break;
}
opStatus = client.getOperationStatus(operationHandle, false);
Assert.assertNotNull(opStatus);
state = opStatus.getState();
rowSetAccumulated = client.fetchResults(operationHandle, FetchOrientation.FETCH_NEXT, 2000, FetchType.LOG);
for (Object[] row : rowSetAccumulated) {
logs.append(row[0]);
}
if (state == OperationState.CANCELED || state == OperationState.CLOSED || state == OperationState.FINISHED || state == OperationState.ERROR) {
isQueryRunning = false;
}
Thread.sleep(10);
}
// The sql should be completed now.
Assert.assertEquals("Query should be finished", OperationState.FINISHED, state);
// Verify the accumulated logs
verifyFetchedLogPost(logs.toString(), expectedLogsVerbose, true);
// Verify the fetched logs from the beginning of the log file
RowSet rowSet = client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 2000, FetchType.LOG);
verifyFetchedLog(rowSet, expectedLogsVerbose);
}
use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class TestOperationLoggingAPIWithMr method testFetchResultsOfLog.
@Test
public void testFetchResultsOfLog() throws Exception {
// verify whether the sql operation log is generated and fetch correctly.
OperationHandle operationHandle = client.executeStatement(sessionHandle, sql, null);
RowSet rowSetLog = client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 1000, FetchType.LOG);
verifyFetchedLog(rowSetLog, expectedLogsVerbose);
}
Aggregations