http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/IndexPlanValidatorTest.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/IndexPlanValidatorTest.java b/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/IndexPlanValidatorTest.java new file mode 100644 index 0000000..b83ef10 --- /dev/null +++ b/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/IndexPlanValidatorTest.java @@ -0,0 +1,1128 @@ +package mvm.rya.indexing.IndexPlanValidator; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import junit.framework.Assert; +import mvm.rya.indexing.IndexPlanValidator.ThreshholdPlanSelectorTest.NodeCollector; +import mvm.rya.indexing.external.ExternalProcessor; +import mvm.rya.indexing.external.tupleSet.ExternalTupleSet; +import mvm.rya.indexing.external.tupleSet.SimpleExternalTupleSet; + +import org.junit.Test; +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.algebra.Projection; +import org.openrdf.query.algebra.QueryModelNode; +import org.openrdf.query.algebra.TupleExpr; +import org.openrdf.query.parser.ParsedQuery; +import org.openrdf.query.parser.sparql.SPARQLParser; + +import com.google.common.collect.Lists; + +public class IndexPlanValidatorTest { + + + @Test + public void testEvaluateTwoIndexTwoVarOrder1() { + + System.out.println("********************Test number 1***************************"); + + // TODO Auto-generated method stub + String indexSparqlString = ""// + + "SELECT ?c ?e ?l " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String indexSparqlString2 = ""// + + "SELECT ?e ?o ?l " // + + "{" // + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String queryString = ""// + + "SELECT ?e ?c ?l ?o " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + + SPARQLParser sp = new SPARQLParser(); + ParsedQuery index1 = null; + ParsedQuery index2 = null; + try { + index1 = sp.parseQuery(indexSparqlString, null); + index2 = sp.parseQuery(indexSparqlString2, null); + } catch (MalformedQueryException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + List<ExternalTupleSet> index = Lists.newArrayList(); + + SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection)index1.getTupleExpr()); + SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection)index2.getTupleExpr());; + + index.add(ais1); + index.add(ais2); + + ParsedQuery pq = null; + + try { + pq = sp.parseQuery(queryString, null); + } catch (MalformedQueryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + ExternalProcessor processor = new ExternalProcessor(index); + TupleExpr tup = processor.process(pq.getTupleExpr()); + + System.out.println("TupleExpr is " + tup); + + IndexPlanValidator ipv = new IndexPlanValidator(false); + Assert.assertEquals(false, ipv.isValid(tup)); + + } + + + + @Test + public void testEvaluateTwoIndexTwoVarOrder2() { + + System.out.println("********************Test number 2***************************"); + + // TODO Auto-generated method stub + String indexSparqlString = ""// + + "SELECT ?e ?l ?c " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String indexSparqlString2 = ""// + + "SELECT ?e ?o ?l " // + + "{" // + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String queryString = ""// + + "SELECT ?e ?c ?l ?o " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + + SPARQLParser sp = new SPARQLParser(); + ParsedQuery index1 = null; + ParsedQuery index2 = null; + try { + index1 = sp.parseQuery(indexSparqlString, null); + index2 = sp.parseQuery(indexSparqlString2, null); + } catch (MalformedQueryException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + List<ExternalTupleSet> index = Lists.newArrayList(); + + SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection)index1.getTupleExpr()); + SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection)index2.getTupleExpr());; + + index.add(ais1); + index.add(ais2); + + ParsedQuery pq = null; + + try { + pq = sp.parseQuery(queryString, null); + } catch (MalformedQueryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + ExternalProcessor processor = new ExternalProcessor(index); + TupleExpr tup = processor.process(pq.getTupleExpr()); + + System.out.println("TupleExpr is " + tup); + + IndexPlanValidator ipv = new IndexPlanValidator(false); + Assert.assertEquals(true, ipv.isValid(tup)); + + } + + + + + + @Test + public void testEvaluateTwoIndexTwoVarOrder3() { + + + System.out.println("********************Test number 3***************************"); + + // TODO Auto-generated method stub + String indexSparqlString = ""// + + "SELECT ?l ?e ?c " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String indexSparqlString2 = ""// + + "SELECT ?e ?o ?l " // + + "{" // + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String queryString = ""// + + "SELECT ?e ?c ?l ?o " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + + SPARQLParser sp = new SPARQLParser(); + ParsedQuery index1 = null; + ParsedQuery index2 = null; + try { + index1 = sp.parseQuery(indexSparqlString, null); + index2 = sp.parseQuery(indexSparqlString2, null); + } catch (MalformedQueryException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + List<ExternalTupleSet> index = Lists.newArrayList(); + + SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection)index1.getTupleExpr()); + SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection)index2.getTupleExpr());; + + index.add(ais1); + index.add(ais2); + + ParsedQuery pq = null; + + try { + pq = sp.parseQuery(queryString, null); + } catch (MalformedQueryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + ExternalProcessor processor = new ExternalProcessor(index); + TupleExpr tup = processor.process(pq.getTupleExpr()); + + System.out.println("TupleExpr is " + tup); + + IndexPlanValidator ipv = new IndexPlanValidator(false); + Assert.assertEquals(true, ipv.isValid(tup)); + + } + + + + @Test + public void testEvaluateTwoIndexTwoVarOrder4() { + + + System.out.println("********************Test number 4***************************"); + + // TODO Auto-generated method stub + String indexSparqlString = ""// + + "SELECT ?e ?c ?l " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String indexSparqlString2 = ""// + + "SELECT ?e ?o ?l " // + + "{" // + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String queryString = ""// + + "SELECT ?e ?c ?l ?o " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + + SPARQLParser sp = new SPARQLParser(); + ParsedQuery index1 = null; + ParsedQuery index2 = null; + try { + index1 = sp.parseQuery(indexSparqlString, null); + index2 = sp.parseQuery(indexSparqlString2, null); + } catch (MalformedQueryException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + List<ExternalTupleSet> index = Lists.newArrayList(); + + SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection)index1.getTupleExpr()); + SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection)index2.getTupleExpr());; + + index.add(ais1); + index.add(ais2); + + ParsedQuery pq = null; + + try { + pq = sp.parseQuery(queryString, null); + } catch (MalformedQueryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + ExternalProcessor processor = new ExternalProcessor(index); + TupleExpr tup = processor.process(pq.getTupleExpr()); + + System.out.println("TupleExpr is " + tup); + + IndexPlanValidator ipv = new IndexPlanValidator(false); + Assert.assertEquals(false, ipv.isValid(tup)); + + } + + + + @Test + public void testEvaluateTwoIndexTwoVarOrder5() { + + System.out.println("********************Test number 5***************************"); + + // TODO Auto-generated method stub + String indexSparqlString = ""// + + "SELECT ?e ?l ?c " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String indexSparqlString2 = ""// + + "SELECT ?l ?o ?e " // + + "{" // + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l ."// + + " ?e <uri:talksTo> ?o . "// + + "}";// + + + String queryString = ""// + + "SELECT ?e ?c ?l ?o " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + + SPARQLParser sp = new SPARQLParser(); + ParsedQuery index1 = null; + ParsedQuery index2 = null; + try { + index1 = sp.parseQuery(indexSparqlString, null); + index2 = sp.parseQuery(indexSparqlString2, null); + } catch (MalformedQueryException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + + List<ExternalTupleSet> index = Lists.newArrayList(); + + SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection)index1.getTupleExpr()); + SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection)index2.getTupleExpr()); + + System.out.println("Supported variable orders are " + ais1.getSupportedVariableOrders() + ", " + ais2.getSupportedVariableOrders()); + + index.add(ais2); + index.add(ais1); + + + ParsedQuery pq = null; + + try { + pq = sp.parseQuery(queryString, null); + } catch (MalformedQueryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + System.out.println("query assured binding names are " + pq.getTupleExpr().getAssuredBindingNames()); + + ExternalProcessor processor = new ExternalProcessor(index); + TupleExpr tup = processor.process(pq.getTupleExpr()); + + System.out.println("TupleExpr is " + tup); + + IndexPlanValidator ipv = new IndexPlanValidator(false); + Assert.assertEquals(false, ipv.isValid(tup)); + + } + + + + + + @Test + public void testEvaluateTwoIndexTwoVarOrder6() { + + + System.out.println("********************Test number 6***************************"); + + // TODO Auto-generated method stub + String indexSparqlString = ""// + + "SELECT ?e ?l ?c " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String indexSparqlString2 = ""// + + "SELECT ?l ?e ?o " // + + "{" // + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String queryString = ""// + + "SELECT ?e ?c ?l ?o " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + + SPARQLParser sp = new SPARQLParser(); + ParsedQuery index1 = null; + ParsedQuery index2 = null; + try { + index1 = sp.parseQuery(indexSparqlString, null); + index2 = sp.parseQuery(indexSparqlString2, null); + } catch (MalformedQueryException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + + List<ExternalTupleSet> index = Lists.newArrayList(); + + SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection)index1.getTupleExpr()); + SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection)index2.getTupleExpr());; + + index.add(ais2); + index.add(ais1); + + + ParsedQuery pq = null; + + try { + pq = sp.parseQuery(queryString, null); + } catch (MalformedQueryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + ExternalProcessor processor = new ExternalProcessor(index); + TupleExpr tup = processor.process(pq.getTupleExpr()); + + System.out.println("TupleExpr is " + tup); + + IndexPlanValidator ipv = new IndexPlanValidator(false); + Assert.assertEquals(true, ipv.isValid(tup)); + + } + + + + + @Test + public void testEvaluateTwoIndexCrossProduct1() { + + System.out.println("********************Test number 7***************************"); + + // TODO Auto-generated method stub + String indexSparqlString = ""// + + "SELECT ?e ?l ?c " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String indexSparqlString2 = ""// + + "SELECT ?e ?l ?o " // + + "{" // + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String queryString = ""// + + "SELECT ?e ?c ?l ?o ?f ?g " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?f <uri:talksTo> ?g . " // + + "}";// + + + + SPARQLParser sp = new SPARQLParser(); + ParsedQuery index1 = null; + ParsedQuery index2 = null; + try { + index1 = sp.parseQuery(indexSparqlString, null); + index2 = sp.parseQuery(indexSparqlString2, null); + } catch (MalformedQueryException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + + List<ExternalTupleSet> index = Lists.newArrayList(); + + SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection)index1.getTupleExpr()); + SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection)index2.getTupleExpr());; + + index.add(ais2); + index.add(ais1); + + + ParsedQuery pq = null; + + try { + pq = sp.parseQuery(queryString, null); + } catch (MalformedQueryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + ExternalProcessor processor = new ExternalProcessor(index); + TupleExpr tup = processor.process(pq.getTupleExpr()); + + System.out.println("TupleExpr is " + tup); + + IndexPlanValidator ipv = new IndexPlanValidator(true); + Assert.assertEquals(false, ipv.isValid(tup)); + + } + + + + + @Test + public void testEvaluateTwoIndexCrossProduct2() { + + System.out.println("********************Test number 8***************************"); + + // TODO Auto-generated method stub + String indexSparqlString = ""// + + "SELECT ?e ?l ?c " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String indexSparqlString2 = ""// + + "SELECT ?e ?l ?o " // + + "{" // + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String queryString = ""// + + "SELECT ?e ?c ?l ?o ?f ?g " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?f <uri:talksTo> ?g . " // + + "}";// + + + + SPARQLParser sp = new SPARQLParser(); + ParsedQuery index1 = null; + ParsedQuery index2 = null; + try { + index1 = sp.parseQuery(indexSparqlString, null); + index2 = sp.parseQuery(indexSparqlString2, null); + } catch (MalformedQueryException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + List<ExternalTupleSet> index = Lists.newArrayList(); + + SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection)index1.getTupleExpr()); + SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection)index2.getTupleExpr());; + + + index.add(ais1); + index.add(ais2); + + + ParsedQuery pq = null; + + try { + pq = sp.parseQuery(queryString, null); + } catch (MalformedQueryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + ExternalProcessor processor = new ExternalProcessor(index); + TupleExpr tup = processor.process(pq.getTupleExpr()); + + System.out.println("TupleExpr is " + tup); + + IndexPlanValidator ipv = new IndexPlanValidator(true); + Assert.assertEquals(false, ipv.isValid(tup)); + + } + + + + @Test + public void testEvaluateTwoIndexCrossProduct3() { + + System.out.println("********************Test number 9***************************"); + + // TODO Auto-generated method stub + String indexSparqlString = ""// + + "SELECT ?e ?l ?c " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String indexSparqlString2 = ""// + + "SELECT ?e ?l ?o " // + + "{" // + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "// + + "}";// + + + String queryString = ""// + + "SELECT ?e ?c ?l ?o ?f ?g " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?f <uri:talksTo> ?g . " // + + "}";// + + + + SPARQLParser sp = new SPARQLParser(); + ParsedQuery index1 = null; + ParsedQuery index2 = null; + try { + index1 = sp.parseQuery(indexSparqlString, null); + index2 = sp.parseQuery(indexSparqlString2, null); + } catch (MalformedQueryException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + List<ExternalTupleSet> index = Lists.newArrayList(); + + SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection)index1.getTupleExpr()); + SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection)index2.getTupleExpr());; + + + index.add(ais1); + index.add(ais2); + + + ParsedQuery pq = null; + + try { + pq = sp.parseQuery(queryString, null); + } catch (MalformedQueryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + ExternalProcessor processor = new ExternalProcessor(index); + TupleExpr tup = processor.process(pq.getTupleExpr()); + + System.out.println("TupleExpr is " + tup); + + IndexPlanValidator ipv = new IndexPlanValidator(false); + Assert.assertEquals(true, ipv.isValid(tup)); + + } + + + + + + + + + @Test + public void testEvaluateTwoIndexDiffVars() { + + System.out.println("********************Test number 10***************************"); + + // TODO Auto-generated method stub + String indexSparqlString = ""// + + "SELECT ?chicken ?dog ?pig " // + + "{" // + + " ?dog a ?chicken . "// + + " ?dog <http://www.w3.org/2000/01/rdf-schema#label> ?pig "// + + "}";// + + + String indexSparqlString2 = ""// + + "SELECT ?fish ?ant ?turkey " // + + "{" // + + " ?fish <uri:talksTo> ?turkey . "// + + " ?turkey <http://www.w3.org/2000/01/rdf-schema#label> ?ant "// + + "}";// + + + String queryString = ""// + + "SELECT ?e ?c ?l ?o ?f ?g " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?f <uri:talksTo> ?g . " // + + "}";// + + + + SPARQLParser sp = new SPARQLParser(); + ParsedQuery index1 = null; + ParsedQuery index2 = null; + try { + index1 = sp.parseQuery(indexSparqlString, null); + index2 = sp.parseQuery(indexSparqlString2, null); + } catch (MalformedQueryException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + List<ExternalTupleSet> index = Lists.newArrayList(); + + SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection)index1.getTupleExpr()); + SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection)index2.getTupleExpr());; + + + index.add(ais1); + index.add(ais2); + + + ParsedQuery pq = null; + + try { + pq = sp.parseQuery(queryString, null); + } catch (MalformedQueryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + ExternalProcessor processor = new ExternalProcessor(index); + TupleExpr tup = processor.process(pq.getTupleExpr()); + + System.out.println("TupleExpr is " + tup); + + IndexPlanValidator ipv = new IndexPlanValidator(false); + Assert.assertEquals(false, ipv.isValid(tup)); + + } + + + + @Test + public void testEvaluateTwoIndexDiffVars2() { + + System.out.println("********************Test number 11***************************"); + + // TODO Auto-generated method stub + String indexSparqlString = ""// + + "SELECT ?dog ?pig ?chicken " // + + "{" // + + " ?dog a ?chicken . "// + + " ?dog <http://www.w3.org/2000/01/rdf-schema#label> ?pig "// + + "}";// + + + String indexSparqlString2 = ""// + + "SELECT ?fish ?ant ?turkey " // + + "{" // + + " ?fish <uri:talksTo> ?turkey . "// + + " ?turkey <http://www.w3.org/2000/01/rdf-schema#label> ?ant "// + + "}";// + + + String queryString = ""// + + "SELECT ?e ?c ?l ?o ?f ?g " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?f <uri:talksTo> ?g . " // + + "}";// + + + + SPARQLParser sp = new SPARQLParser(); + ParsedQuery index1 = null; + ParsedQuery index2 = null; + try { + index1 = sp.parseQuery(indexSparqlString, null); + index2 = sp.parseQuery(indexSparqlString2, null); + } catch (MalformedQueryException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + List<ExternalTupleSet> index = Lists.newArrayList(); + + SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection)index1.getTupleExpr()); + SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection)index2.getTupleExpr());; + + + index.add(ais1); + index.add(ais2); + + + ParsedQuery pq = null; + + try { + pq = sp.parseQuery(queryString, null); + } catch (MalformedQueryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + ExternalProcessor processor = new ExternalProcessor(index); + TupleExpr tup = processor.process(pq.getTupleExpr()); + + System.out.println("TupleExpr is " + tup); + + IndexPlanValidator ipv = new IndexPlanValidator(false); + Assert.assertEquals(true, ipv.isValid(tup)); + + } + + + @Test + public void testEvaluateTwoIndexDiffVars3() { + + System.out.println("********************Test number 11***************************"); + + // TODO Auto-generated method stub + String indexSparqlString = ""// + + "SELECT ?pig ?dog ?chicken " // + + "{" // + + " ?dog a ?chicken . "// + + " ?dog <http://www.w3.org/2000/01/rdf-schema#label> ?pig "// + + "}";// + + + String indexSparqlString2 = ""// + + "SELECT ?fish ?ant ?turkey " // + + "{" // + + " ?fish <uri:talksTo> ?turkey . "// + + " ?turkey <http://www.w3.org/2000/01/rdf-schema#label> ?ant "// + + "}";// + + + String queryString = ""// + + "SELECT ?e ?c ?l ?o ?f ?g " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?f <uri:talksTo> ?g . " // + + "}";// + + + + SPARQLParser sp = new SPARQLParser(); + ParsedQuery index1 = null; + ParsedQuery index2 = null; + try { + index1 = sp.parseQuery(indexSparqlString, null); + index2 = sp.parseQuery(indexSparqlString2, null); + } catch (MalformedQueryException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + List<ExternalTupleSet> index = Lists.newArrayList(); + + SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection)index1.getTupleExpr()); + SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection)index2.getTupleExpr());; + + + index.add(ais1); + index.add(ais2); + + + ParsedQuery pq = null; + + try { + pq = sp.parseQuery(queryString, null); + } catch (MalformedQueryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + ExternalProcessor processor = new ExternalProcessor(index); + TupleExpr tup = processor.process(pq.getTupleExpr()); + + System.out.println("TupleExpr is " + tup); + + IndexPlanValidator ipv = new IndexPlanValidator(false); + Assert.assertEquals(true, ipv.isValid(tup)); + + } + + + + + @Test + public void testEvaluateTwoIndexDiffVarsDirProd() { + + System.out.println("********************Test number 12***************************"); + + // TODO Auto-generated method stub + String indexSparqlString = ""// + + "SELECT ?pig ?dog ?chicken " // + + "{" // + + " ?dog a ?chicken . "// + + " ?dog <http://www.w3.org/2000/01/rdf-schema#label> ?pig "// + + "}";// + + + String indexSparqlString2 = ""// + + "SELECT ?fish ?ant ?turkey " // + + "{" // + + " ?fish <uri:talksTo> ?turkey . "// + + " ?turkey <http://www.w3.org/2000/01/rdf-schema#label> ?ant "// + + "}";// + + + String queryString = ""// + + "SELECT ?e ?c ?l ?o ?f ?g " // + + "{" // + + " ?e a ?c . "// + + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?e <uri:talksTo> ?o . "// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + + " ?f <uri:talksTo> ?g . " // + + "}";// + + + + SPARQLParser sp = new SPARQLParser(); + ParsedQuery index1 = null; + ParsedQuery index2 = null; + try { + index1 = sp.parseQuery(indexSparqlString, null); + index2 = sp.parseQuery(indexSparqlString2, null); + } catch (MalformedQueryException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + List<ExternalTupleSet> index = Lists.newArrayList(); + + SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection)index1.getTupleExpr()); + SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection)index2.getTupleExpr());; + + + index.add(ais1); + index.add(ais2); + + + ParsedQuery pq = null; + + try { + pq = sp.parseQuery(queryString, null); + } catch (MalformedQueryException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + ExternalProcessor processor = new ExternalProcessor(index); + TupleExpr tup = processor.process(pq.getTupleExpr()); + + System.out.println("TupleExpr is " + tup); + + IndexPlanValidator ipv = new IndexPlanValidator(true); + Assert.assertEquals(false, ipv.isValid(tup)); + + } + + + + @Test + public void testValidTupleIterator() throws Exception { + + System.out.println("********************Test number 13***************************"); + + String q1 = ""// + + "SELECT ?f ?m ?d ?h ?i " // + + "{" // + + " ?f a ?m ."// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?d <uri:talksTo> ?f . "// + + " ?d <uri:hangOutWith> ?f ." // + + " ?f <uri:hangOutWith> ?h ." // + + " ?f <uri:associatesWith> ?i ." // + + " ?i <uri:associatesWith> ?h ." // + + "}";// + + String q2 = ""// + + "SELECT ?t ?s ?u " // + + "{" // + + " ?s a ?t ."// + + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// + + " ?u <uri:talksTo> ?s . "// + + "}";// + + + String q3 = ""// + + "SELECT ?s ?t ?u " // + + "{" // + + " ?s <uri:hangOutWith> ?t ." // + + " ?t <uri:hangOutWith> ?u ." // + + "}";// + + String q4 = ""// + + "SELECT ?s ?t ?u " // + + "{" // + + " ?s <uri:associatesWith> ?t ." // + + " ?t <uri:associatesWith> ?u ." // + + "}";// + + + + + + + SPARQLParser parser = new SPARQLParser(); + + ParsedQuery pq1 = parser.parseQuery(q1, null); + ParsedQuery pq2 = parser.parseQuery(q2, null); + ParsedQuery pq3 = parser.parseQuery(q3, null); + ParsedQuery pq4 = parser.parseQuery(q4, null); + + + SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr()); + SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr()); + SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr()); + + List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); + + list.add(extTup2); + list.add(extTup1); + list.add(extTup3); + + IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list); + + Iterator<TupleExpr> plans = (new TupleExecutionPlanGenerator()).getPlans(iep.getIndexedTuples()); + IndexPlanValidator ipv = new IndexPlanValidator(true); + Iterator<TupleExpr> validPlans = ipv.getValidTuples(plans); + + int size = 0; + + while(validPlans.hasNext()) { + Assert.assertTrue(validPlans.hasNext()); + validPlans.next(); + size++; + } + + Assert.assertTrue(!validPlans.hasNext()); + Assert.assertEquals(732, size); + + + + } + + + + + + + + + + + + + +}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/IndexedExecutionPlanGeneratorTest.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/IndexedExecutionPlanGeneratorTest.java b/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/IndexedExecutionPlanGeneratorTest.java new file mode 100644 index 0000000..ead7330 --- /dev/null +++ b/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/IndexedExecutionPlanGeneratorTest.java @@ -0,0 +1,403 @@ +package mvm.rya.indexing.IndexPlanValidator; + + + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Set; +import junit.framework.Assert; +import mvm.rya.indexing.external.ExternalProcessor; +import mvm.rya.indexing.external.tupleSet.ExternalTupleSet; +import mvm.rya.indexing.external.tupleSet.SimpleExternalTupleSet; + +import org.junit.Test; +import org.openrdf.query.algebra.Projection; +import org.openrdf.query.algebra.TupleExpr; +import org.openrdf.query.parser.ParsedQuery; +import org.openrdf.query.parser.sparql.SPARQLParser; + +import com.google.common.collect.Lists; + +public class IndexedExecutionPlanGeneratorTest { + + private String q7 = ""// + + "SELECT ?s ?t ?u " // + + "{" // + + " ?s a ?t ."// + + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// + + " ?u <uri:talksTo> ?s . "// + + "}";// + + + + private String q12 = ""// + + "SELECT ?b ?p ?dog ?cat " // + + "{" // + + " ?b a ?p ."// + + " ?dog a ?cat. "// + + "}";// + + private String q15 = ""// + + "SELECT ?f ?m ?d ?e ?l ?c " // + + "{" // + + " ?f a ?m ."// + + " ?e a ?l ."// + + " ?d <uri:talksTo> ?f . "// + + " ?c <uri:talksTo> ?e . "// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// + + "}";// + + private String q16 = ""// + + "SELECT ?f ?m ?d ?e ?l ?c " // + + "{" // + + " ?l <uri:talksTo> ?c . "// + + " ?d <uri:talksTo> ?f . "// + + " ?c <uri:talksTo> ?e . "// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// + + "}";// + + private String q17 = ""// + + "SELECT ?dog ?cat ?chicken " // + + "{" // + + " ?chicken <uri:talksTo> ?dog . "// + + " ?cat <http://www.w3.org/2000/01/rdf-schema#label> ?chicken ."// + + "}";// + + private String q18 = ""// + + "SELECT ?cat ?chicken ?pig ?duck " // + + "{" // + + " ?cat <uri:talksTo> ?chicken. "// + + " ?pig <uri:talksTo> ?duck . "// + + "}";// + + + + private String q19 = ""// + + "SELECT ?f ?m ?d ?e ?l ?c " // + + "{" // + + " ?f <uri:talksTo> ?m . "// + + " ?d <uri:talksTo> ?e . "// + + " ?l <uri:talksTo> ?c . "// + + "}";// + + private String q20 = ""// + + "SELECT ?f ?m " // + + "{" // + + " ?f <uri:talksTo> ?m . "// + + "}";// + + + private String q21 = ""// + + "SELECT ?s ?t ?u " // + + "{" // + + " Filter(?s > 3). " // + + " ?s a ?t ."// + + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// + + " ?u <uri:talksTo> ?s . "// + + "}";// + + + + private String q22 = ""// + + "SELECT ?f ?m ?d ?e ?l ?c " // + + "{" // + + " Filter(?f > 3) ."// + + " Filter(?e > 3) ."// + + " ?e a ?f ." // + + " ?f a ?m ."// + + " ?e a ?l ."// + + " ?d <uri:talksTo> ?f . "// + + " ?c <uri:talksTo> ?e . "// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// + + "}";// + + + private String q23 = ""// + + "SELECT ?h ?i ?j " // + + "{" // + + " Filter(?h > 3) ."// + + " Filter(?i > 3) ."// + + " ?h a ?i ." // + + " ?h a ?j ."// + + "}";// + + + + + + + @Test + public void testTwoIndexLargeQuery() throws Exception { + + SPARQLParser parser = new SPARQLParser(); + + ParsedQuery pq1 = parser.parseQuery(q15, null); + ParsedQuery pq2 = parser.parseQuery(q7, null); + ParsedQuery pq3 = parser.parseQuery(q12, null); + + SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr()); + SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr()); + + List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); + + list.add(extTup2); + list.add(extTup1); + + IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list); + List<ExternalTupleSet> indexSet = iep.getNormalizedIndices(); + Assert.assertEquals(4, indexSet.size()); + + Iterator<TupleExpr> processedTups = iep.getIndexedTuples(); + + int size = 0; + + while (processedTups.hasNext()) { + Assert.assertTrue(processedTups.hasNext()); + processedTups.next(); + size++; + } + + Assert.assertTrue(!processedTups.hasNext()); + + Assert.assertEquals(5, size); + + } + + + + + + @Test + public void testThreeSingleNodeIndex() throws Exception { + + SPARQLParser parser = new SPARQLParser(); + + ParsedQuery pq1 = parser.parseQuery(q19, null); + ParsedQuery pq2 = parser.parseQuery(q20, null); + + SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr()); + + List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); + + list.add(extTup1); + + IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list); + List<ExternalTupleSet> indexSet = iep.getNormalizedIndices(); + Assert.assertEquals(3, indexSet.size()); + + Iterator<TupleExpr> processedTups = iep.getIndexedTuples(); + + int size = 0; + + while(processedTups.hasNext()) { + Assert.assertTrue(processedTups.hasNext()); + processedTups.next(); + size++; + } + Assert.assertTrue(!processedTups.hasNext()); + + Assert.assertEquals(3, size); + + } + + + + @Test + public void testThreeIndexQuery() throws Exception { + + SPARQLParser parser = new SPARQLParser(); + + + ParsedQuery pq1 = parser.parseQuery(q16, null); + ParsedQuery pq2 = parser.parseQuery(q17, null); + ParsedQuery pq3 = parser.parseQuery(q18, null); + + + SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr()); + SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr()); + + List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); + + list.add(extTup2); + list.add(extTup1); + + + IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(),list); + List<ExternalTupleSet> indexSet = iep.getNormalizedIndices(); + Assert.assertEquals(6, indexSet.size()); + + Iterator<TupleExpr> processedTups = iep.getIndexedTuples(); + + int size = 0; + + while(processedTups.hasNext()) { + Assert.assertTrue(processedTups.hasNext()); + processedTups.next(); + size++; + } + + Assert.assertTrue(!processedTups.hasNext()); + Assert.assertEquals(9, size); + + + } + + + + + @Test + public void testThrowsException1() throws Exception { + + SPARQLParser parser = new SPARQLParser(); + + + ParsedQuery pq1 = parser.parseQuery(q16, null); + ParsedQuery pq2 = parser.parseQuery(q17, null); + ParsedQuery pq3 = parser.parseQuery(q18, null); + + + SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr()); + SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr()); + + List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); + + list.add(extTup2); + list.add(extTup1); + + + IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(),list); + List<ExternalTupleSet> indexSet = iep.getNormalizedIndices(); + Assert.assertEquals(6, indexSet.size()); + + Iterator<TupleExpr> processedTups = iep.getIndexedTuples(); + + + boolean exceptionThrown = false; + + try{ + processedTups.remove(); + } catch(UnsupportedOperationException e) { + exceptionThrown = true; + } + + Assert.assertTrue(exceptionThrown); + + + } + + + @Test + public void testThrowsException2() throws Exception { + + SPARQLParser parser = new SPARQLParser(); + + ParsedQuery pq1 = parser.parseQuery(q19, null); + ParsedQuery pq2 = parser.parseQuery(q20, null); + + SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr()); + + List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); + + list.add(extTup1); + + IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list); + List<ExternalTupleSet> indexSet = iep.getNormalizedIndices(); + Assert.assertEquals(3, indexSet.size()); + + Iterator<TupleExpr> processedTups = iep.getIndexedTuples(); + + int size = 0; + + processedTups.next(); + processedTups.next(); + processedTups.next(); + + boolean exceptionThrown = false; + try { + processedTups.next(); + } catch (NoSuchElementException e) { + exceptionThrown = true; + } + + Assert.assertTrue(exceptionThrown); + + } + + + + + + @Test + public void testThreeIndexQueryFilter() throws Exception { + + SPARQLParser parser = new SPARQLParser(); + + + ParsedQuery pq1 = parser.parseQuery(q22, null); + ParsedQuery pq2 = parser.parseQuery(q7, null); + ParsedQuery pq3 = parser.parseQuery(q21, null); + ParsedQuery pq4 = parser.parseQuery(q23, null); + + + SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr()); + SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr()); + SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr()); + + List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); + + list.add(extTup2); + list.add(extTup1); + list.add(extTup3); + + + IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(),list); + List<ExternalTupleSet> indexSet = iep.getNormalizedIndices(); + Assert.assertEquals(5, indexSet.size()); + + Iterator<TupleExpr> processedTups = iep.getIndexedTuples(); + + + int size = 0; + + while(processedTups.hasNext()) { + Assert.assertTrue(processedTups.hasNext()); + TupleExpr te = processedTups.next(); + System.out.println(te); + size++; + } + + Assert.assertTrue(!processedTups.hasNext()); + Assert.assertEquals(10, size); + + + } + + + + + + + + + + + + + + + + + + + + + + + + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/ThreshholdPlanSelectorTest.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/ThreshholdPlanSelectorTest.java b/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/ThreshholdPlanSelectorTest.java new file mode 100644 index 0000000..3292fed --- /dev/null +++ b/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/ThreshholdPlanSelectorTest.java @@ -0,0 +1,818 @@ +package mvm.rya.indexing.IndexPlanValidator; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import junit.framework.Assert; +import mvm.rya.indexing.external.ExternalProcessor; +import mvm.rya.indexing.external.tupleSet.ExternalTupleSet; +import mvm.rya.indexing.external.tupleSet.SimpleExternalTupleSet; + +import org.junit.Test; +import org.openrdf.query.algebra.Filter; +import org.openrdf.query.algebra.Projection; +import org.openrdf.query.algebra.QueryModelNode; +import org.openrdf.query.algebra.StatementPattern; +import org.openrdf.query.algebra.TupleExpr; +import org.openrdf.query.algebra.helpers.QueryModelVisitorBase; +import org.openrdf.query.algebra.helpers.StatementPatternCollector; +import org.openrdf.query.parser.ParsedQuery; +import org.openrdf.query.parser.sparql.SPARQLParser; + +import com.beust.jcommander.internal.Lists; +import com.google.common.collect.Sets; + +public class ThreshholdPlanSelectorTest { + + private String q7 = ""// + + "SELECT ?s ?t ?u " // + + "{" // + + " ?s a ?t ."// + + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// + + " ?u <uri:talksTo> ?s . "// + + "}";// + + private String q8 = ""// + + "SELECT ?e ?l ?c " // + + "{" // + + " ?e a ?l ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// + + " ?c <uri:talksTo> ?e . "// + + "}";// + + private String q9 = ""// + + "SELECT ?f ?m ?d " // + + "{" // + + " ?f a ?m ."// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?d <uri:talksTo> ?f . "// + + "}";// + + + + + private String q15 = ""// + + "SELECT ?f ?m ?d ?e ?l ?c " // + + "{" // + + " ?f a ?m ."// + + " ?e a ?l ."// + + " ?d <uri:talksTo> ?f . "// + + " ?c <uri:talksTo> ?e . "// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// + + "}";// + + private String q16 = ""// + + "SELECT ?f ?m ?d ?e ?l " // + + "{" // + + " ?d <uri:talksTo> ?f . "// + + " ?d <uri:talksTo> ?e . "// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + "}";// + + private String q17 = ""// + + "SELECT ?chicken ?dog ?cat " // + + "{" // + + " ?chicken <uri:talksTo> ?dog . "// + + " ?cat <http://www.w3.org/2000/01/rdf-schema#label> ?chicken ."// + + "}";// + + private String q18 = ""// + + "SELECT ?dog ?chicken " // + + "{" // + + " ?chicken <uri:talksTo> ?dog . "// + + "}";// + + private String q19 = ""// + + "SELECT ?cat ?chicken " // + + "{" // + + " ?cat <http://www.w3.org/2000/01/rdf-schema#label> ?chicken ."// + + "}";// + + + private String q20 = ""// + + "SELECT ?f ?m ?d ?e ?l ?c " // + + "{" // + + " ?f a ?m ."// + + " ?e a ?l ."// + + " ?d <uri:talksTo> ?f . "// + + " ?c <uri:talksTo> ?e . "// + + " ?m <uri:talksTo> ?e . "// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// + + "}";// + + + + private String q21 = ""// + + "SELECT ?u ?s ?t " // + + "{" // + + " ?s a ?t ."// + + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// + + " ?u <uri:talksTo> ?s . "// + + "}";// + + + + @Test + public void testSingleIndex() throws Exception { + + SPARQLParser parser = new SPARQLParser(); + + + ParsedQuery pq1 = parser.parseQuery(q15, null); + ParsedQuery pq2 = parser.parseQuery(q7, null); + ParsedQuery pq3 = parser.parseQuery(q8, null); + ParsedQuery pq4 = parser.parseQuery(q9, null); + //ParsedQuery pq3 = parser.parseQuery(q12, null); + + SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr()); + SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr()); + SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr()); + + List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); + + list.add(extTup1); + + List<QueryModelNode> optTupNodes = Lists.newArrayList(); + optTupNodes.add(extTup2); + optTupNodes.add(extTup3); + + 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, .1, 1, 0, 0); + + NodeCollector nc = new NodeCollector(); + optimalTup.visit(nc); + + List<QueryModelNode> qNodes = nc.getNodes(); + + + Assert.assertEquals(qNodes.size(), optTupNodes.size()); + for(QueryModelNode node: qNodes) { + Assert.assertTrue(optTupNodes.contains(node)); + } + + + } + + + + + + @Test + public void testSingleIndex2() throws Exception { + + String q1 = ""// + + "SELECT ?f ?m ?d ?e ?l ?c " // + + "{" // + + " ?f a ?m ."// + + " ?c a ?l ."// + + " ?d <uri:talksTo> ?f . "// + + " ?e <uri:talksTo> ?c . "// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?e ."// + + " ?m <uri:talksTo> ?e . "// + + "}";// + + String q2 = ""// + + "SELECT ?u ?s ?t " // + + "{" // + + " ?s a ?t ."// + + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// + + " ?u <uri:talksTo> ?s . "// + + "}";// + + String q3 = ""// + + "SELECT ?e ?c ?l " // + + "{" // + + " ?c a ?l ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?e ."// + + " ?e <uri:talksTo> ?c . "// + + "}";// + + String q4 = ""// + + "SELECT ?d ?f ?m " // + + "{" // + + " ?f a ?m ."// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?d <uri:talksTo> ?f . "// + + "}";// + + SPARQLParser parser = new SPARQLParser(); + + ParsedQuery pq1 = parser.parseQuery(q1, null); + ParsedQuery pq2 = parser.parseQuery(q2, null); + ParsedQuery pq3 = parser.parseQuery(q3, null); + ParsedQuery pq4 = parser.parseQuery(q4, null); + + SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr()); + SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr()); + SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr()); + + List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); + + list.add(extTup1); + + List<StatementPattern> spList = StatementPatternCollector.process(pq1.getTupleExpr()); + List<QueryModelNode> optTupNodes = Lists.newArrayList(); + optTupNodes.add(extTup3); + optTupNodes.add(spList.get(6)); + optTupNodes.add(extTup2); + + IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list); + + Iterator<TupleExpr> plans = (new TupleExecutionPlanGenerator()).getPlans(iep.getIndexedTuples()); + + //System.out.println("Size is " + plans.size()); + // System.out.println("Plans are " + plans); + + IndexPlanValidator ipv = new IndexPlanValidator(true); + Iterator<TupleExpr> validPlans = ipv.getValidTuples(plans); + + //System.out.println("Valid plan size is " + validPlans.size()); + // System.out.println("Valid plans are " + validPlans); + + ThreshholdPlanSelector tps = new ThreshholdPlanSelector(pq1.getTupleExpr()); + + TupleExpr optimalTup = tps.getThreshholdQueryPlan(validPlans, .4, .7, .1, .2); + + NodeCollector nc = new NodeCollector(); + optimalTup.visit(nc); + + //System.out.println("Optimal plan is " + optimalTup); + + List<QueryModelNode> qNodes = nc.getNodes(); + //System.out.println("Returned list is " + qNodes + " and comp list is " + optTupNodes); + + Assert.assertTrue(qNodes.equals(optTupNodes)); + + } + + + + + + + + + @Test + public void testTwoIndex() throws Exception { + + String q1 = ""// + + "SELECT ?f ?m ?d ?h ?i " // + + "{" // + + " ?f a ?m ."// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?d <uri:talksTo> ?f . "// + + " ?d <uri:hangOutWith> ?f ." // + + " ?f <uri:hangOutWith> ?h ." // + + " ?f <uri:associatesWith> ?i ." // + + " ?i <uri:associatesWith> ?h ." // + + "}";// + + String q2 = ""// + + "SELECT ?t ?s ?u " // + + "{" // + + " ?s a ?t ."// + + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// + + " ?u <uri:talksTo> ?s . "// + + "}";// + + + String q3 = ""// + + "SELECT ?s ?t ?u " // + + "{" // + + " ?s <uri:hangOutWith> ?t ." // + + " ?t <uri:hangOutWith> ?u ." // + + "}";// + + String q4 = ""// + + "SELECT ?s ?t ?u " // + + "{" // + + " ?s <uri:associatesWith> ?t ." // + + " ?t <uri:associatesWith> ?u ." // + + "}";// + + + + String q5 = ""// + + "SELECT ?m ?f ?d " // + + "{" // + + " ?f a ?m ."// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?d <uri:talksTo> ?f . "// + + "}";// + + + String q6 = ""// + + "SELECT ?d ?f ?h " // + + "{" // + + " ?d <uri:hangOutWith> ?f ." // + + " ?f <uri:hangOutWith> ?h ." // + + "}";// + + String q7 = ""// + + "SELECT ?f ?i ?h " // + + "{" // + + " ?f <uri:associatesWith> ?i ." // + + " ?i <uri:associatesWith> ?h ." // + + "}";// + + + + + + + SPARQLParser parser = new SPARQLParser(); + + ParsedQuery pq1 = parser.parseQuery(q1, null); + ParsedQuery pq2 = parser.parseQuery(q2, null); + ParsedQuery pq3 = parser.parseQuery(q3, null); + ParsedQuery pq4 = parser.parseQuery(q4, null); + ParsedQuery pq5 = parser.parseQuery(q5, null); + ParsedQuery pq6 = parser.parseQuery(q6, null); + ParsedQuery pq7 = parser.parseQuery(q7, null); + + 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()); + SimpleExternalTupleSet extTup5 = new SimpleExternalTupleSet((Projection) pq6.getTupleExpr()); + SimpleExternalTupleSet extTup6 = new SimpleExternalTupleSet((Projection) pq7.getTupleExpr()); + + + + + List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); + + list.add(extTup2); + list.add(extTup1); + list.add(extTup3); + + List<QueryModelNode> optTupNodes = Lists.newArrayList(); + optTupNodes.add(extTup4); + optTupNodes.add(extTup6); + optTupNodes.add(extTup5); + + IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list); + + Iterator<TupleExpr> plans = (new TupleExecutionPlanGenerator()).getPlans(iep.getIndexedTuples()); + IndexPlanValidator ipv = new IndexPlanValidator(true); + Iterator<TupleExpr> validPlans = ipv.getValidTuples(plans); + + ThreshholdPlanSelector tps = new ThreshholdPlanSelector(pq1.getTupleExpr()); + TupleExpr optimalTup = tps.getThreshholdQueryPlan(validPlans, .2, .6, .4, 0); + + NodeCollector nc = new NodeCollector(); + optimalTup.visit(nc); + + List<QueryModelNode> qNodes = nc.getNodes(); + + Assert.assertTrue(qNodes.equals(optTupNodes)); + + } + + + + + @Test + public void largeQueryFourtyIndexTest() { + + + String q1 = ""// + + "SELECT ?f ?m ?d ?e ?l ?c ?n ?o ?p ?a ?h ?r " // + + "{" // + + " ?f a ?m ."// + + " ?e a ?l ."// + + " ?n a ?o ."// + + " ?a a ?h ."// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ."// + + " ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ."// + + " ?d <uri:talksTo> ?f . "// + + " ?c <uri:talksTo> ?e . "// + + " ?p <uri:talksTo> ?n . "// + + " ?r <uri:talksTo> ?a . "// + + "}";// + + + String q2 = ""// + + "SELECT ?s ?t ?u " // + + "{" // + + " ?s a ?t ."// + + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// + + " ?u <uri:talksTo> ?s . "// + + "}";// + + + + String q3 = ""// + + "SELECT ?s ?t ?u ?d ?f ?g " // + + "{" // + + " ?s a ?t ."// + + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// + + " ?u <uri:talksTo> ?s . "// + + " ?d a ?f ."// + + " ?f <http://www.w3.org/2000/01/rdf-schema#label> ?g ."// + + " ?g <uri:talksTo> ?d . "// + + "}";// + + + + String q4 = ""// + + "SELECT ?s ?t ?u ?d ?f ?g ?a ?b ?c" // + + "{" // + + " ?s a ?t ."// + + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// + + " ?u <uri:talksTo> ?s . "// + + " ?d a ?f ."// + + " ?f <http://www.w3.org/2000/01/rdf-schema#label> ?g ."// + + " ?g <uri:talksTo> ?d . "// + + " ?a a ?b ."// + + " ?b <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// + + " ?c <uri:talksTo> ?a . "// + + "}";// + + + String q5 = ""// + + "SELECT ?f ?m ?d ?a ?h ?r " // + + "{" // + + " ?f a ?m ."// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?d <uri:talksTo> ?f . "// + + " ?a a ?h ."// + + " ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ."// + + " ?r <uri:talksTo> ?a . "// + + "}";// + + String q6 = ""// + + "SELECT ?e ?l ?c " // + + "{" // + + " ?e a ?l ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// + + " ?c <uri:talksTo> ?e . "// + + "}";// + + String q7 = ""// + + "SELECT ?n ?o ?p " // + + "{" // + + " ?n a ?o ."// + + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ."// + + " ?p <uri:talksTo> ?n . "// + + "}";// + + + + + + SPARQLParser parser = new SPARQLParser(); + + ParsedQuery pq1 = null; + ParsedQuery pq2 = null; + ParsedQuery pq3 = null; + ParsedQuery pq4 = null; + ParsedQuery pq5 = null; + ParsedQuery pq6 = null; + ParsedQuery pq7 = 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); + pq6 = parser.parseQuery(q6, null); + pq7 = parser.parseQuery(q7, 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()); + SimpleExternalTupleSet extTup5 = new SimpleExternalTupleSet((Projection) pq6.getTupleExpr()); + SimpleExternalTupleSet extTup6 = new SimpleExternalTupleSet((Projection) pq7.getTupleExpr()); + + List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>(); + + list.add(extTup2); + list.add(extTup1); + list.add(extTup3); + + List<ExternalTupleSet> list2 = new ArrayList<ExternalTupleSet>(); + + list2.add(extTup4); + list2.add(extTup5); + list2.add(extTup6); + + 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); + + + + } + + + + + + + + + @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://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// + + "}";// + + + String q2 = ""// + + "SELECT ?s ?t ?u " // + + "{" // + + " ?s a ?t ."// + + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// + + " ?u <uri:talksTo> ?s . "// + + "}";// + + + String q3 = ""// + + "SELECT ?s ?t ?u " // + + "{" // + + " Filter(?s > \"5\") ."// + + " ?s a ?t ."// + + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// + + " ?u <uri:talksTo> ?s . "// + + "}";// + + + + String q4 = ""// + + "SELECT ?f ?m ?d " // + + "{" // + + " Filter(?f > \"5\") ."// + + " ?f a ?m ."// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?d <uri:talksTo> ?f . "// + + "}";// + + + String q5 = ""// + + "SELECT ?e ?l ?c " // + + "{" // + + " Filter(?e > \"5\") ."// + + " ?e a ?l ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// + + " ?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((ExternalTupleSet)e)); + } + + + + } + + + + + + + + + + @Test + public void testCost1() throws Exception { + + String q1 = ""// + + "SELECT ?f ?m ?d ?h ?i " // + + "{" // + + " ?f a ?m ."// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?d <uri:talksTo> ?f . "// + + " ?d <uri:hangOutWith> ?f ." // + + " ?f <uri:hangOutWith> ?h ." // + + " ?f <uri:associatesWith> ?i ." // + + " ?i <uri:associatesWith> ?h ." // + + "}";// + + + SPARQLParser parser = new SPARQLParser(); + + ParsedQuery pq1 = parser.parseQuery(q1, null); + + ThreshholdPlanSelector tps = new ThreshholdPlanSelector(pq1.getTupleExpr()); + double cost = tps.getCost(pq1.getTupleExpr(), .6, .4, 0); + Assert.assertEquals(.7,cost); + + } + + + + + @Test + public void testCost2() throws Exception { + + String q1 = ""// + + "SELECT ?f ?m ?d ?e ?l ?c " // + + "{" // + + " ?f a ?m ."// + + " ?e a ?l ."// + + " ?d <uri:talksTo> ?f . "// + + " ?c <uri:talksTo> ?e . "// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// + + "}";// + + + SPARQLParser parser = new SPARQLParser(); + + ParsedQuery pq1 = parser.parseQuery(q1, null); + + ThreshholdPlanSelector tps = new ThreshholdPlanSelector(pq1.getTupleExpr()); + double cost = tps.getCost(pq1.getTupleExpr(), .4, .3, .3); + Assert.assertEquals(.58,cost, .000000001); + + } + + + + + + @Test + public void testCost3() throws Exception { + + String q1 = ""// + + "SELECT ?f ?m ?d ?e ?l ?c " // + + "{" // + + " Filter(?f > \"5\")." // + + " Filter(?e > \"6\")." // + + " ?f a ?m ."// + + " ?e a ?l ."// + + " ?d <uri:talksTo> ?f . "// + + " ?c <uri:talksTo> ?e . "// + + " ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ."// + + " ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ."// + + "}";// + + + String q2 = ""// + + "SELECT ?s ?t ?u " // + + "{" // + + " ?s a ?t ."// + + " ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ."// + + " ?u <uri:talksTo> ?s . "// + + "}";// + + + SPARQLParser parser = new SPARQLParser(); + + ParsedQuery pq1 = parser.parseQuery(q1, null); + ParsedQuery pq2 = parser.parseQuery(q2, null); + + SimpleExternalTupleSet sep = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr()); + List<ExternalTupleSet> eList = Lists.newArrayList(); + + eList.add(sep); + ExternalProcessor ep = new ExternalProcessor(eList); + + TupleExpr te = pq1.getTupleExpr(); + te = ep.process(te); + + + + ThreshholdPlanSelector tps = new ThreshholdPlanSelector(pq1.getTupleExpr()); + double cost = tps.getCost(te, .4, .3, .3); + Assert.assertEquals(.575,cost); + + + } + + + + + + + + + + public static class NodeCollector extends QueryModelVisitorBase<RuntimeException> { + + List<QueryModelNode> qNodes = Lists.newArrayList(); + + + public List<QueryModelNode> getNodes() { + return qNodes; + } + + + + @Override + public void meetNode(QueryModelNode node) { + if(node instanceof StatementPattern || node instanceof ExternalTupleSet) { + qNodes.add(node); + } + super.meetNode(node); + + } + + + } + + + + + + +}
