use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class ThriftCliServiceTestWithCookie method testExecuteStatement.
/**
* Test synchronous query execution
* @throws Exception
*/
@Test
public void testExecuteStatement() throws Exception {
Map<String, String> opConf = new HashMap<String, String>();
// Open a new client session
SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, opConf);
// Session handle should not be null
assertNotNull("Session handle should not be null", sessHandle);
// Change lock manager to embedded mode
String queryString = "SET hive.lock.manager=" + "org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager";
client.executeStatement(sessHandle, queryString, opConf);
// Drop the table if it exists
queryString = "DROP TABLE IF EXISTS TEST_EXEC_THRIFT";
client.executeStatement(sessHandle, queryString, opConf);
// Create a test table
queryString = "CREATE TABLE TEST_EXEC_THRIFT(ID STRING)";
client.executeStatement(sessHandle, queryString, opConf);
// Execute another query
queryString = "SELECT ID+1 FROM TEST_EXEC_THRIFT";
OperationHandle opHandle = client.executeStatement(sessHandle, queryString, opConf);
assertNotNull(opHandle);
OperationStatus opStatus = client.getOperationStatus(opHandle, false);
assertNotNull(opStatus);
OperationState state = opStatus.getState();
// Expect query to be completed now
assertEquals("Query should be finished", OperationState.FINISHED, state);
// Cleanup
queryString = "DROP TABLE TEST_EXEC_THRIFT";
client.executeStatement(sessHandle, queryString, opConf);
client.closeSession(sessHandle);
}
use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class OperationLoggingAPITestBase method testFetchResultsOfLogWithVerboseMode.
@Test
public void testFetchResultsOfLogWithVerboseMode() throws Exception {
String queryString = "set hive.server2.logging.operation.level=verbose";
client.executeStatement(sessionHandle, queryString, null);
// 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);
// Verbose Logs should contain everything, including execution and performance
verifyFetchedLog(rowSetLog, expectedLogsVerbose);
verifyFetchedLog(rowSetLog, expectedLogsExecution);
verifyFetchedLog(rowSetLog, expectedLogsPerformance);
}
use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class OperationLoggingAPITestBase method testFetchResultsOfLogWithNoneMode.
@Test
public void testFetchResultsOfLogWithNoneMode() throws Exception {
try {
String queryString = "set hive.server2.logging.operation.level=none";
client.executeStatement(sessionHandle, queryString, null);
// 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);
// We should not get any rows.
assert (rowSetLog.numRows() == 0);
} finally {
// Restore everything to default setup to avoid discrepancy between junit test runs
String queryString2 = "set hive.server2.logging.operation.level=verbose";
client.executeStatement(sessionHandle, queryString2, null);
}
}
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);
}
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);
}
Aggregations