Search in sources :

Example 41 with Projection

use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.

the class TopologyFactoryTest method projectionJoinStatementPattern.

@Test
public void projectionJoinStatementPattern() throws Exception {
    final String query = "SELECT * WHERE { " + "?person <urn:talksTo> ?otherPerson . " + "?otherPerson <urn:talksTo> ?dog . " + "}";
    FACTORY.build(query, "source", "sink", new RandomUUIDFactory());
    final List<ProcessorEntry> entries = FACTORY.getProcessorEntry();
    assertTrue(entries.get(0).getNode() instanceof Projection);
    assertTrue(entries.get(1).getNode() instanceof Join);
    StatementPattern expected = new StatementPattern(new Var("person"), TALKS_TO, new Var("otherPerson"));
    assertEquals(expected, entries.get(2).getNode());
    expected = new StatementPattern(new Var("otherPerson"), TALKS_TO, new Var("dog"));
    assertEquals(expected, entries.get(3).getNode());
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) RandomUUIDFactory(org.apache.rya.api.function.projection.RandomUUIDFactory) Projection(org.openrdf.query.algebra.Projection) Join(org.openrdf.query.algebra.Join) ProcessorEntry(org.apache.rya.streams.kafka.topology.TopologyFactory.ProcessorEntry) Test(org.junit.Test)

Example 42 with Projection

use of org.openrdf.query.algebra.Projection 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)

Example 43 with Projection

use of org.openrdf.query.algebra.Projection 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 44 with Projection

use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.

the class ConstructConsequentVisitorTest method testNoExtension.

@Test
public void testNoExtension() {
    StatementPattern sp = new StatementPattern(new Var("x"), new Var("y"), new Var("z"));
    Projection projection = new Projection(sp, new ProjectionElemList(new ProjectionElem("x", "subject"), new ProjectionElem("y", "predicate"), new ProjectionElem("z", "object")));
    ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
    projection.visit(visitor);
    Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(null), p(null), o(null)));
    Assert.assertEquals(expected, visitor.getConsequents());
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 45 with Projection

use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.

the class ConstructConsequentVisitorTest method testBNode.

@Test
public void testBNode() {
    Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new Var("x"), "x"), new ExtensionElem(new BNodeGenerator(), "z"));
    Projection projection = new Projection(extension, new ProjectionElemList(new ProjectionElem("x", "subject"), new ProjectionElem("y", "predicate"), new ProjectionElem("z", "object")));
    ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
    projection.visit(visitor);
    Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(null), p(null), anon(o(null))));
    Assert.assertEquals(expected, visitor.getConsequents());
}
Also used : Extension(org.openrdf.query.algebra.Extension) ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) BNodeGenerator(org.openrdf.query.algebra.BNodeGenerator) SingletonSet(org.openrdf.query.algebra.SingletonSet) Var(org.openrdf.query.algebra.Var) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Aggregations

Projection (org.openrdf.query.algebra.Projection)76 Test (org.junit.Test)64 StatementPattern (org.openrdf.query.algebra.StatementPattern)41 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)37 ParsedQuery (org.openrdf.query.parser.ParsedQuery)34 TupleExpr (org.openrdf.query.algebra.TupleExpr)33 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)27 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)27 ProjectionElemList (org.openrdf.query.algebra.ProjectionElemList)24 Var (org.openrdf.query.algebra.Var)24 ArrayList (java.util.ArrayList)23 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)23 ProjectionElem (org.openrdf.query.algebra.ProjectionElem)22 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)17 Join (org.openrdf.query.algebra.Join)15 HashSet (java.util.HashSet)14 Union (org.openrdf.query.algebra.Union)10 Resource (org.openrdf.model.Resource)9 MultiProjection (org.openrdf.query.algebra.MultiProjection)9 HashMap (java.util.HashMap)8