use of io.prestosql.server.SessionContext in project hetu-core by openlookeng.
the class DataCenterStatementResource method postStatement.
@POST
@Path("/v1/dc/statement/{globalQueryId}")
@Produces(APPLICATION_JSON)
public synchronized Response postStatement(@PathParam("globalQueryId") String globalQueryId, DataCenterRequest request, @Context HttpServletRequest servletRequest, @Context UriInfo uriInfo) {
if (isNull(request)) {
throw badRequest(BAD_REQUEST, "SQL statement is empty");
}
SessionContext context = new HttpRequestSessionContext(servletRequest, groupProvider);
DataCenterResponse response;
try {
PagePublisherQueryRunner queryRunner = this.queryManager.submit(globalQueryId, request.getQuery(), request.getClientId(), request.getMaxAnticipatedDelay(), context);
if (queryRunner != null) {
response = new DataCenterResponse(DataCenterResponse.State.SUBMITTED, queryRunner.getSlug(), queryRunner.getConsumer(request.getClientId()) != null);
} else {
response = new DataCenterResponse(DataCenterResponse.State.FINISHED_ALREADY, null, false);
}
} catch (IllegalStateException ex) {
response = new DataCenterResponse(DataCenterResponse.State.FINISHED_ALREADY, null, false);
}
return Response.ok(response).build();
}
use of io.prestosql.server.SessionContext in project hetu-core by openlookeng.
the class QueuedStatementResource method postStatement.
@POST
@Path("/v1/statement")
@Produces(APPLICATION_JSON)
public Response postStatement(String statement, @HeaderParam(X_FORWARDED_PROTO) String xForwardedProto, @Context HttpServletRequest servletRequest, @Context UriInfo uriInfo) {
if (isNullOrEmpty(statement)) {
throw badRequest(BAD_REQUEST, "SQL statement is empty");
}
// only active coordinator is ready to accept new queries
NodeState state = nodeStateChangeHandler.getState();
if (state != ACTIVE) {
throw badRequest(SERVICE_UNAVAILABLE, "This coordinator is not active so can not accept queries");
}
SessionContext sessionContext = new HttpRequestSessionContext(servletRequest, groupProvider);
Query query = new Query(statement, sessionContext, dispatchManager);
queries.put(query.getQueryId(), query);
return Response.ok(query.getQueryResults(query.getLastToken(), uriInfo, xForwardedProto)).build();
}
Aggregations