use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class ExploreQueryExecutorHttpHandler method getQueryResultPreview.
@POST
@Path("data/explore/queries/{id}/preview")
public void getQueryResultPreview(HttpRequest request, HttpResponder responder, @PathParam("id") String id) throws 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 {
results = doAs(handle, new Callable<List<QueryResult>>() {
@Override
public List<QueryResult> call() throws Exception {
return exploreService.previewResults(handle);
}
});
}
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) {
if (e.isInactive()) {
responder.sendString(HttpResponseStatus.CONFLICT, "Preview is unavailable for inactive queries.");
return;
}
responder.sendStatus(HttpResponseStatus.NOT_FOUND);
}
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class ExploreQueryExecutorHttpHandler method closeQuery.
@DELETE
@Path("data/explore/queries/{id}")
public void closeQuery(HttpRequest request, HttpResponder responder, @PathParam("id") String id) throws ExploreException, SQLException {
try {
final QueryHandle handle = QueryHandle.fromId(id);
if (!handle.equals(QueryHandle.NO_OP)) {
doAs(handle, new Callable<Void>() {
@Override
public Void call() throws Exception {
exploreService.close(handle);
return null;
}
});
}
responder.sendStatus(HttpResponseStatus.OK);
} catch (IllegalArgumentException e) {
LOG.debug("Got exception:", e);
responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
} catch (HandleNotFoundException e) {
responder.sendStatus(HttpResponseStatus.NOT_FOUND);
}
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class ExploreQueryExecutorHttpHandler method downloadQueryResults.
@POST
@Path("data/explore/queries/{id}/download")
public void downloadQueryResults(HttpRequest request, final HttpResponder responder, @PathParam("id") final String id) throws ExploreException, IOException, SQLException, HandleNotFoundException {
// NOTE: this call is a POST because it is not idempotent: cursor of results is moved
final QueryHandle handle = QueryHandle.fromId(id);
doAs(handle, new Callable<Void>() {
@Override
public Void call() throws Exception {
doDownloadQueryResults(responder, handle);
return null;
}
});
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class BaseHiveExploreServiceTest method deleteNamespace.
/**
* Delete a namespace because app fabric is not started in explore tests.
*/
protected static void deleteNamespace(NamespaceId namespaceId) throws Exception {
namespacePathLocator.get(namespaceId).delete(true);
if (!NamespaceId.DEFAULT.equals(namespaceId)) {
QueryHandle handle = exploreService.deleteNamespace(namespaceId);
waitForCompletionStatus(handle, 50, TimeUnit.MILLISECONDS, 40);
}
namespaceAdmin.delete(namespaceId);
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class InMemoryExploreServiceTest method runCommand.
private static void runCommand(String namespace, String command, boolean expectedHasResult, List<ColumnDesc> expectedColumnDescs, List<QueryResult> expectedResults) throws Exception {
QueryHandle handle = exploreService.execute(new NamespaceId(namespace), command);
QueryStatus status = waitForCompletionStatus(handle);
Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
Assert.assertEquals(expectedHasResult, status.hasResults());
Assert.assertEquals(expectedColumnDescs, exploreService.getResultSchema(handle));
Assert.assertEquals(expectedResults.toString(), trimColumnValues(exploreService.nextResults(handle, 100)).toString());
exploreService.close(handle);
}
Aggregations