final QueryHandle handle = QueryHandle.fromId(id); List<QueryResult> results; if (handle.equals(QueryHandle.NO_OP)) { results = Lists.newArrayList(); } else {
final QueryHandle handle = QueryHandle.fromId(id); QueryStatus status; if (!handle.equals(QueryHandle.NO_OP)) { status = doAs(handle, new Callable<QueryStatus>() { @Override
@GET @Path("data/explore/queries/{id}/schema") public void getQueryResultsSchema(HttpRequest request, HttpResponder responder, @PathParam("id") String id) throws ExploreException { try { final QueryHandle handle = QueryHandle.fromId(id); List<ColumnDesc> schema; if (!handle.equals(QueryHandle.NO_OP)) { schema = doAs(handle, new Callable<List<ColumnDesc>>() { @Override public List<ColumnDesc> call() throws Exception { return exploreService.getResultSchema(handle); } }); } else { schema = Lists.newArrayList(); } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(schema)); } 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); } }
@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); } }
@GET @Path("data/explore/queries/{id}/schema") public void getQueryResultsSchema(HttpRequest request, HttpResponder responder, @PathParam("id") String id) throws ExploreException { try { final QueryHandle handle = QueryHandle.fromId(id); List<ColumnDesc> schema; if (!handle.equals(QueryHandle.NO_OP)) { schema = doAs(handle, new Callable<List<ColumnDesc>>() { @Override public List<ColumnDesc> call() throws Exception { return exploreService.getResultSchema(handle); } }); } else { schema = Lists.newArrayList(); } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(schema)); } 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); } }
@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); } }
final QueryHandle handle = QueryHandle.fromId(id); List<QueryResult> results; if (handle.equals(QueryHandle.NO_OP)) { results = Lists.newArrayList(); } else {
final QueryHandle handle = QueryHandle.fromId(id); QueryStatus status; if (!handle.equals(QueryHandle.NO_OP)) { status = doAs(handle, new Callable<QueryStatus>() { @Override
final QueryHandle handle = QueryHandle.fromId(id); List<QueryResult> results; if (handle.equals(QueryHandle.NO_OP)) { results = Lists.newArrayList(); } else {
final QueryHandle handle = QueryHandle.fromId(id); List<QueryResult> results; if (handle.equals(QueryHandle.NO_OP)) { results = Lists.newArrayList(); } else {
private void doDownloadQueryResults(HttpResponder responder, QueryHandle handle) throws ExploreException, IOException { try { if (handle.equals(QueryHandle.NO_OP) || !exploreService.getStatus(handle).getStatus().equals(QueryStatus.OpStatus.FINISHED)) { responder.sendStatus(HttpResponseStatus.CONFLICT); return; } QueryResultsBodyProducer queryResultsBodyProducer = new QueryResultsBodyProducer(exploreService, handle); responder.sendContent(HttpResponseStatus.OK, queryResultsBodyProducer, EmptyHttpHeaders.INSTANCE); } 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, "Query is inactive"); } else { responder.sendStatus(HttpResponseStatus.NOT_FOUND); } } } }
private void doDownloadQueryResults(HttpResponder responder, QueryHandle handle) throws ExploreException, IOException { try { if (handle.equals(QueryHandle.NO_OP) || !exploreService.getStatus(handle).getStatus().equals(QueryStatus.OpStatus.FINISHED)) { responder.sendStatus(HttpResponseStatus.CONFLICT); return; } QueryResultsBodyProducer queryResultsBodyProducer = new QueryResultsBodyProducer(exploreService, handle); responder.sendContent(HttpResponseStatus.OK, queryResultsBodyProducer, EmptyHttpHeaders.INSTANCE); } 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, "Query is inactive"); } else { responder.sendStatus(HttpResponseStatus.NOT_FOUND); } } } }