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());
}
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()));
}
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()));
}
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());
}
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());
}
Aggregations