@Test public void testQueryJoinOptimizer() { final TupleExpr expr = new SPARQLParser().parseQuery("select * where {?a ?b ?c, \"1\".}", "http: new HalyardQueryJoinOptimizer(new HalyardEvaluationStatistics(null, null)).optimize(expr, null, null); expr.visit(new AbstractQueryModelVisitor<RuntimeException>(){ @Override public void meet(Join node) throws RuntimeException { assertTrue(expr.toString(), ((StatementPattern)node.getLeftArg()).getObjectVar().hasValue()); assertEquals(expr.toString(), "c", ((StatementPattern)node.getRightArg()).getObjectVar().getName()); } }); }
@Override public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) { final Set<String> parallelSplitBounds = new HashSet<>(); tupleExpr.visit(new AbstractQueryModelVisitor<IncompatibleOperationException>() { @Override public void meet(FunctionCall node) throws IncompatibleOperationException { if (HALYARD.PARALLEL_SPLIT_FUNCTION.toString().equals(node.getURI())) { for (ValueExpr arg : node.getArgs()) { if (arg instanceof Var) parallelSplitBounds.add(((Var)arg).getName()); } } super.meet(node); } }); tupleExpr.visit(new QueryJoinOptimizer.JoinVisitor() { private Set<String> priorityBounds = new HashSet<>(); @Override protected double getTupleExprCardinality(TupleExpr tupleExpr, Map<TupleExpr, Double> cardinalityMap, Map<TupleExpr, List<Var>> varsMap, Map<Var, Integer> varFreqMap, Set<String> boundVars) { boundVars.addAll(parallelSplitBounds); boundVars.addAll(priorityBounds); ((HalyardEvaluationStatistics) statistics).updateCardinalityMap(tupleExpr, boundVars, parallelSplitBounds, cardinalityMap); return super.getTupleExprCardinality(tupleExpr, cardinalityMap, varsMap, varFreqMap, boundVars); } @Override public void meet(Join node) { Set<String> origPriorityBounds = priorityBounds; try { priorityBounds = new HashSet<>(priorityBounds); super.meet(node); } finally { priorityBounds = origPriorityBounds; } } @Override protected List<Extension> getExtensions(List<TupleExpr> expressions) { List<Extension> exts = super.getExtensions(expressions); for (Extension ext : exts) { priorityBounds.addAll(ext.getBindingNames()); } return exts; } @Override protected List<TupleExpr> getSubSelects(List<TupleExpr> expressions) { List<TupleExpr> subs = super.getSubSelects(expressions); for (TupleExpr sub : subs) { priorityBounds.addAll(sub.getBindingNames()); } return subs; } }); }
HalyardQueryJoinOptimizer extends QueryJoinOptimizer { @Override public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) { final Set<String> parallelSplitBounds = new HashSet<>(); tupleExpr.visit(new AbstractQueryModelVisitor<IncompatibleOperationException>() { @Override public void meet(FunctionCall node) throws IncompatibleOperationException { if (HALYARD.PARALLEL_SPLIT_FUNCTION.toString().equals(node.getURI())) { for (ValueExpr arg : node.getArgs()) { if (arg instanceof Var) parallelSplitBounds.add(((Var)arg).getName()); } } super.meet(node); } }); tupleExpr.visit(new QueryJoinOptimizer.JoinVisitor() { private Set<String> priorityBounds = new HashSet<>(); @Override protected double getTupleExprCardinality(TupleExpr tupleExpr, Map<TupleExpr, Double> cardinalityMap, Map<TupleExpr, List<Var>> varsMap, Map<Var, Integer> varFreqMap, Set<String> boundVars) { boundVars.addAll(parallelSplitBounds); boundVars.addAll(priorityBounds); ((HalyardEvaluationStatistics) statistics).updateCardinalityMap(tupleExpr, boundVars, parallelSplitBounds, cardinalityMap); return super.getTupleExprCardinality(tupleExpr, cardinalityMap, varsMap, varFreqMap, boundVars); } @Override public void meet(Join node) { Set<String> origPriorityBounds = priorityBounds; try { priorityBounds = new HashSet<>(priorityBounds); super.meet(node); } finally { priorityBounds = origPriorityBounds; } } @Override protected List<Extension> getExtensions(List<TupleExpr> expressions) { List<Extension> exts = super.getExtensions(expressions); for (Extension ext : exts) { priorityBounds.addAll(ext.getBindingNames()); } return exts; } @Override protected List<TupleExpr> getSubSelects(List<TupleExpr> expressions) { List<TupleExpr> subs = super.getSubSelects(expressions); for (TupleExpr sub : subs) { priorityBounds.addAll(sub.getBindingNames()); } return subs; } }); } }
HalyardQueryJoinOptimizer extends QueryJoinOptimizer { @Override public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) { final Set<String> parallelSplitBounds = new HashSet<>(); tupleExpr.visit(new AbstractQueryModelVisitor<IncompatibleOperationException>() { @Override public void meet(FunctionCall node) throws IncompatibleOperationException { if (HALYARD.PARALLEL_SPLIT_FUNCTION.toString().equals(node.getURI())) { for (ValueExpr arg : node.getArgs()) { if (arg instanceof Var) parallelSplitBounds.add(((Var)arg).getName()); } } super.meet(node); } }); tupleExpr.visit(new QueryJoinOptimizer.JoinVisitor() { private Set<String> priorityBounds = new HashSet<>(); @Override protected double getTupleExprCardinality(TupleExpr tupleExpr, Map<TupleExpr, Double> cardinalityMap, Map<TupleExpr, List<Var>> varsMap, Map<Var, Integer> varFreqMap, Set<String> boundVars) { boundVars.addAll(parallelSplitBounds); boundVars.addAll(priorityBounds); ((HalyardEvaluationStatistics) statistics).updateCardinalityMap(tupleExpr, boundVars, parallelSplitBounds, cardinalityMap); return super.getTupleExprCardinality(tupleExpr, cardinalityMap, varsMap, varFreqMap, boundVars); } @Override public void meet(Join node) { Set<String> origPriorityBounds = priorityBounds; try { priorityBounds = new HashSet<>(priorityBounds); super.meet(node); } finally { priorityBounds = origPriorityBounds; } } @Override protected List<Extension> getExtensions(List<TupleExpr> expressions) { List<Extension> exts = super.getExtensions(expressions); for (Extension ext : exts) { priorityBounds.addAll(ext.getBindingNames()); } return exts; } @Override protected List<TupleExpr> getSubSelects(List<TupleExpr> expressions) { List<TupleExpr> subs = super.getSubSelects(expressions); for (TupleExpr sub : subs) { priorityBounds.addAll(sub.getBindingNames()); } return subs; } }); } HalyardQueryJoinOptimizer(HalyardEvaluationStatistics statistics); }
HalyardQueryJoinOptimizer extends QueryJoinOptimizer { @Override public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) { final Set<String> parallelSplitBounds = new HashSet<>(); tupleExpr.visit(new AbstractQueryModelVisitor<IncompatibleOperationException>() { @Override public void meet(FunctionCall node) throws IncompatibleOperationException { if (HALYARD.PARALLEL_SPLIT_FUNCTION.toString().equals(node.getURI())) { for (ValueExpr arg : node.getArgs()) { if (arg instanceof Var) parallelSplitBounds.add(((Var)arg).getName()); } } super.meet(node); } }); tupleExpr.visit(new QueryJoinOptimizer.JoinVisitor() { private Set<String> priorityBounds = new HashSet<>(); @Override protected double getTupleExprCardinality(TupleExpr tupleExpr, Map<TupleExpr, Double> cardinalityMap, Map<TupleExpr, List<Var>> varsMap, Map<Var, Integer> varFreqMap, Set<String> boundVars) { boundVars.addAll(parallelSplitBounds); boundVars.addAll(priorityBounds); ((HalyardEvaluationStatistics) statistics).updateCardinalityMap(tupleExpr, boundVars, parallelSplitBounds, cardinalityMap); return super.getTupleExprCardinality(tupleExpr, cardinalityMap, varsMap, varFreqMap, boundVars); } @Override public void meet(Join node) { Set<String> origPriorityBounds = priorityBounds; try { priorityBounds = new HashSet<>(priorityBounds); super.meet(node); } finally { priorityBounds = origPriorityBounds; } } @Override protected List<Extension> getExtensions(List<TupleExpr> expressions) { List<Extension> exts = super.getExtensions(expressions); for (Extension ext : exts) { priorityBounds.addAll(ext.getBindingNames()); } return exts; } @Override protected List<TupleExpr> getSubSelects(List<TupleExpr> expressions) { List<TupleExpr> subs = super.getSubSelects(expressions); for (TupleExpr sub : subs) { priorityBounds.addAll(sub.getBindingNames()); } return subs; } }); } HalyardQueryJoinOptimizer(HalyardEvaluationStatistics statistics); @Override void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings); }
HalyardQueryJoinOptimizer extends QueryJoinOptimizer { @Override public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) { final Set<String> parallelSplitBounds = new HashSet<>(); tupleExpr.visit(new AbstractQueryModelVisitor<IncompatibleOperationException>() { @Override public void meet(FunctionCall node) throws IncompatibleOperationException { if (HALYARD.PARALLEL_SPLIT_FUNCTION.toString().equals(node.getURI())) { for (ValueExpr arg : node.getArgs()) { if (arg instanceof Var) parallelSplitBounds.add(((Var)arg).getName()); } } super.meet(node); } }); tupleExpr.visit(new QueryJoinOptimizer.JoinVisitor() { private Set<String> priorityBounds = new HashSet<>(); @Override protected double getTupleExprCardinality(TupleExpr tupleExpr, Map<TupleExpr, Double> cardinalityMap, Map<TupleExpr, List<Var>> varsMap, Map<Var, Integer> varFreqMap, Set<String> boundVars) { boundVars.addAll(parallelSplitBounds); boundVars.addAll(priorityBounds); ((HalyardEvaluationStatistics) statistics).updateCardinalityMap(tupleExpr, boundVars, parallelSplitBounds, cardinalityMap); return super.getTupleExprCardinality(tupleExpr, cardinalityMap, varsMap, varFreqMap, boundVars); } @Override public void meet(Join node) { Set<String> origPriorityBounds = priorityBounds; try { priorityBounds = new HashSet<>(priorityBounds); super.meet(node); } finally { priorityBounds = origPriorityBounds; } } @Override protected List<Extension> getExtensions(List<TupleExpr> expressions) { List<Extension> exts = super.getExtensions(expressions); for (Extension ext : exts) { priorityBounds.addAll(ext.getBindingNames()); } return exts; } @Override protected List<TupleExpr> getSubSelects(List<TupleExpr> expressions) { List<TupleExpr> subs = super.getSubSelects(expressions); for (TupleExpr sub : subs) { priorityBounds.addAll(sub.getBindingNames()); } return subs; } }); } HalyardQueryJoinOptimizer(HalyardEvaluationStatistics statistics); @Override void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings);  }