Search in sources :

Example 21 with PCJOptimizer

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

the class IndexPlanValidatorTest method testEvaluateTwoIndexCrossProduct3.

@Test
public void testEvaluateTwoIndexCrossProduct3() 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(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 22 with PCJOptimizer

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

the class IndexPlanValidatorTest method testEvaluateTwoIndexDiffVars3.

@Test
public void testEvaluateTwoIndexDiffVars3() throws Exception {
    final String indexSparqlString = // 
    "" + // 
    "SELECT ?pig ?dog ?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 23 with PCJOptimizer

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

the class IndexPlanValidatorTest method testEvaluateTwoIndexTwoVarOrder4.

@Test
public void testEvaluateTwoIndexTwoVarOrder4() throws Exception {
    final String indexSparqlString = // 
    "" + // 
    "SELECT ?e ?c ?l  " + // 
    "{" + // 
    "  ?e a ?c . " + // 
    "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + // 
    "}";
    final String indexSparqlString2 = // 
    "" + // 
    "SELECT ?e ?o ?l " + // 
    "{" + // 
    "  ?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(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 24 with PCJOptimizer

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

the class PCJOptimizerBenchmark method optimizeQuery_chained.

@Benchmark
public void optimizeQuery_chained() throws MalformedQueryException {
    // Fetch the pieces that benchmark uses.
    final BenchmarkValues values = chainedBenchmarkValues.get(new BenchmarkParams(numPCJs, pcjSPCount, querySPCount));
    final PCJOptimizer pcjOptimizer = values.getPCJOptimizer();
    final TupleExpr query = values.getQuery();
    // Perform the optimization.
    pcjOptimizer.optimize(query, null, null);
}
Also used : PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) TupleExpr(org.openrdf.query.algebra.TupleExpr) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 25 with PCJOptimizer

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

the class PCJOptimizerBenchmark method makeChainedPCJOptimizer.

private static PCJOptimizer makeChainedPCJOptimizer(final BenchmarkParams params) throws Exception {
    final Queue<String> varQueue = Lists.newLinkedList(variables);
    final SPARQLParser parser = new SPARQLParser();
    final List<ExternalTupleSet> indices = new ArrayList<>();
    // Create the first PCJ.
    final List<String> pcjVars = new ArrayList<>();
    pcjVars.add(varQueue.remove());
    pcjVars.add(varQueue.remove());
    for (int spI = 1; spI < params.getPCJSPCount(); spI++) {
        pcjVars.add(varQueue.remove());
    }
    String pcjSparql = buildChainedSPARQL(pcjVars);
    Projection projection = (Projection) parser.parseQuery(pcjSparql, null).getTupleExpr();
    indices.add(new SimpleExternalTupleSet(projection));
    // Add the rest of the PCJs.
    for (int pcjI = 1; pcjI < params.getNumPCJS(); pcjI++) {
        // Remove the previous PCJs first variable.
        pcjVars.remove(0);
        // And add a new one to the end of it.
        pcjVars.add(varQueue.remove());
        // Build the index.
        pcjSparql = buildChainedSPARQL(pcjVars);
        projection = (Projection) parser.parseQuery(pcjSparql, null).getTupleExpr();
        indices.add(new SimpleExternalTupleSet(projection));
    }
    // Create the optimizer.
    return new PCJOptimizer(indices, false, new AccumuloIndexSetProvider(new Configuration()));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) Configuration(org.apache.hadoop.conf.Configuration) AccumuloIndexSetProvider(org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider) ArrayList(java.util.ArrayList) Projection(org.openrdf.query.algebra.Projection) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer)

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