use of co.cask.cdap.proto.QueryResult in project cdap by caskdata.
the class InMemoryExploreServiceTest method runNamespacedTest.
private void runNamespacedTest(String namespace) throws Exception {
URL loadFileUrl = getClass().getResource("/test_table.dat");
Assert.assertNotNull(loadFileUrl);
// Should have no tables
runCommand(namespace, "show tables", true, Lists.newArrayList(new ColumnDesc("tab_name", "STRING", 1, "from deserializer")), ImmutableList.<QueryResult>of());
runCommand(namespace, "create table test (first INT, second STRING) ROW FORMAT " + "DELIMITED FIELDS TERMINATED BY '\\t'", false, ImmutableList.<ColumnDesc>of(), ImmutableList.<QueryResult>of());
runCommand(namespace, "show tables", true, Lists.newArrayList(new ColumnDesc("tab_name", "STRING", 1, "from deserializer")), Lists.newArrayList(new QueryResult(Lists.<Object>newArrayList("test"))));
runCommand(namespace, "describe test", true, Lists.newArrayList(new ColumnDesc("col_name", "STRING", 1, "from deserializer"), new ColumnDesc("data_type", "STRING", 2, "from deserializer"), new ColumnDesc("comment", "STRING", 3, "from deserializer")), Lists.newArrayList(new QueryResult(Lists.<Object>newArrayList("first", "int", "")), new QueryResult(Lists.<Object>newArrayList("second", "string", ""))));
// Should have no data
runCommand(namespace, "select * from test", true, Lists.newArrayList(new ColumnDesc("test.first", "INT", 1, null), new ColumnDesc("test.second", "STRING", 2, null)), ImmutableList.<QueryResult>of());
runCommand(namespace, "LOAD DATA LOCAL INPATH '" + new File(loadFileUrl.toURI()).getAbsolutePath() + "' INTO TABLE test", false, ImmutableList.<ColumnDesc>of(), ImmutableList.<QueryResult>of());
runCommand(namespace, "select first, second from test", true, Lists.newArrayList(new ColumnDesc("first", "INT", 1, null), new ColumnDesc("second", "STRING", 2, null)), Lists.newArrayList(new QueryResult(Lists.<Object>newArrayList("1", "one")), new QueryResult(Lists.<Object>newArrayList("2", "two")), new QueryResult(Lists.<Object>newArrayList("3", "three")), new QueryResult(Lists.<Object>newArrayList("4", "four")), new QueryResult(Lists.<Object>newArrayList("5", "five"))));
runCommand(namespace, "select * from test", true, Lists.newArrayList(new ColumnDesc("test.first", "INT", 1, null), new ColumnDesc("test.second", "STRING", 2, null)), Lists.newArrayList(new QueryResult(Lists.<Object>newArrayList("1", "one")), new QueryResult(Lists.<Object>newArrayList("2", "two")), new QueryResult(Lists.<Object>newArrayList("3", "three")), new QueryResult(Lists.<Object>newArrayList("4", "four")), new QueryResult(Lists.<Object>newArrayList("5", "five"))));
}
use of co.cask.cdap.proto.QueryResult in project cdap by caskdata.
the class ExploreResultSetTest method sameNamedColumns.
@Test
public void sameNamedColumns() throws Exception {
ExploreClient exploreClient = new MockExploreClient(ImmutableMap.of("mock_query", (List<ColumnDesc>) Lists.newArrayList(new ColumnDesc("column1", "STRING", 2, ""), new ColumnDesc("column1", "int", 1, ""))), ImmutableMap.of("mock_query", (List<QueryResult>) Lists.newArrayList(new QueryResult(ImmutableList.<Object>of(1, "value1")))));
ResultSet resultSet = new ExploreResultSet(exploreClient.submit(new NamespaceId(ns), "mock_query").get(), new ExploreStatement(null, exploreClient, ns), 0);
Assert.assertTrue(resultSet.next());
Assert.assertEquals(1, resultSet.findColumn("column1"));
Assert.assertEquals(1, resultSet.getObject("column1"));
// Can't call get... after resultSet is closed, nor findColumn
resultSet.close();
try {
resultSet.getObject(1);
} catch (SQLException e) {
// Expected
}
try {
resultSet.findColumn("column1");
} catch (SQLException e) {
// Expected
}
}
use of co.cask.cdap.proto.QueryResult in project cdap by caskdata.
the class ExploreQueryExecutorHttpHandler method getQueryNextResults.
@POST
@Path("data/explore/queries/{id}/next")
public void getQueryNextResults(FullHttpRequest request, HttpResponder responder, @PathParam("id") String id) throws IOException, ExploreException {
// NOTE: this call is a POST because it is not idempotent: cursor of results is moved
try {
final QueryHandle handle = QueryHandle.fromId(id);
List<QueryResult> results;
if (handle.equals(QueryHandle.NO_OP)) {
results = Lists.newArrayList();
} else {
Map<String, String> args = decodeArguments(request);
final int size = args.containsKey("size") ? Integer.valueOf(args.get("size")) : 100;
results = doAs(handle, new Callable<List<QueryResult>>() {
@Override
public List<QueryResult> call() throws Exception {
return exploreService.nextResults(handle, size);
}
});
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(results));
} catch (IllegalArgumentException e) {
LOG.debug("Got exception:", e);
responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
} catch (SQLException e) {
LOG.debug("Got exception:", e);
responder.sendString(HttpResponseStatus.BAD_REQUEST, String.format("[SQLState %s] %s", e.getSQLState(), e.getMessage()));
} catch (HandleNotFoundException e) {
responder.sendStatus(HttpResponseStatus.NOT_FOUND);
}
}
use of co.cask.cdap.proto.QueryResult in project cdap by caskdata.
the class QueryResultsBodyProducer method nextChunk.
@Override
public ByteBuf nextChunk() throws Exception {
buffer.clear();
if (results == null) {
initialize();
}
if (results.isEmpty()) {
return Unpooled.EMPTY_BUFFER;
}
for (QueryResult result : results) {
appendCSVRow(writer, result);
}
writer.flush();
results = exploreService.nextResults(handle, AbstractExploreQueryExecutorHttpHandler.DOWNLOAD_FETCH_CHUNK_SIZE);
return buffer.copy();
}
use of co.cask.cdap.proto.QueryResult in project cdap by caskdata.
the class Hive13ExploreService method doFetchNextResults.
@SuppressWarnings("unchecked")
@Override
protected List<QueryResult> doFetchNextResults(OperationHandle handle, FetchOrientation fetchOrientation, int size) throws Exception {
Class cliServiceClass = Class.forName("org.apache.hive.service.cli.CLIService");
Method fetchResultsMethod = cliServiceClass.getMethod("fetchResults", OperationHandle.class, FetchOrientation.class, Long.TYPE);
RowSet rowSet = (RowSet) fetchResultsMethod.invoke(getCliService(), handle, fetchOrientation, size);
ImmutableList.Builder<QueryResult> rowsBuilder = ImmutableList.builder();
for (Object[] row : rowSet) {
List<Object> cols = Lists.newArrayList(row);
rowsBuilder.add(new QueryResult(cols));
}
return rowsBuilder.build();
}
Aggregations