Search in sources :

Example 1 with LogicalPlan

use of edu.uci.ics.textdb.exp.plangen.LogicalPlan 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());
    }
}
Also used : TupleSink(edu.uci.ics.textdb.exp.sink.tuple.TupleSink) TextdbWebResponse(edu.uci.ics.textdb.web.response.TextdbWebResponse) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IOException(java.io.IOException) LogicalPlan(edu.uci.ics.textdb.exp.plangen.LogicalPlan) Plan(edu.uci.ics.textdb.api.engine.Plan) ISink(edu.uci.ics.textdb.api.dataflow.ISink) TextdbWebException(edu.uci.ics.textdb.web.TextdbWebException) LogicalPlan(edu.uci.ics.textdb.exp.plangen.LogicalPlan) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with LogicalPlan

use of edu.uci.ics.textdb.exp.plangen.LogicalPlan in project textdb by TextDB.

the class NewQueryPlanResourceTest method getLogicalPlan1.

/*
     * It generates a valid logical plan as follows.
     *
     * KeywordSource --> RegexMatcher --> TupleSink
     *
     */
public static LogicalPlan getLogicalPlan1() throws RuntimeException {
    LogicalPlan logicalPlan = new LogicalPlan();
    logicalPlan.addOperator(keywordSourcePredicate);
    logicalPlan.addOperator(regexPredicate);
    logicalPlan.addOperator(tupleSinkPredicate);
    logicalPlan.addLink(new OperatorLink(KEYWORD_SOURCE_ID, REGEX_ID));
    logicalPlan.addLink(new OperatorLink(REGEX_ID, TUPLE_SINK_ID));
    return logicalPlan;
}
Also used : OperatorLink(edu.uci.ics.textdb.exp.plangen.OperatorLink) LogicalPlan(edu.uci.ics.textdb.exp.plangen.LogicalPlan)

Aggregations

LogicalPlan (edu.uci.ics.textdb.exp.plangen.LogicalPlan)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ISink (edu.uci.ics.textdb.api.dataflow.ISink)1 Plan (edu.uci.ics.textdb.api.engine.Plan)1 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)1 OperatorLink (edu.uci.ics.textdb.exp.plangen.OperatorLink)1 TupleSink (edu.uci.ics.textdb.exp.sink.tuple.TupleSink)1 TextdbWebException (edu.uci.ics.textdb.web.TextdbWebException)1 TextdbWebResponse (edu.uci.ics.textdb.web.response.TextdbWebResponse)1 IOException (java.io.IOException)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1