Search in sources :

Example 1 with ITupleSink

use of edu.uci.ics.texera.dataflow.sink.ITupleSink in project textdb by TextDB.

the class QueryPlanResource method executeMutipleSinkPlan.

/**
 * @param plan Logical plan to be executed
 * @return Generic GenericWebResponse object
 */
private JsonNode executeMutipleSinkPlan(Plan plan) {
    HashMap<String, ISink> sinkMap = plan.getSinkMap();
    ObjectNode response = new ObjectMapper().createObjectNode();
    HashMap<String, List<Tuple>> executionResult = new HashMap<>();
    // execute the query plan from all sink operators and collect result
    for (HashMap.Entry<String, ISink> sinkEntry : sinkMap.entrySet()) {
        ISink sinkOperator = sinkEntry.getValue();
        if (sinkOperator instanceof ITupleSink) {
            ITupleSink tupleSink = (ITupleSink) sinkOperator;
            tupleSink.open();
            List<Tuple> result = tupleSink.collectAllTuples();
            tupleSink.close();
            executionResult.put(sinkEntry.getKey(), result);
        } else {
            sinkOperator.open();
            sinkOperator.processTuples();
            sinkOperator.close();
        }
    }
    // put all results in the array node.
    // each result has three fields : table, operatorID, chartType (if the sink operator is a visualization operator).
    ArrayNode arrayNode = new ObjectMapper().createArrayNode();
    for (HashMap.Entry<String, List<Tuple>> result : executionResult.entrySet()) {
        ObjectNode operatorMap = new ObjectMapper().createObjectNode();
        operatorMap.put("operatorID", result.getKey());
        ArrayNode resultNode = new ObjectMapper().createArrayNode();
        for (Tuple tuple : result.getValue()) {
            resultNode.add(tuple.getReadableJson());
        }
        operatorMap.set("table", resultNode);
        String operatorID = result.getKey();
        ISink operator = sinkMap.get(operatorID);
        if (operator instanceof VisualizationOperator) {
            operatorMap.put("chartType", ((VisualizationOperator) operator).getChartType());
        }
        arrayNode.add(operatorMap);
    }
    String resultID = UUID.randomUUID().toString();
    response.put("code", executionResult.isEmpty() ? 1 : 0);
    response.put("resultID", resultID);
    response.set("result", arrayNode);
    return response;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VisualizationOperator(edu.uci.ics.texera.dataflow.sink.VisualizationOperator) ISink(edu.uci.ics.texera.api.dataflow.ISink) ITupleSink(edu.uci.ics.texera.dataflow.sink.ITupleSink) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Aggregations

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 Tuple (edu.uci.ics.texera.api.tuple.Tuple)1 ITupleSink (edu.uci.ics.texera.dataflow.sink.ITupleSink)1 VisualizationOperator (edu.uci.ics.texera.dataflow.sink.VisualizationOperator)1