private static Tuple<QueryResult, Set<Variable>> evaluateSubgraph(
final String subgraphSerializedAsJSONString, final Dataset dataset,
final IOperatorCreator operatorCreator, final ISubgraphExecutor<?> sgExecuter) throws JSONException {
final CollectResult collectResult = new CollectResult(true);
final SubgraphContainerFormatter formatter = new SubgraphContainerFormatter(dataset, operatorCreator, collectResult,sgExecuter);
final Root root = formatter.deserialize(new JSONObject(subgraphSerializedAsJSONString));
// some initializations
root.deleteParents();
root.setParents();
root.detectCycles();
root.sendMessage(new BoundVariablesMessage());
Class<? extends Bindings> instanceClass = null;
if (Bindings.instanceClass == BindingsArrayVarMinMax.class
|| Bindings.instanceClass == BindingsArrayPresortingNumbers.class) {
// is BindingsArrayVarMinMax or BindingsArrayPresortingNumbers
// necessary? Or is only BindingsArray sufficient?
@SuppressWarnings("serial")
final SimpleOperatorGraphVisitor sogv = new SimpleOperatorGraphVisitor() {
public boolean found = false;
@Override
public Object visit(final BasicOperator basicOperator) {
if (basicOperator instanceof FastSort) {
this.found = true;
}
return null;
}
@Override
public boolean equals(final Object o) {
if (o instanceof Boolean) {
return this.found == (Boolean) o;
} else {
return super.equals(o);
}
}
};
root.visit(sogv);
if (sogv.equals(false)) {
instanceClass = Bindings.instanceClass;
Bindings.instanceClass = BindingsArray.class;
}
}
root.physicalOptimization();
root.deleteParents();
root.setParents();
root.detectCycles();
//MoveFilter to SubgraphContainer rule
final AfterPhysicalOptimizationDistributedRulePackage refie = new AfterPhysicalOptimizationDistributedRulePackage();
refie.applyRules(root);
// evaluate subgraph!
final BindingsFactory bindingsFactory= BindingsFactory.createBindingsFactory(CommonCoreQueryEvaluator.getAllVariablesOfQuery(root));
root.sendMessage(new BindingsFactoryMessage(bindingsFactory));
root.sendMessage(new StartOfEvaluationMessage());
root.startProcessing();
root.sendMessage(new EndOfEvaluationMessage());
if (instanceClass != null) {
Bindings.instanceClass = instanceClass;
}
//Result is back ..