Search in sources :

Example 26 with PCJOptimizer

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

the class PCJOptimizerBenchmark method optimizeQuery_unchained.

@Benchmark
public void optimizeQuery_unchained() throws MalformedQueryException {
    // Fetch the pieces that benchmark uses.
    final BenchmarkValues values = unchainedBenchmarkValues.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 27 with PCJOptimizer

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

the class PCJOptimizerBenchmark method makeUnchainedPCJOptimizer.

private static PCJOptimizer makeUnchainedPCJOptimizer(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());
        pcjVars.add(varQueue.remove());
    }
    String pcjSparql = buildUnchainedSPARQL(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);
        pcjVars.remove(0);
        // And add a new one to the end of it.
        pcjVars.add(varQueue.remove());
        pcjVars.add(varQueue.remove());
        // Build the index.
        pcjSparql = buildUnchainedSPARQL(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)

Example 28 with PCJOptimizer

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

the class PCJOptionalTestIT method testSimpleOptionalTest2.

@Test
public void testSimpleOptionalTest2() throws Exception {
    final String query = // 
    "" + // 
    "SELECT ?u ?s ?t " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  OPTIONAL{?t <http://www.w3.org/2000/01/rdf-schema#label> ?u } ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "  ?s a ?u ." + // 
    "}";
    final String pcj = // 
    "" + // 
    "SELECT ?d ?b ?c " + // 
    "{" + // 
    "  ?b a ?c ." + // 
    "  OPTIONAL{?c <http://www.w3.org/2000/01/rdf-schema#label> ?d } ." + // 
    "  ?d <uri:talksTo> ?b . " + // 
    "}";
    final String relabel_pcj = // 
    "" + // 
    "SELECT ?u ?s ?t " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  OPTIONAL{?t <http://www.w3.org/2000/01/rdf-schema#label> ?u } ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(query, null);
    final ParsedQuery pq2 = parser.parseQuery(pcj, null);
    final ParsedQuery pq3 = parser.parseQuery(relabel_pcj, null);
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup1);
    final List<QueryModelNode> optTupNodes = Lists.newArrayList();
    optTupNodes.add(extTup2);
    final PCJOptimizer opt = new PCJOptimizer(list, true, new AccumuloIndexSetProvider(new Configuration(), list));
    final TupleExpr te = pq1.getTupleExpr();
    opt.optimize(te, null, null);
    final NodeCollector nc = new NodeCollector();
    te.visit(nc);
    final List<QueryModelNode> qNodes = nc.getNodes();
    Assert.assertEquals(qNodes.size(), optTupNodes.size() + 1);
    for (final QueryModelNode node : optTupNodes) {
        Assert.assertTrue(qNodes.contains(node));
    }
}
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) 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) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) NodeCollector(org.apache.rya.indexing.external.PrecompJoinOptimizerTest.NodeCollector) Test(org.junit.Test)

Example 29 with PCJOptimizer

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

the class PrecompJoinOptimizerTest2 method testContextFilter2.

@Test
public void testContextFilter2() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser2 = new SPARQLParser();
    final String query1 = // 
    "" + // 
    "SELECT ?k ?l ?m ?n " + // 
    "{" + // 
    " GRAPH ?z { " + // 
    " ?l <uri:talksTo> ?n . " + // 
    " ?l a ?n." + // 
    " ?k a ?m." + // 
    "  FILTER ((?k < ?l) && (?m < ?n)). " + // 
    "		}" + // 
    "}";
    final String query2 = // 
    "" + // 
    "SELECT ?s ?t " + // 
    "{" + // 
    " GRAPH ?r { " + // 
    " ?s <uri:talksTo> ?t . " + // 
    " ?s a ?t." + // 
    "	}" + // 
    "}";
    final ParsedQuery pq1 = parser1.parseQuery(query1, null);
    final ParsedQuery pq2 = parser2.parseQuery(query2, null);
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup1);
    final TupleExpr tup = pq1.getTupleExpr().clone();
    provider.setIndices(list);
    final PCJOptimizer pcj = new PCJOptimizer(list, false, provider);
    pcj.optimize(tup, null, null);
    final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
    final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
    final Set<StatementPattern> set = Sets.newHashSet();
    for (final QueryModelNode s : eTupSet) {
        set.addAll(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
    }
    Assert.assertTrue(qSet.containsAll(set) && eTupSet.size() == 1);
}
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 30 with PCJOptimizer

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

the class PrecompJoinOptimizerTest2 method testVarRelableIndexSameSize.

@Test
public void testVarRelableIndexSameSize() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser2 = new SPARQLParser();
    final ParsedQuery pq1 = parser1.parseQuery(q1, null);
    final ParsedQuery pq2 = parser2.parseQuery(q2, null);
    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();
    provider.setIndices(list);
    final PCJOptimizer pcj = new PCJOptimizer(list, false, provider);
    pcj.optimize(tup, null, null);
    final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
    final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
    final Set<StatementPattern> set = Sets.newHashSet();
    for (final QueryModelNode s : eTupSet) {
        set.addAll(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
    }
    Assert.assertTrue(set.equals(qSet));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) 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