@Test public void twoIndexFilterTest() { String q1 = "" + "SELECT ?f ?m ?d ?e ?l ?c " + "{" + " Filter(?f > \"5\")." + " Filter(?e > \"5\")." + " ?f a ?m ." + " ?e a ?l ." + " ?d <uri:talksTo> ?f . " + " ?c <uri:talksTo> ?e . " + " ?m <http: + " ?l <http: + "}"; String q2 = "" + "SELECT ?s ?t ?u " + "{" + " ?s a ?t ." + " ?t <http: + " ?u <uri:talksTo> ?s . " + "}"; String q3 = "" + "SELECT ?s ?t ?u " + "{" + " Filter(?s > \"5\") ." + " ?s a ?t ." + " ?t <http: + " ?u <uri:talksTo> ?s . " + "}"; String q4 = "" + "SELECT ?f ?m ?d " + "{" + " Filter(?f > \"5\") ." + " ?f a ?m ." + " ?m <http: + " ?d <uri:talksTo> ?f . " + "}"; String q5 = "" + "SELECT ?e ?l ?c " + "{" + " Filter(?e > \"5\") ." + " ?e a ?l ." + " ?l <http: + " ?c <uri:talksTo> ?e . " + "}"; SPARQLParser parser = new SPARQLParser(); ParsedQuery pq1 = null; ParsedQuery pq2 = null; ParsedQuery pq3 = null; ParsedQuery pq4 = null; ParsedQuery pq5 = null; try { pq1 = parser.parseQuery(q1, null); pq2 = parser.parseQuery(q2, null); pq3 = parser.parseQuery(q3, null); pq4 = parser.parseQuery(q4, null); pq5 = parser.parseQuery(q5, null); } catch (Exception e) { e.printStackTrace(); } SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet( (Projection) pq2.getTupleExpr()); SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet( (Projection) pq3.getTupleExpr()); SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet( (Projection) pq4.getTupleExpr()); SimpleExternalTupleSet extTup4 = new SimpleExternalTupleSet( (Projection) pq5.getTupleExpr()); List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); list.add(extTup2); list.add(extTup1); List<ExternalTupleSet> list2 = new ArrayList<ExternalTupleSet>(); list2.add(extTup3); list2.add(extTup4); IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator( pq1.getTupleExpr(), list); Iterator<TupleExpr> plans = new TupleExecutionPlanGenerator() .getPlans(iep.getIndexedTuples()); IndexPlanValidator ipv = new IndexPlanValidator(false); Iterator<TupleExpr> validPlans = ipv.getValidTuples(plans); ThreshholdPlanSelector tps = new ThreshholdPlanSelector( pq1.getTupleExpr()); TupleExpr optimalTup = tps.getThreshholdQueryPlan(validPlans, .4, .8, .1, .1); NodeCollector nc = new NodeCollector(); optimalTup.visit(nc); Assert.assertEquals(nc.getNodes().size(), list2.size()); for (QueryModelNode e : nc.getNodes()) { Assert.assertTrue(list2.contains(e)); } }
@Override public TupleExpr getThreshholdQueryPlan(Iterator<TupleExpr> tuples, double threshhold, double indexWeight, double commonVarWeight, double extProdWeight) { if (threshhold < 0 || threshhold > 1) { throw new IllegalArgumentException("Threshhold must be between 0 and 1!"); } double minCost = Double.MAX_VALUE; TupleExpr minTup = null; double tempCost = 0; TupleExpr tempTup = null; while (tuples.hasNext()) { tempTup = tuples.next(); tempCost = getCost(tempTup, indexWeight, commonVarWeight, extProdWeight); if (tempCost < minCost) { minCost = tempCost; minTup = tempTup; } if (minCost <= threshhold) { return minTup; } } return minTup; }
ThreshholdPlanSelector implements IndexedQueryPlanSelector { @Override public TupleExpr getThreshholdQueryPlan(Iterator<TupleExpr> tuples, double threshhold, double indexWeight, double commonVarWeight, double extProdWeight) { if (threshhold < 0 || threshhold > 1) { throw new IllegalArgumentException("Threshhold must be between 0 and 1!"); } double minCost = Double.MAX_VALUE; TupleExpr minTup = null; double tempCost = 0; TupleExpr tempTup = null; while (tuples.hasNext()) { tempTup = tuples.next(); tempCost = getCost(tempTup, indexWeight, commonVarWeight, extProdWeight); if (tempCost < minCost) { minCost = tempCost; minTup = tempTup; } if (minCost <= threshhold) { return minTup; } } return minTup; } }
ThreshholdPlanSelector implements IndexedQueryPlanSelector { @Override public TupleExpr getThreshholdQueryPlan(Iterator<TupleExpr> tuples, double threshhold, double indexWeight, double commonVarWeight, double extProdWeight) { if (threshhold < 0 || threshhold > 1) { throw new IllegalArgumentException("Threshhold must be between 0 and 1!"); } double minCost = Double.MAX_VALUE; TupleExpr minTup = null; double tempCost = 0; TupleExpr tempTup = null; while (tuples.hasNext()) { tempTup = tuples.next(); tempCost = getCost(tempTup, indexWeight, commonVarWeight, extProdWeight); if (tempCost < minCost) { minCost = tempCost; minTup = tempTup; } if (minCost <= threshhold) { return minTup; } } return minTup; } ThreshholdPlanSelector(TupleExpr query); }
ThreshholdPlanSelector implements IndexedQueryPlanSelector { @Override public TupleExpr getThreshholdQueryPlan(Iterator<TupleExpr> tuples, double threshhold, double indexWeight, double commonVarWeight, double extProdWeight) { if (threshhold < 0 || threshhold > 1) { throw new IllegalArgumentException("Threshhold must be between 0 and 1!"); } double minCost = Double.MAX_VALUE; TupleExpr minTup = null; double tempCost = 0; TupleExpr tempTup = null; while (tuples.hasNext()) { tempTup = tuples.next(); tempCost = getCost(tempTup, indexWeight, commonVarWeight, extProdWeight); if (tempCost < minCost) { minCost = tempCost; minTup = tempTup; } if (minCost <= threshhold) { return minTup; } } return minTup; } ThreshholdPlanSelector(TupleExpr query); @Override TupleExpr getThreshholdQueryPlan(Iterator<TupleExpr> tuples, double threshhold, double indexWeight,
            double commonVarWeight, double extProdWeight); double getCost(TupleExpr te, double indexWeight, double commonVarWeight, double dirProdWeight); }
ThreshholdPlanSelector implements IndexedQueryPlanSelector { @Override public TupleExpr getThreshholdQueryPlan(Iterator<TupleExpr> tuples, double threshhold, double indexWeight, double commonVarWeight, double extProdWeight) { if (threshhold < 0 || threshhold > 1) { throw new IllegalArgumentException("Threshhold must be between 0 and 1!"); } double minCost = Double.MAX_VALUE; TupleExpr minTup = null; double tempCost = 0; TupleExpr tempTup = null; while (tuples.hasNext()) { tempTup = tuples.next(); tempCost = getCost(tempTup, indexWeight, commonVarWeight, extProdWeight); if (tempCost < minCost) { minCost = tempCost; minTup = tempTup; } if (minCost <= threshhold) { return minTup; } } return minTup; } ThreshholdPlanSelector(TupleExpr query); @Override TupleExpr getThreshholdQueryPlan(Iterator<TupleExpr> tuples, double threshhold, double indexWeight,
            double commonVarWeight, double extProdWeight); double getCost(TupleExpr te, double indexWeight, double commonVarWeight, double dirProdWeight);  }