private void replaceIndexScanOperatorWithSubGraphContainer(
final BasicIndexScan _indexScan) {
try {
// get root
final Root rootNodeOfOuterGraph = _indexScan.getRoot();
Object[] keys = distribution.getKeysForQuerying(_indexScan
.getTriplePattern().iterator().next());
// TODO: 2) catch TriplePatternNotSupportedError and make union of
// SubgraphContainer to all possible nodes...
// remember original connections and connect new graph with these
// connections
final Collection<BasicOperator> preds = _indexScan
.getPrecedingOperators();
final List<OperatorIDTuple> succs = _indexScan
.getSucceedingOperators();
// create union - operation
final Collection<Variable> v = _indexScan.getIntersectionVariables();
final Union union = new Union();
// the succeding of the union of all subgraphs is the succeding of the indexScan
union.addSucceedingOperators(succs);
union.setIntersectionVariables(v);
union.setUnionVariables(v);
/*
* here we collect all used subgraphs
*/
Collection<BasicOperator> subgraphs = new ArrayList<BasicOperator>();
/*
* for each key for the given triple pattern ...
*/
int countingSubgraphs = 0;
for (Object key : keys) {
/*
* create new inner root
*/
final Root rootNodeOfSubGraph = rootNodeOfOuterGraph
.newInstance(rootNodeOfOuterGraph.dataset);
/*
* create subgraph
*/
final SubgraphContainer container = new SubgraphContainer(
rootNodeOfSubGraph, key, subgraphExecutor);
/*
* store new basic index scan instead of using it n-times, because same object used
*/
BasicIndexScan indexScan = new QueryClientIndexScan(_indexScan.getRoot(),_indexScan.getTriplePattern());
/*
* store variables
*/
final HashSet<Variable> variables = new HashSet<Variable>(
_indexScan.getIntersectionVariables());
container.setUnionVariables(variables);
container.setIntersectionVariables(variables);
// generate new connections...
final Filter filter = this.getFilterFromIndexScan(indexScan);
if (filter != null) {
if (indexScan.getUnionVariables().containsAll(
filter.getUsedVariables())) {
Filter newFilter;
try {
newFilter = new Filter(filter.toString().substring(
0, filter.toString().length() - 2));
indexScan
.setSucceedingOperator(new OperatorIDTuple(
newFilter, 0));
newFilter
.setSucceedingOperator(new OperatorIDTuple(
new Result(), 0));
} catch (final ParseException e) {
e.printStackTrace();
}
} else {
indexScan.setSucceedingOperator(new OperatorIDTuple(
new Result(), 0));
}
} else {
indexScan.setSucceedingOperator(new OperatorIDTuple(
new Result(), 0));
}
// indexScan.setSucceedingOperator(new OperatorIDTuple(new
// Result(),
// 0));
//connect indexScan in subgraph container
rootNodeOfSubGraph.setSucceedingOperator(new OperatorIDTuple(
indexScan, countingSubgraphs));
rootNodeOfSubGraph.deleteParents();
rootNodeOfSubGraph.setParents();
// original connections set at new graph
/*
* create Operator for union of all subgraphs
*/