Search in sources :

Example 16 with PCJOptimizer

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

the class PrecompJoinOptimizerTest method twoFourIndexWithFilterTest.

@Test
public void twoFourIndexWithFilterTest() throws Exception {
    final String q1 = // 
    "" + // 
    "SELECT ?f ?m ?d ?e ?l ?c " + // 
    "{" + // 
    "  Filter(?f > \"5\")." + // 
    "  Filter(?e > \"5\")." + // 
    "  ?f a ?m ." + // 
    "  ?e a ?l ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "  ?c <uri:talksTo> ?e . " + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ." + // 
    "}";
    final String q2 = // 
    "" + // 
    "SELECT ?s ?t ?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 " + // 
    "{" + // 
    " Filter(?s > \"5\") ." + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    final String q4 = // 
    "" + // 
    "SELECT ?f ?m ?d " + // 
    "{" + // 
    " Filter(?f > \"5\") ." + // 
    "  ?f a ?m ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "}";
    final String q5 = // 
    "" + // 
    "SELECT ?e ?l ?c " + // 
    "{" + // 
    " Filter(?e > \"5\") ." + // 
    "  ?e a ?l ." + // 
    "  ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ." + // 
    "  ?c <uri:talksTo> ?e . " + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = null;
    ParsedQuery pq2 = null;
    ParsedQuery pq3 = null;
    ParsedQuery pq4 = null;
    ParsedQuery pq5 = null;
    try {
        pq1 = parser.parseQuery(q1, null);
        pq2 = parser.parseQuery(q2, null);
        pq3 = parser.parseQuery(q3, null);
        pq4 = parser.parseQuery(q4, null);
        pq5 = parser.parseQuery(q5, null);
    } catch (final Exception e) {
        e.printStackTrace();
    }
    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 List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup2);
    list.add(extTup1);
    final List<ExternalTupleSet> list2 = new ArrayList<ExternalTupleSet>();
    list2.add(extTup3);
    list2.add(extTup4);
    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.size(), list2.size());
    for (final QueryModelNode e : nc.qNodes) {
        Assert.assertTrue(list2.contains(e));
    }
}
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 17 with PCJOptimizer

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

the class PrecompJoinOptimizerVarToConstTest method testFreeTestIndexFunction.

@Test
public void testFreeTestIndexFunction() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser2 = new SPARQLParser();
    final ParsedQuery pq1 = parser1.parseQuery(q22, null);
    final ParsedQuery pq2 = parser2.parseQuery(q24, 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(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 18 with PCJOptimizer

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

the class PrecompJoinOptimizerVarToConstTest method testContextFilterFourIndex.

@Test
public void testContextFilterFourIndex() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser3 = new SPARQLParser();
    final SPARQLParser parser4 = new SPARQLParser();
    final ParsedQuery pq1 = parser1.parseQuery(q19, null);
    final ParsedQuery pq3 = parser3.parseQuery(q17, null);
    final ParsedQuery pq4 = parser4.parseQuery(q18, null);
    System.out.println("Query is " + pq1.getTupleExpr());
    System.out.println("Indexes are " + pq3.getTupleExpr() + " , " + pq4.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(extTup3);
    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);
    Assert.assertEquals(2, eTupSet.size());
    final Set<StatementPattern> set = Sets.newHashSet();
    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 19 with PCJOptimizer

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

the class IndexPlanValidatorTest method testEvaluateTwoIndexTwoVarOrder6.

@Test
public void testEvaluateTwoIndexTwoVarOrder6() throws Exception {
    final String indexSparqlString = // 
    "" + // 
    "SELECT ?e ?l ?c  " + // 
    "{" + // 
    "  ?e a ?c . " + // 
    "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + // 
    "}";
    final String indexSparqlString2 = // 
    "" + // 
    "SELECT ?l ?e ?o " + // 
    "{" + // 
    "  ?e <uri:talksTo> ?o . " + // 
    "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l " + // 
    "}";
    final 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 " + // 
    "}";
    final SPARQLParser sp = new SPARQLParser();
    final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null);
    final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
    final List<ExternalTupleSet> index = Lists.newArrayList();
    final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection) index1.getTupleExpr());
    final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection) index2.getTupleExpr());
    index.add(ais2);
    index.add(ais1);
    final ParsedQuery pq = sp.parseQuery(queryString, null);
    final TupleExpr tup = pq.getTupleExpr().clone();
    provider.setIndices(index);
    final PCJOptimizer pcj = new PCJOptimizer(index, false, provider);
    pcj.optimize(tup, null, null);
    final IndexPlanValidator ipv = new IndexPlanValidator(false);
    Assert.assertEquals(true, ipv.isValid(tup));
}
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 20 with PCJOptimizer

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

the class IndexPlanValidatorTest method testEvaluateTwoIndexCrossProduct1.

@Test
public void testEvaluateTwoIndexCrossProduct1() throws Exception {
    final String indexSparqlString = // 
    "" + // 
    "SELECT ?e ?l ?c  " + // 
    "{" + // 
    "  ?e a ?c . " + // 
    "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + // 
    "}";
    final String indexSparqlString2 = // 
    "" + // 
    "SELECT ?e ?l ?o " + // 
    "{" + // 
    "  ?e <uri:talksTo> ?o . " + // 
    "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l " + // 
    "}";
    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(ais2);
    index.add(ais1);
    final ParsedQuery pq = sp.parseQuery(queryString, null);
    final TupleExpr tup = pq.getTupleExpr().clone();
    provider.setIndices(index);
    final PCJOptimizer pcj = new PCJOptimizer(index, false, provider);
    pcj.optimize(tup, null, null);
    final IndexPlanValidator ipv = new IndexPlanValidator(true);
    Assert.assertEquals(false, ipv.isValid(tup));
}
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)

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