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;
}
Aggregations