use of org.apache.hive.service.cli.RowSet in project hive by apache.
the class TestOperationLoggingLayout method testSwitchLogLayout.
@Test
public void testSwitchLogLayout() 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);
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);
checkAppenderState("before operation close ", LogDivertAppenderForTest.TEST_QUERY_ROUTING_APPENDER, queryId, false);
client.closeOperation(operationHandle);
checkAppenderState("after operation close ", LogDivertAppender.QUERY_ROUTING_APPENDER, queryId, true);
checkAppenderState("after operation close ", LogDivertAppenderForTest.TEST_QUERY_ROUTING_APPENDER, queryId, true);
}
use of org.apache.hive.service.cli.RowSet in project cdap by caskdata.
the class Hive14ExploreService method doFetchNextResults.
@Override
protected List<QueryResult> doFetchNextResults(OperationHandle handle, FetchOrientation fetchOrientation, int size) throws Exception {
RowSet rowSet = getCliService().fetchResults(handle, fetchOrientation, size, FetchType.QUERY_OUTPUT);
ImmutableList.Builder<QueryResult> rowsBuilder = ImmutableList.builder();
for (Object[] row : rowSet) {
List<Object> cols = Lists.newArrayList(row);
rowsBuilder.add(new QueryResult(cols));
}
return rowsBuilder.build();
}
use of org.apache.hive.service.cli.RowSet in project hive by apache.
the class TestHiveServer2Acid method testAsyncConcurrent.
/**
* Test overlapping async queries in one session.
* Since TxnManager is shared in the session this can cause all kind of trouble.
* @throws Exception ex
*/
@Test
public void testAsyncConcurrent() throws Exception {
String tableName = "TestHiveServer2TestConnection";
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);
serviceClient.executeStatement(sessHandle, "insert into " + tableName + " values(5)", confOverlay);
OperationHandle opHandle = serviceClient.executeStatementAsync(sessHandle, "select * from " + tableName, confOverlay);
assertOperationFinished(serviceClient, opHandle);
RowSet rowSet = serviceClient.fetchResults(opHandle);
serviceClient.executeStatement(sessHandle, "create temporary function sleepMsUDF as '" + TestHiveServer2Acid.SleepMsUDF.class.getName() + "'", confOverlay);
// Start a second "slow" query
OperationHandle opHandle2 = serviceClient.executeStatementAsync(sessHandle, "select sleepMsUDF(id, 1000), id from " + tableName, confOverlay);
// Close the first operation (this will destroy the Driver and TxnManager)
serviceClient.closeOperation(opHandle);
assertEquals(1, rowSet.numRows());
assertOperationFinished(serviceClient, opHandle2);
rowSet = serviceClient.fetchResults(opHandle2);
assertEquals(1, rowSet.numRows());
serviceClient.executeStatement(sessHandle, "DROP TABLE IF EXISTS " + tableName, confOverlay);
serviceClient.closeSession(sessHandle);
}
use of org.apache.hive.service.cli.RowSet in project hive by apache.
the class TestHiveServer2 method testConnection.
/**
* Open a new session and run a test query
* @throws Exception
*/
@Test
public void testConnection() throws Exception {
String tableName = "TestHiveServer2TestConnection";
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);
serviceClient.executeStatement(sessHandle, "DROP TABLE IF EXISTS " + tableName, confOverlay);
serviceClient.closeSession(sessHandle);
}
use of org.apache.hive.service.cli.RowSet 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);
}
}
Aggregations