Search in sources :

Example 76 with SimpleExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.

the class IndexPlanValidatorTest method testEvaluateTwoIndexDiffVars.

@Test
public void testEvaluateTwoIndexDiffVars() throws Exception {
    final String indexSparqlString = // 
    "" + // 
    "SELECT ?chicken ?dog ?pig  " + // 
    "{" + // 
    "  ?dog a ?chicken . " + // 
    "  ?dog <http://www.w3.org/2000/01/rdf-schema#label> ?pig " + // 
    "}";
    final String indexSparqlString2 = // 
    "" + // 
    "SELECT ?fish ?ant ?turkey " + // 
    "{" + // 
    "  ?fish <uri:talksTo> ?turkey . " + // 
    "  ?turkey <http://www.w3.org/2000/01/rdf-schema#label> ?ant " + // 
    "}";
    final 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 . " + // 
    "}";
    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));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) ParsedQuery(org.openrdf.query.parser.ParsedQuery) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) Test(org.junit.Test)

Example 77 with SimpleExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.

the class IndexPlanValidatorTest method testEvaluateTwoIndexDiffVars2.

@Test
public void testEvaluateTwoIndexDiffVars2() throws Exception {
    final String indexSparqlString = // 
    "" + // 
    "SELECT ?dog ?pig ?chicken  " + // 
    "{" + // 
    "  ?dog a ?chicken . " + // 
    "  ?dog <http://www.w3.org/2000/01/rdf-schema#label> ?pig " + // 
    "}";
    final String indexSparqlString2 = // 
    "" + // 
    "SELECT ?fish ?ant ?turkey " + // 
    "{" + // 
    "  ?fish <uri:talksTo> ?turkey . " + // 
    "  ?turkey <http://www.w3.org/2000/01/rdf-schema#label> ?ant " + // 
    "}";
    final 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 . " + // 
    "}";
    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));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) ParsedQuery(org.openrdf.query.parser.ParsedQuery) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) Test(org.junit.Test)

Example 78 with SimpleExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.

the class IndexPlanValidatorTest method testValidTupleIterator.

@Test
public void testValidTupleIterator() throws Exception {
    final 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 ." + // 
    "}";
    final String q2 = // 
    "" + // 
    "SELECT ?t ?s ?u " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    final String q3 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  ?s <uri:hangOutWith> ?t ." + // 
    "  ?t <uri:hangOutWith> ?u ." + // 
    "}";
    final String q4 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  ?s <uri:associatesWith> ?t ." + // 
    "  ?t <uri:associatesWith> ?u ." + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(q1, null);
    final ParsedQuery pq2 = parser.parseQuery(q2, null);
    final ParsedQuery pq3 = parser.parseQuery(q3, null);
    final ParsedQuery pq4 = parser.parseQuery(q4, null);
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
    final SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr());
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup2);
    list.add(extTup1);
    list.add(extTup3);
    final IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
    final Iterator<TupleExpr> plans = new TupleExecutionPlanGenerator().getPlans(iep.getIndexedTuples());
    final IndexPlanValidator ipv = new IndexPlanValidator(true);
    final 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);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) Test(org.junit.Test)

Example 79 with SimpleExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.

the class ThreshholdPlanSelectorTest method testSingleIndex.

@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);
    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));
    }
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) Test(org.junit.Test)

Example 80 with SimpleExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.

the class ThreshholdPlanSelectorTest method testCost3.

@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);
    final TupleExpr te = pq1.getTupleExpr().clone();
    final PCJOptimizer pcj = new PCJOptimizer(eList, false, new AccumuloIndexSetProvider(new Configuration(), eList));
    pcj.optimize(te, null, null);
    ThreshholdPlanSelector tps = new ThreshholdPlanSelector(pq1.getTupleExpr());
    double cost = tps.getCost(te, .4, .3, .3);
    Assert.assertEquals(.575, cost, .0001);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Configuration(org.apache.hadoop.conf.Configuration) ParsedQuery(org.openrdf.query.parser.ParsedQuery) AccumuloIndexSetProvider(org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) Test(org.junit.Test)

Aggregations

SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)84 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)84 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)83 Test (org.junit.Test)82 ParsedQuery (org.openrdf.query.parser.ParsedQuery)82 TupleExpr (org.openrdf.query.algebra.TupleExpr)74 ArrayList (java.util.ArrayList)60 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)47 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)42 Projection (org.openrdf.query.algebra.Projection)27 StatementPattern (org.openrdf.query.algebra.StatementPattern)23 HashSet (java.util.HashSet)18 Configuration (org.apache.hadoop.conf.Configuration)10 AccumuloIndexSetProvider (org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider)10 Join (org.openrdf.query.algebra.Join)6 List (java.util.List)5 MalformedQueryException (org.openrdf.query.MalformedQueryException)5 LeftJoin (org.openrdf.query.algebra.LeftJoin)5 Filter (org.openrdf.query.algebra.Filter)4 NodeCollector (org.apache.rya.indexing.external.PrecompJoinOptimizerTest.NodeCollector)2