IndexPlanValidator implements TupleValidator { @Override public boolean isValid(TupleExpr te) { TupleValidateVisitor tv = new TupleValidateVisitor(); te.visit(tv); return tv.isValid(); } IndexPlanValidator(boolean omitCrossProd); void setOmitCrossProd(boolean omitCrossProd); @Override boolean isValid(TupleExpr te); int getValidTupleSize(Iterator<TupleExpr> iter); @Override Iterator<TupleExpr> getValidTuples(Iterator<TupleExpr> tupleIter);  }
@Test public void testEvaluateTwoIndexTwoVarOrder1() throws Exception { final String indexSparqlString = "" + "SELECT ?c ?e ?l " + "{" + " ?e a ?c . " + " ?e <http: + "}"; final String indexSparqlString2 = "" + "SELECT ?e ?o ?l " + "{" + " ?e <uri:talksTo> ?o . " + " ?o <http: + "}"; final String queryString = "" + "SELECT ?e ?c ?l ?o " + "{" + " ?e a ?c . " + " ?e <http: + " ?e <uri:talksTo> ?o . " + " ?o <http: + "}"; final SPARQLParser sp = new SPARQLParser(); final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null); final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null); final List<ExternalTupleSet> index = Lists.newArrayList(); final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet( (Projection) index1.getTupleExpr()); final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet( (Projection) index2.getTupleExpr()); index.add(ais1); index.add(ais2); final ParsedQuery pq = sp.parseQuery(queryString, null); final TupleExpr tup = pq.getTupleExpr().clone(); provider.setIndices(index); final PCJOptimizer pcj = new PCJOptimizer(index, false, provider); pcj.optimize(tup, null, null); final IndexPlanValidator ipv = new IndexPlanValidator(false); Assert.assertEquals(false, ipv.isValid(tup)); }
@Test public void testEvaluateTwoIndexTwoVarOrder2() throws Exception { final String indexSparqlString = "" + "SELECT ?e ?l ?c " + "{" + " ?e a ?c . " + " ?e <http: + "}"; final String indexSparqlString2 = "" + "SELECT ?e ?o ?l " + "{" + " ?e <uri:talksTo> ?o . " + " ?o <http: + "}"; final String queryString = "" + "SELECT ?e ?c ?l ?o " + "{" + " ?e a ?c . " + " ?e <http: + " ?e <uri:talksTo> ?o . " + " ?o <http: + "}"; final SPARQLParser sp = new SPARQLParser(); final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null); final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null); final List<ExternalTupleSet> index = Lists.newArrayList(); final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet( (Projection) index1.getTupleExpr()); final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet( (Projection) index2.getTupleExpr()); index.add(ais1); index.add(ais2); final ParsedQuery pq = sp.parseQuery(queryString, null); final TupleExpr tup = pq.getTupleExpr().clone(); provider.setIndices(index); final PCJOptimizer pcj = new PCJOptimizer(index, false, provider); pcj.optimize(tup, null, null); final IndexPlanValidator ipv = new IndexPlanValidator(false); Assert.assertEquals(true, ipv.isValid(tup)); }
@Test public void testEvaluateTwoIndexTwoVarOrder3() throws Exception { final String indexSparqlString = "" + "SELECT ?l ?e ?c " + "{" + " ?e a ?c . " + " ?e <http: + "}"; final String indexSparqlString2 = "" + "SELECT ?e ?o ?l " + "{" + " ?e <uri:talksTo> ?o . " + " ?o <http: + "}"; final String queryString = "" + "SELECT ?e ?c ?l ?o " + "{" + " ?e a ?c . " + " ?e <http: + " ?e <uri:talksTo> ?o . " + " ?o <http: + "}"; final SPARQLParser sp = new SPARQLParser(); final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null); final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null); final List<ExternalTupleSet> index = Lists.newArrayList(); final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet( (Projection) index1.getTupleExpr()); final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet( (Projection) index2.getTupleExpr()); index.add(ais1); index.add(ais2); final ParsedQuery pq = sp.parseQuery(queryString, null); final TupleExpr tup = pq.getTupleExpr().clone(); provider.setIndices(index); final PCJOptimizer pcj = new PCJOptimizer(index, false, provider); pcj.optimize(tup, null, null); final IndexPlanValidator ipv = new IndexPlanValidator(false); Assert.assertEquals(true, ipv.isValid(tup)); }
@Test public void testEvaluateTwoIndexTwoVarOrder4() throws Exception { final String indexSparqlString = "" + "SELECT ?e ?c ?l " + "{" + " ?e a ?c . " + " ?e <http: + "}"; final String indexSparqlString2 = "" + "SELECT ?e ?o ?l " + "{" + " ?e <uri:talksTo> ?o . " + " ?o <http: + "}"; final String queryString = "" + "SELECT ?e ?c ?l ?o " + "{" + " ?e a ?c . " + " ?e <http: + " ?e <uri:talksTo> ?o . " + " ?o <http: + "}"; final SPARQLParser sp = new SPARQLParser(); final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null); final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null); final List<ExternalTupleSet> index = Lists.newArrayList(); final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet( (Projection) index1.getTupleExpr()); final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet( (Projection) index2.getTupleExpr()); index.add(ais1); index.add(ais2); final ParsedQuery pq = sp.parseQuery(queryString, null); final TupleExpr tup = pq.getTupleExpr().clone(); provider.setIndices(index); final PCJOptimizer pcj = new PCJOptimizer(index, false, provider); pcj.optimize(tup, null, null); final IndexPlanValidator ipv = new IndexPlanValidator(false); Assert.assertEquals(false, ipv.isValid(tup)); }
@Test public void testEvaluateTwoIndexTwoVarOrder6() throws Exception { final String indexSparqlString = "" + "SELECT ?e ?l ?c " + "{" + " ?e a ?c . " + " ?e <http: + "}"; final String indexSparqlString2 = "" + "SELECT ?l ?e ?o " + "{" + " ?e <uri:talksTo> ?o . " + " ?o <http: + "}"; final String queryString = "" + "SELECT ?e ?c ?l ?o " + "{" + " ?e a ?c . " + " ?e <http: + " ?e <uri:talksTo> ?o . " + " ?o <http: + "}"; final SPARQLParser sp = new SPARQLParser(); final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null); final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null); final List<ExternalTupleSet> index = Lists.newArrayList(); final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet( (Projection) index1.getTupleExpr()); final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet( (Projection) index2.getTupleExpr()); index.add(ais2); index.add(ais1); final ParsedQuery pq = sp.parseQuery(queryString, null); final TupleExpr tup = pq.getTupleExpr().clone(); provider.setIndices(index); final PCJOptimizer pcj = new PCJOptimizer(index, false, provider); pcj.optimize(tup, null, null); final IndexPlanValidator ipv = new IndexPlanValidator(false); Assert.assertEquals(true, ipv.isValid(tup)); }
@Test public void testEvaluateTwoIndexCrossProduct1() throws Exception { final String indexSparqlString = "" + "SELECT ?e ?l ?c " + "{" + " ?e a ?c . " + " ?e <http: + "}"; final String indexSparqlString2 = "" + "SELECT ?e ?l ?o " + "{" + " ?e <uri:talksTo> ?o . " + " ?o <http: + "}"; final String queryString = "" + "SELECT ?e ?c ?l ?o ?f ?g " + "{" + " ?e a ?c . " + " ?e <http: + " ?e <uri:talksTo> ?o . " + " ?o <http: + " ?f <uri:talksTo> ?g . " + "}"; final SPARQLParser sp = new SPARQLParser(); final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null); final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null); final List<ExternalTupleSet> index = Lists.newArrayList(); final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet( (Projection) index1.getTupleExpr()); final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet( (Projection) index2.getTupleExpr()); index.add(ais2); index.add(ais1); final ParsedQuery pq = sp.parseQuery(queryString, null); final TupleExpr tup = pq.getTupleExpr().clone(); provider.setIndices(index); final PCJOptimizer pcj = new PCJOptimizer(index, false, provider); pcj.optimize(tup, null, null); final IndexPlanValidator ipv = new IndexPlanValidator(true); Assert.assertEquals(false, ipv.isValid(tup)); }
@Test public void testEvaluateTwoIndexCrossProduct2() throws Exception { final String indexSparqlString = "" + "SELECT ?e ?l ?c " + "{" + " ?e a ?c . " + " ?e <http: + "}"; final String indexSparqlString2 = "" + "SELECT ?e ?l ?o " + "{" + " ?e <uri:talksTo> ?o . " + " ?o <http: + "}"; final String queryString = "" + "SELECT ?e ?c ?l ?o ?f ?g " + "{" + " ?e a ?c . " + " ?e <http: + " ?e <uri:talksTo> ?o . " + " ?o <http: + " ?f <uri:talksTo> ?g . " + "}"; final SPARQLParser sp = new SPARQLParser(); final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null); final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null); final List<ExternalTupleSet> index = Lists.newArrayList(); final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet( (Projection) index1.getTupleExpr()); final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet( (Projection) index2.getTupleExpr()); index.add(ais1); index.add(ais2); final ParsedQuery pq = sp.parseQuery(queryString, null); final TupleExpr tup = pq.getTupleExpr().clone(); provider.setIndices(index); final PCJOptimizer pcj = new PCJOptimizer(index, false, provider); pcj.optimize(tup, null, null); final IndexPlanValidator ipv = new IndexPlanValidator(true); Assert.assertEquals(false, ipv.isValid(tup)); }
@Test public void testEvaluateTwoIndexCrossProduct3() throws Exception { final String indexSparqlString = "" + "SELECT ?e ?l ?c " + "{" + " ?e a ?c . " + " ?e <http: + "}"; final String indexSparqlString2 = "" + "SELECT ?e ?l ?o " + "{" + " ?e <uri:talksTo> ?o . " + " ?o <http: + "}"; final String queryString = "" + "SELECT ?e ?c ?l ?o ?f ?g " + "{" + " ?e a ?c . " + " ?e <http: + " ?e <uri:talksTo> ?o . " + " ?o <http: + " ?f <uri:talksTo> ?g . " + "}"; final SPARQLParser sp = new SPARQLParser(); final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null); final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null); final List<ExternalTupleSet> index = Lists.newArrayList(); final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet( (Projection) index1.getTupleExpr()); final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet( (Projection) index2.getTupleExpr()); index.add(ais1); index.add(ais2); final ParsedQuery pq = sp.parseQuery(queryString, null); final TupleExpr tup = pq.getTupleExpr().clone(); provider.setIndices(index); final PCJOptimizer pcj = new PCJOptimizer(index, false, provider); pcj.optimize(tup, null, null); final IndexPlanValidator ipv = new IndexPlanValidator(false); Assert.assertEquals(true, ipv.isValid(tup)); }
@Test public void testEvaluateTwoIndexDiffVars() throws Exception { final String indexSparqlString = "" + "SELECT ?chicken ?dog ?pig " + "{" + " ?dog a ?chicken . " + " ?dog <http: + "}"; final String indexSparqlString2 = "" + "SELECT ?fish ?ant ?turkey " + "{" + " ?fish <uri:talksTo> ?turkey . " + " ?turkey <http: + "}"; final String queryString = "" + "SELECT ?e ?c ?l ?o ?f ?g " + "{" + " ?e a ?c . " + " ?e <http: + " ?e <uri:talksTo> ?o . " + " ?o <http: + " ?f <uri:talksTo> ?g . " + "}"; final SPARQLParser sp = new SPARQLParser(); final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null); final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null); final List<ExternalTupleSet> index = Lists.newArrayList(); final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet( (Projection) index1.getTupleExpr()); final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet( (Projection) index2.getTupleExpr()); index.add(ais1); index.add(ais2); final ParsedQuery pq = sp.parseQuery(queryString, null); final TupleExpr tup = pq.getTupleExpr().clone(); provider.setIndices(index); final PCJOptimizer pcj = new PCJOptimizer(index, false, provider); pcj.optimize(tup, null, null); final IndexPlanValidator ipv = new IndexPlanValidator(false); Assert.assertEquals(false, ipv.isValid(tup)); }
@Test public void testEvaluateTwoIndexDiffVars2() throws Exception { final String indexSparqlString = "" + "SELECT ?dog ?pig ?chicken " + "{" + " ?dog a ?chicken . " + " ?dog <http: + "}"; final String indexSparqlString2 = "" + "SELECT ?fish ?ant ?turkey " + "{" + " ?fish <uri:talksTo> ?turkey . " + " ?turkey <http: + "}"; final String queryString = "" + "SELECT ?e ?c ?l ?o ?f ?g " + "{" + " ?e a ?c . " + " ?e <http: + " ?e <uri:talksTo> ?o . " + " ?o <http: + " ?f <uri:talksTo> ?g . " + "}"; final SPARQLParser sp = new SPARQLParser(); final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null); final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null); final List<ExternalTupleSet> index = Lists.newArrayList(); final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet( (Projection) index1.getTupleExpr()); final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet( (Projection) index2.getTupleExpr()); index.add(ais1); index.add(ais2); final ParsedQuery pq = sp.parseQuery(queryString, null); final TupleExpr tup = pq.getTupleExpr().clone(); provider.setIndices(index); final PCJOptimizer pcj = new PCJOptimizer(index, false, provider); pcj.optimize(tup, null, null); final IndexPlanValidator ipv = new IndexPlanValidator(false); Assert.assertEquals(true, ipv.isValid(tup)); }
@Test public void testEvaluateTwoIndexDiffVars3() throws Exception { final String indexSparqlString = "" + "SELECT ?pig ?dog ?chicken " + "{" + " ?dog a ?chicken . " + " ?dog <http: + "}"; final String indexSparqlString2 = "" + "SELECT ?fish ?ant ?turkey " + "{" + " ?fish <uri:talksTo> ?turkey . " + " ?turkey <http: + "}"; final String queryString = "" + "SELECT ?e ?c ?l ?o ?f ?g " + "{" + " ?e a ?c . " + " ?e <http: + " ?e <uri:talksTo> ?o . " + " ?o <http: + " ?f <uri:talksTo> ?g . " + "}"; final SPARQLParser sp = new SPARQLParser(); final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null); final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null); final List<ExternalTupleSet> index = Lists.newArrayList(); final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet( (Projection) index1.getTupleExpr()); final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet( (Projection) index2.getTupleExpr()); index.add(ais1); index.add(ais2); final ParsedQuery pq = sp.parseQuery(queryString, null); final TupleExpr tup = pq.getTupleExpr().clone(); provider.setIndices(index); final PCJOptimizer pcj = new PCJOptimizer(index, false, provider); pcj.optimize(tup, null, null); final IndexPlanValidator ipv = new IndexPlanValidator(false); Assert.assertEquals(true, ipv.isValid(tup)); }
@Test public void testEvaluateTwoIndexDiffVarsDirProd() throws Exception { final String indexSparqlString = "" + "SELECT ?pig ?dog ?chicken " + "{" + " ?dog a ?chicken . " + " ?dog <http: + "}"; final String indexSparqlString2 = "" + "SELECT ?fish ?ant ?turkey " + "{" + " ?fish <uri:talksTo> ?turkey . " + " ?turkey <http: + "}"; final String queryString = "" + "SELECT ?e ?c ?l ?o ?f ?g " + "{" + " ?e a ?c . " + " ?e <http: + " ?e <uri:talksTo> ?o . " + " ?o <http: + " ?f <uri:talksTo> ?g . " + "}"; final SPARQLParser sp = new SPARQLParser(); final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null); final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null); final List<ExternalTupleSet> index = Lists.newArrayList(); final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet( (Projection) index1.getTupleExpr()); final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet( (Projection) index2.getTupleExpr()); index.add(ais1); index.add(ais2); final ParsedQuery pq = sp.parseQuery(queryString, null); final TupleExpr tup = pq.getTupleExpr().clone(); provider.setIndices(index); final PCJOptimizer pcj = new PCJOptimizer(index, false, provider); pcj.optimize(tup, null, null); final IndexPlanValidator ipv = new IndexPlanValidator(true); Assert.assertEquals(false, ipv.isValid(tup)); }