You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rya.apache.org by mi...@apache.org on 2016/02/07 19:26:14 UTC
[11/16] incubator-rya git commit: RYA-32 Improve how metadata and
values are written to Accumulo PCJ tables
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/c12f58f4/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
index eea5b95..2826318 100644
--- a/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/IndexPlanValidatorTest.java
+++ b/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/IndexPlanValidatorTest.java
@@ -8,9 +8,9 @@ package mvm.rya.indexing.IndexPlanValidator;
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,22 +19,18 @@ package mvm.rya.indexing.IndexPlanValidator;
* under the License.
*/
-
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.PrecompJoinOptimizer;
import mvm.rya.indexing.external.tupleSet.ExternalTupleSet;
import mvm.rya.indexing.external.tupleSet.SimpleExternalTupleSet;
+import org.junit.Assert;
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;
@@ -43,1106 +39,746 @@ 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);
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
+ @Test
+ public void testEvaluateTwoIndexTwoVarOrder1()
+ throws MalformedQueryException {
+
+ System.out
+ .println("********************Test number 1***************************");
+
+ 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 = sp.parseQuery(indexSparqlString, null);
+ ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
+ 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 = sp.parseQuery(queryString, null);
+ TupleExpr tup = pq.getTupleExpr().clone();
+ PrecompJoinOptimizer pcj = new PrecompJoinOptimizer(index, false);
+ pcj.optimize(tup, null, null);
+
+ System.out.println("TupleExpr is " + tup);
+
+ IndexPlanValidator ipv = new IndexPlanValidator(false);
+ Assert.assertEquals(false, ipv.isValid(tup));
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexTwoVarOrder2()
+ throws MalformedQueryException {
+
+ System.out
+ .println("********************Test number 2***************************");
+
+ 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 = sp.parseQuery(indexSparqlString, null);
+ ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
+
+ 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 = sp.parseQuery(queryString, null);
+ TupleExpr tup = pq.getTupleExpr().clone();
+ PrecompJoinOptimizer pcj = new PrecompJoinOptimizer(index, false);
+ pcj.optimize(tup, null, null);
+
+ System.out.println("TupleExpr is " + tup);
+
+ IndexPlanValidator ipv = new IndexPlanValidator(false);
+ Assert.assertEquals(true, ipv.isValid(tup));
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexTwoVarOrder3()
+ throws MalformedQueryException {
+
+ System.out
+ .println("********************Test number 3***************************");
+
+ 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 = sp.parseQuery(indexSparqlString, null);
+ ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
+
+ 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 = sp.parseQuery(queryString, null);
+ TupleExpr tup = pq.getTupleExpr().clone();
+ PrecompJoinOptimizer pcj = new PrecompJoinOptimizer(index, false);
+ pcj.optimize(tup, null, null);
+
+ System.out.println("TupleExpr is " + tup);
+
+ IndexPlanValidator ipv = new IndexPlanValidator(false);
+ Assert.assertEquals(true, ipv.isValid(tup));
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexTwoVarOrder4()
+ throws MalformedQueryException {
+
+ System.out
+ .println("********************Test number 4***************************");
+
+ 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 = sp.parseQuery(indexSparqlString, null);
+ ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
+
+ 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 = sp.parseQuery(queryString, null);
+ TupleExpr tup = pq.getTupleExpr().clone();
+ PrecompJoinOptimizer pcj = new PrecompJoinOptimizer(index, false);
+ pcj.optimize(tup, null, null);
+
+ System.out.println("TupleExpr is " + tup);
+
+ IndexPlanValidator ipv = new IndexPlanValidator(false);
+ Assert.assertEquals(false, ipv.isValid(tup));
+
+ }
+
+
+ @Test
+ public void testEvaluateTwoIndexTwoVarOrder6()
+ throws MalformedQueryException {
+
+ System.out
+ .println("********************Test number 6***************************");
+
+ 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 = sp.parseQuery(indexSparqlString, null);
+ ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
+
+ 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 = sp.parseQuery(queryString, null);
+ TupleExpr tup = pq.getTupleExpr().clone();
+ PrecompJoinOptimizer pcj = new PrecompJoinOptimizer(index, false);
+ pcj.optimize(tup, null, null);
+
+ System.out.println("TupleExpr is " + tup);
+
+ IndexPlanValidator ipv = new IndexPlanValidator(false);
+ Assert.assertEquals(true, ipv.isValid(tup));
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexCrossProduct1()
+ throws MalformedQueryException {
+
+ System.out
+ .println("********************Test number 7***************************");
+
+ 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 = sp.parseQuery(indexSparqlString, null);
+ ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
+ 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 = sp.parseQuery(queryString, null);
+ TupleExpr tup = pq.getTupleExpr().clone();
+ PrecompJoinOptimizer pcj = new PrecompJoinOptimizer(index, false);
+ pcj.optimize(tup, null, null);
+
+ IndexPlanValidator ipv = new IndexPlanValidator(true);
+ Assert.assertEquals(false, ipv.isValid(tup));
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexCrossProduct2()
+ throws MalformedQueryException {
+
+ System.out
+ .println("********************Test number 8***************************");
+
+ 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 = sp.parseQuery(indexSparqlString, null);
+ ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
+
+ 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 = sp.parseQuery(queryString, null);
+ TupleExpr tup = pq.getTupleExpr().clone();
+ PrecompJoinOptimizer pcj = new PrecompJoinOptimizer(index, false);
+ pcj.optimize(tup, null, null);
+
+ IndexPlanValidator ipv = new IndexPlanValidator(true);
+ Assert.assertEquals(false, ipv.isValid(tup));
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexCrossProduct3()
+ throws MalformedQueryException {
+
+ System.out
+ .println("********************Test number 9***************************");
+
+ 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 = sp.parseQuery(indexSparqlString, null);
+ ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
+
+ 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 = sp.parseQuery(queryString, null);
+ TupleExpr tup = pq.getTupleExpr().clone();
+ PrecompJoinOptimizer pcj = new PrecompJoinOptimizer(index, false);
+ pcj.optimize(tup, null, null);
+
+ IndexPlanValidator ipv = new IndexPlanValidator(false);
+ Assert.assertEquals(true, ipv.isValid(tup));
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexDiffVars() throws MalformedQueryException {
+
+ System.out
+ .println("********************Test number 10***************************");
+
+ 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 = sp.parseQuery(indexSparqlString, null);
+ ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
+
+ 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 = sp.parseQuery(queryString, null);
+ TupleExpr tup = pq.getTupleExpr().clone();
+ PrecompJoinOptimizer pcj = new PrecompJoinOptimizer(index, false);
+ pcj.optimize(tup, null, null);
+
+ IndexPlanValidator ipv = new IndexPlanValidator(false);
+ Assert.assertEquals(false, ipv.isValid(tup));
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexDiffVars2() throws MalformedQueryException {
+
+ System.out
+ .println("********************Test number 11***************************");
+
+ 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 = sp.parseQuery(indexSparqlString, null);
+ ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
+
+ 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 = sp.parseQuery(queryString, null);
+ TupleExpr tup = pq.getTupleExpr().clone();
+ PrecompJoinOptimizer pcj = new PrecompJoinOptimizer(index, false);
+ pcj.optimize(tup, null, null);
+
+ IndexPlanValidator ipv = new IndexPlanValidator(false);
+ Assert.assertEquals(true, ipv.isValid(tup));
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexDiffVars3() throws MalformedQueryException {
+
+ System.out
+ .println("********************Test number 11***************************");
+
+ 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 = sp.parseQuery(indexSparqlString, null);
+ ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
+
+ 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 = sp.parseQuery(queryString, null);
+ TupleExpr tup = pq.getTupleExpr().clone();
+ PrecompJoinOptimizer pcj = new PrecompJoinOptimizer(index, false);
+ pcj.optimize(tup, null, null);
+
+ IndexPlanValidator ipv = new IndexPlanValidator(false);
+ Assert.assertEquals(true, ipv.isValid(tup));
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexDiffVarsDirProd()
+ throws MalformedQueryException {
+
+ System.out
+ .println("********************Test number 12***************************");
+
+ 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 = sp.parseQuery(indexSparqlString, null);
+ ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
+
+ 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 = sp.parseQuery(queryString, null);
+ TupleExpr tup = pq.getTupleExpr().clone();
+ PrecompJoinOptimizer pcj = new PrecompJoinOptimizer(index, false);
+ pcj.optimize(tup, null, null);
+
+ 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/c12f58f4/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
index 79a6656..296a010 100644
--- a/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/IndexedExecutionPlanGeneratorTest.java
+++ b/extras/indexing/src/test/java/mvm/rya/indexing/IndexPlanValidator/IndexedExecutionPlanGeneratorTest.java
@@ -8,9 +8,9 @@ package mvm.rya.indexing.IndexPlanValidator;
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,405 +19,350 @@ package mvm.rya.indexing.IndexPlanValidator;
* under the License.
*/
-
-
-
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.Assert;
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);
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ 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();
+
+ 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);
+ }
}