Search in sources :

Example 36 with PCJOptimizer

use of org.apache.rya.indexing.pcj.matching.PCJOptimizer in project incubator-rya by apache.

the class PrecompJoinOptimizerTest method testSixIndex.

@Test
public void testSixIndex() 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 String q5 = // 
    "" + // 
    "SELECT ?m ?f ?d " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "}";
    final String q6 = // 
    "" + // 
    "SELECT ?d ?f ?h " + // 
    "{" + // 
    "  ?d <uri:hangOutWith> ?f ." + // 
    "  ?f <uri:hangOutWith> ?h ." + // 
    "}";
    final String q7 = // 
    "" + // 
    "SELECT ?f ?i ?h " + // 
    "{" + // 
    "  ?f <uri:associatesWith> ?i ." + // 
    "  ?i <uri:associatesWith> ?h ." + // 
    "}";
    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 ParsedQuery pq5 = parser.parseQuery(q5, null);
    final ParsedQuery pq6 = parser.parseQuery(q6, null);
    final ParsedQuery pq7 = parser.parseQuery(q7, 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 SimpleExternalTupleSet extTup4 = new SimpleExternalTupleSet((Projection) pq5.getTupleExpr());
    final SimpleExternalTupleSet extTup5 = new SimpleExternalTupleSet((Projection) pq6.getTupleExpr());
    final SimpleExternalTupleSet extTup6 = new SimpleExternalTupleSet((Projection) pq7.getTupleExpr());
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup2);
    list.add(extTup1);
    list.add(extTup3);
    final List<QueryModelNode> optTupNodes = Lists.newArrayList();
    optTupNodes.add(extTup4);
    optTupNodes.add(extTup6);
    optTupNodes.add(extTup5);
    provider.setIndices(list);
    final PCJOptimizer pcj = new PCJOptimizer(list, true, provider);
    final TupleExpr te = pq1.getTupleExpr();
    pcj.optimize(te, null, null);
    System.out.println(te);
    final NodeCollector nc = new NodeCollector();
    te.visit(nc);
    Assert.assertEquals(nc.qNodes, Sets.newHashSet(optTupNodes));
}
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) 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) Test(org.junit.Test)

Example 37 with PCJOptimizer

use of org.apache.rya.indexing.pcj.matching.PCJOptimizer in project incubator-rya by apache.

the class PrecompJoinOptimizerTest method testThreeIndex2.

@Test
public void testThreeIndex2() throws Exception {
    final String q1 = // 
    "" + // 
    "SELECT ?f ?m ?d ?e ?l ?c " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?c a ?l ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "  ?e <uri:talksTo> ?c . " + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?l <http://www.w3.org/2000/01/rdf-schema#label> ?e ." + // 
    "  ?m <uri:talksTo> ?e . " + // 
    "}";
    final String q2 = // 
    "" + // 
    "SELECT ?u ?s ?t " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    final String q3 = // 
    "" + // 
    "SELECT ?e ?c ?l " + // 
    "{" + // 
    "  ?c a ?l ." + // 
    "  ?l <http://www.w3.org/2000/01/rdf-schema#label> ?e ." + // 
    "  ?e <uri:talksTo> ?c . " + // 
    "}";
    final String q4 = // 
    "" + // 
    "SELECT ?d ?f ?m " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "}";
    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(extTup1);
    final List<StatementPattern> spList = StatementPatternCollector.process(pq1.getTupleExpr());
    final List<QueryModelNode> optTupNodes = Lists.newArrayList();
    optTupNodes.add(extTup3);
    optTupNodes.add(spList.get(6));
    optTupNodes.add(extTup2);
    provider.setIndices(list);
    final PCJOptimizer pcj = new PCJOptimizer(list, true, provider);
    final TupleExpr te = pq1.getTupleExpr();
    pcj.optimize(te, null, null);
    final NodeCollector nc = new NodeCollector();
    te.visit(nc);
    Assert.assertEquals(nc.qNodes, Sets.newHashSet(optTupNodes));
}
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) StatementPattern(org.openrdf.query.algebra.StatementPattern) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Test(org.junit.Test)

Example 38 with PCJOptimizer

use of org.apache.rya.indexing.pcj.matching.PCJOptimizer in project incubator-rya by apache.

the class PrecompJoinOptimizerVarToConstTest method testThreeIndexGeoFreeCompareFilterMix.

@Test
public void testThreeIndexGeoFreeCompareFilterMix() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser2 = new SPARQLParser();
    final SPARQLParser parser3 = new SPARQLParser();
    final ParsedQuery pq1 = parser1.parseQuery(q25, null);
    final ParsedQuery pq2 = parser2.parseQuery(q24, null);
    final ParsedQuery pq3 = parser3.parseQuery(q26, null);
    System.out.println("Query is " + pq1.getTupleExpr());
    System.out.println("Indexes are " + pq2.getTupleExpr() + " and " + pq3.getTupleExpr());
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
    final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup1);
    list.add(extTup2);
    final TupleExpr tup = pq1.getTupleExpr().clone();
    final PCJOptimizer pcj = new PCJOptimizer(list, false, new AccumuloIndexSetProvider(new Configuration(), list));
    pcj.optimize(tup, null, null);
    System.out.println("Processed query is " + tup);
    final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
    final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
    final Set<StatementPattern> set = Sets.newHashSet();
    Assert.assertEquals(2, eTupSet.size());
    for (final QueryModelNode s : eTupSet) {
        final Set<StatementPattern> tempSet = Sets.newHashSet(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
        set.addAll(tempSet);
    }
    Assert.assertTrue(qSet.containsAll(set));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) Configuration(org.apache.hadoop.conf.Configuration) ParsedQuery(org.openrdf.query.parser.ParsedQuery) AccumuloIndexSetProvider(org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider) ArrayList(java.util.ArrayList) Projection(org.openrdf.query.algebra.Projection) 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) StatementPattern(org.openrdf.query.algebra.StatementPattern) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Test(org.junit.Test)

Example 39 with PCJOptimizer

use of org.apache.rya.indexing.pcj.matching.PCJOptimizer in project incubator-rya by apache.

the class PrecompJoinOptimizerVarToConstTest method testGeoIndexFunction.

@Test
public void testGeoIndexFunction() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser2 = new SPARQLParser();
    final ParsedQuery pq1 = parser1.parseQuery(q21, null);
    final ParsedQuery pq2 = parser2.parseQuery(q23, null);
    System.out.println("Query is " + pq1.getTupleExpr());
    System.out.println("Index is " + pq2.getTupleExpr());
    final SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup);
    final TupleExpr tup = pq1.getTupleExpr().clone();
    final PCJOptimizer pcj = new PCJOptimizer(list, false, new AccumuloIndexSetProvider(new Configuration(), list));
    pcj.optimize(tup, null, null);
    System.out.println("Processed query is " + tup);
    final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
    final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
    final Set<StatementPattern> set = Sets.newHashSet();
    Assert.assertEquals(1, eTupSet.size());
    for (final QueryModelNode s : eTupSet) {
        final Set<StatementPattern> tempSet = Sets.newHashSet(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
        set.addAll(tempSet);
    }
    Assert.assertTrue(qSet.containsAll(set));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) Configuration(org.apache.hadoop.conf.Configuration) ParsedQuery(org.openrdf.query.parser.ParsedQuery) AccumuloIndexSetProvider(org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider) ArrayList(java.util.ArrayList) Projection(org.openrdf.query.algebra.Projection) 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) StatementPattern(org.openrdf.query.algebra.StatementPattern) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Test(org.junit.Test)

Example 40 with PCJOptimizer

use of org.apache.rya.indexing.pcj.matching.PCJOptimizer in project incubator-rya by apache.

the class PrecompJoinOptimizerVarToConstTest method testFourIndexGeoFreeCompareFilterMix.

@Test
public void testFourIndexGeoFreeCompareFilterMix() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser2 = new SPARQLParser();
    final SPARQLParser parser3 = new SPARQLParser();
    final SPARQLParser parser4 = new SPARQLParser();
    final ParsedQuery pq1 = parser1.parseQuery(q27, null);
    final ParsedQuery pq2 = parser2.parseQuery(q23, null);
    final ParsedQuery pq3 = parser3.parseQuery(q26, null);
    final ParsedQuery pq4 = parser4.parseQuery(q24, null);
    System.out.println("Query is " + pq1.getTupleExpr());
    System.out.println("Indexes are " + pq2.getTupleExpr() + " , " + pq3.getTupleExpr() + " , " + pq4.getTupleExpr());
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
    final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
    final SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet(new Projection(pq4.getTupleExpr()));
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup1);
    list.add(extTup2);
    list.add(extTup3);
    final TupleExpr tup = pq1.getTupleExpr().clone();
    final PCJOptimizer pcj = new PCJOptimizer(list, false, new AccumuloIndexSetProvider(new Configuration(), list));
    pcj.optimize(tup, null, null);
    System.out.println("Processed query is " + tup);
    final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
    final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
    final Set<StatementPattern> set = Sets.newHashSet();
    Assert.assertEquals(3, eTupSet.size());
    for (final QueryModelNode s : eTupSet) {
        final Set<StatementPattern> tempSet = Sets.newHashSet(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
        set.addAll(tempSet);
    }
    Assert.assertTrue(qSet.containsAll(set));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) Configuration(org.apache.hadoop.conf.Configuration) ParsedQuery(org.openrdf.query.parser.ParsedQuery) AccumuloIndexSetProvider(org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider) ArrayList(java.util.ArrayList) Projection(org.openrdf.query.algebra.Projection) 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) StatementPattern(org.openrdf.query.algebra.StatementPattern) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Test(org.junit.Test)

Aggregations

PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)48 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)46 TupleExpr (org.openrdf.query.algebra.TupleExpr)46 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)46 Test (org.junit.Test)44 ParsedQuery (org.openrdf.query.parser.ParsedQuery)44 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)42 ArrayList (java.util.ArrayList)33 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)27 StatementPattern (org.openrdf.query.algebra.StatementPattern)22 Projection (org.openrdf.query.algebra.Projection)17 AccumuloIndexSetProvider (org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider)12 Configuration (org.apache.hadoop.conf.Configuration)10 IndexPlanValidator (org.apache.rya.indexing.IndexPlanValidator.IndexPlanValidator)4 URI (org.openrdf.model.URI)4 LiteralImpl (org.openrdf.model.impl.LiteralImpl)4 URIImpl (org.openrdf.model.impl.URIImpl)4 NodeCollector (org.apache.rya.indexing.external.PrecompJoinOptimizerTest.NodeCollector)2 AccumuloIndexSet (org.apache.rya.indexing.external.tupleSet.AccumuloIndexSet)2 MongoPcjIndexSetProvider (org.apache.rya.indexing.mongodb.pcj.MongoPcjIndexSetProvider)2