Search in sources :

Example 1 with LogicalPlan

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

the class QueryPlanResourceTest method getLogicalPlan1.

/*
     * It generates a valid logical plan as follows.
     *
     * KeywordSource --> RegexMatcher --> TupleSink
     *
     */
public static LogicalPlan getLogicalPlan1() throws TexeraException {
    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.texera.dataflow.plangen.OperatorLink) LogicalPlan(edu.uci.ics.texera.dataflow.plangen.LogicalPlan)

Example 2 with LogicalPlan

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

the class QueryPlanResource method executeQueryPlan.

/**
 * This is the edu.uci.ics.texera.web.request handler for the execution of a Query Plan.
 * @param logicalPlanJson, the json representation of the logical plan
 * @return - Generic TexeraWebResponse object
 */
@POST
@Path("/execute")
public // TODO: investigate how to use LogicalPlan directly
JsonNode 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();
            // make sure result directory is created
            if (Files.notExists(resultDirectory)) {
                Files.createDirectories(resultDirectory);
            }
            // clean up old result files
            cleanupOldResults();
            // generate new UUID as the result id
            String resultID = UUID.randomUUID().toString();
            // write original json of the result into a file
            java.nio.file.Path resultFile = resultDirectory.resolve(resultID + ".json");
            Files.createFile(resultFile);
            Files.write(resultFile, new ObjectMapper().writeValueAsBytes(results));
            // put readable json of the result into response
            ArrayNode resultNode = new ObjectMapper().createArrayNode();
            for (Tuple tuple : results) {
                resultNode.add(tuple.getReadableJson());
            }
            ObjectNode response = new ObjectMapper().createObjectNode();
            response.put("code", 0);
            response.set("result", resultNode);
            response.put("resultID", resultID);
            return response;
        } else {
            // execute the plan and return success message
            Engine.getEngine().evaluate(plan);
            ObjectNode response = new ObjectMapper().createObjectNode();
            response.put("code", 1);
            response.put("message", "plan sucessfully executed");
            return response;
        }
    } catch (IOException | TexeraException e) {
        throw new TexeraWebException(e.getMessage());
    }
}
Also used : TupleSink(edu.uci.ics.texera.dataflow.sink.tuple.TupleSink) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IOException(java.io.IOException) Plan(edu.uci.ics.texera.api.engine.Plan) LogicalPlan(edu.uci.ics.texera.dataflow.plangen.LogicalPlan) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) ISink(edu.uci.ics.texera.api.dataflow.ISink) LogicalPlan(edu.uci.ics.texera.dataflow.plangen.LogicalPlan) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TexeraWebException(edu.uci.ics.texera.web.TexeraWebException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(edu.uci.ics.texera.api.tuple.Tuple) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

LogicalPlan (edu.uci.ics.texera.dataflow.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.texera.api.dataflow.ISink)1 Plan (edu.uci.ics.texera.api.engine.Plan)1 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)1 Tuple (edu.uci.ics.texera.api.tuple.Tuple)1 OperatorLink (edu.uci.ics.texera.dataflow.plangen.OperatorLink)1 TupleSink (edu.uci.ics.texera.dataflow.sink.tuple.TupleSink)1 TexeraWebException (edu.uci.ics.texera.web.TexeraWebException)1 IOException (java.io.IOException)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1