use of edu.uci.ics.textdb.web.response.TextdbWebResponse in project textdb by TextDB.
the class NewQueryPlanResource method executeQueryPlan.
/**
* This is the edu.uci.ics.textdb.web.request handler for the execution of a Query Plan.
* @param logicalPlanJson, the json representation of the logical plan
* @return - Generic TextdbWebResponse object
*/
@POST
@Path("/execute")
public // TODO: investigate how to use LogicalPlan directly
TextdbWebResponse executeQueryPlan(String logicalPlanJson) {
try {
LogicalPlan logicalPlan = new ObjectMapper().readValue(logicalPlanJson, LogicalPlan.class);
Plan plan = logicalPlan.buildQueryPlan();
ISink sink = plan.getRoot();
// send response back to frontend
if (sink instanceof TupleSink) {
TupleSink tupleSink = (TupleSink) sink;
tupleSink.open();
List<Tuple> results = tupleSink.collectAllTuples();
tupleSink.close();
ArrayNode arrayNode = new ObjectMapper().createArrayNode();
for (Tuple tuple : results) {
arrayNode.add(tuple.getReadableJson());
}
return new TextdbWebResponse(0, new ObjectMapper().writeValueAsString(arrayNode));
} else {
// execute the plan and return success message
Engine.getEngine().evaluate(plan);
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("status", "plan sucessfully executed");
return new TextdbWebResponse(0, new ObjectMapper().writeValueAsString(objectNode));
}
} catch (IOException | RuntimeException e) {
// TODO remove RuntimeException after the exception refactor
e.printStackTrace();
throw new TextdbWebException(e.getMessage());
}
}
use of edu.uci.ics.textdb.web.response.TextdbWebResponse in project textdb by TextDB.
the class PlanStoreResource method updateQueryPlan.
@PUT
@Path("/{plan_name}")
public TextdbWebResponse updateQueryPlan(@PathParam("plan_name") String planName, String queryPlanBeanJson) {
try {
QueryPlanBean queryPlanBean = new ObjectMapper().readValue(queryPlanBeanJson, QueryPlanBean.class);
// Updating the plan in the plan store
planStore.updatePlan(planName, queryPlanBean.getDescription(), mapper.writeValueAsString(queryPlanBean.getQueryPlan()));
} catch (IOException | TextDBException e) {
throw new TextdbWebException(e.getMessage());
}
return new TextdbWebResponse(0, "Success");
}
use of edu.uci.ics.textdb.web.response.TextdbWebResponse in project textdb by TextDB.
the class PlanStoreResource method addQueryPlan.
@POST
public TextdbWebResponse addQueryPlan(String queryPlanBeanJson) {
try {
QueryPlanBean queryPlanBean = new ObjectMapper().readValue(queryPlanBeanJson, QueryPlanBean.class);
// Adding the query plan to the PlanStore
planStore.addPlan(queryPlanBean.getName(), queryPlanBean.getDescription(), mapper.writeValueAsString(queryPlanBean.getQueryPlan()));
} catch (TextDBException e) {
throw new TextdbWebException(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
}
return new TextdbWebResponse(0, "Success");
}
Aggregations