use of org.openrdf.query.algebra.QueryRoot in project incubator-rya by apache.
the class PipelineQueryIT method testNoVariableSP.
@Test
public void testNoVariableSP() throws Exception {
// Insert data
insert(OWL.THING, RDF.TYPE, OWL.CLASS);
insert(FOAF.PERSON, RDF.TYPE, OWL.CLASS, 1);
insert(FOAF.PERSON, RDFS.SUBCLASSOF, OWL.THING);
insert(VF.createURI("urn:Alice"), RDF.TYPE, FOAF.PERSON);
dao.flush();
// Define query and expected results
final String query = "SELECT * WHERE {\n" + " owl:Thing a owl:Class .\n" + "}";
Multiset<BindingSet> expectedSolutions = HashMultiset.create();
expectedSolutions.add(new EmptyBindingSet());
// Execute pipeline and verify results
QueryRoot queryTree = new QueryRoot(PARSER.parseQuery(query, null).getTupleExpr());
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(getRyaCollection());
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof Projection);
Projection projection = (Projection) queryTree.getArg();
Assert.assertTrue(projection.getArg() instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) projection.getArg();
Multiset<BindingSet> solutions = HashMultiset.create();
CloseableIteration<BindingSet, QueryEvaluationException> iter = pipelineNode.evaluate(new QueryBindingSet());
while (iter.hasNext()) {
solutions.add(iter.next());
}
Assert.assertEquals(expectedSolutions, solutions);
}
use of org.openrdf.query.algebra.QueryRoot in project incubator-rya by apache.
the class SparqlToPipelineTransformVisitorTest method testComplexJoin.
@Test
public void testComplexJoin() throws Exception {
StatementPattern isUndergrad = new StatementPattern(new Var("x"), constant(RDF.TYPE), constant(UNDERGRAD));
StatementPattern isProfessor = new StatementPattern(new Var("y"), constant(RDF.TYPE), constant(PROFESSOR));
StatementPattern takesCourse = new StatementPattern(new Var("x"), constant(TAKES), new Var("c"));
StatementPattern teachesCourse = new StatementPattern(new Var("y"), constant(TEACHES), new Var("c"));
QueryRoot queryTree = new QueryRoot(new Join(new Join(isUndergrad, takesCourse), new Join(isProfessor, teachesCourse)));
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof Join);
Join topJoin = (Join) queryTree.getArg();
Assert.assertTrue(topJoin.getLeftArg() instanceof AggregationPipelineQueryNode);
Assert.assertTrue(topJoin.getRightArg() instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode leftPipeline = (AggregationPipelineQueryNode) topJoin.getLeftArg();
AggregationPipelineQueryNode rightPipeline = (AggregationPipelineQueryNode) topJoin.getRightArg();
Assert.assertEquals(Sets.newHashSet("x", "c"), leftPipeline.getAssuredBindingNames());
Assert.assertEquals(Sets.newHashSet("y", "c"), rightPipeline.getAssuredBindingNames());
}
use of org.openrdf.query.algebra.QueryRoot in project incubator-rya by apache.
the class SparqlToPipelineTransformVisitorTest method testUnsupportedExtension.
@Test
public void testUnsupportedExtension() throws Exception {
StatementPattern sp = new StatementPattern(new Var("x"), constant(TAKES), new Var("c"));
List<ExtensionElem> elements = Arrays.asList(new ExtensionElem(new Var("x"), "renamed"), new ExtensionElem(new Not(new ValueConstant(VF.createLiteral(true))), "notTrue"), new ExtensionElem(new ValueConstant(TAKES), "constant"));
Extension extensionNode = new Extension(sp, elements);
QueryRoot queryTree = new QueryRoot(extensionNode);
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof Extension);
Assert.assertEquals(elements, ((Extension) queryTree.getArg()).getElements());
TupleExpr innerQuery = ((Extension) queryTree.getArg()).getArg();
Assert.assertTrue(innerQuery instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) innerQuery;
Assert.assertEquals(Sets.newHashSet("x", "c"), pipelineNode.getAssuredBindingNames());
}
use of org.openrdf.query.algebra.QueryRoot in project incubator-rya by apache.
the class SparqlToPipelineTransformVisitorTest method testExtension.
@Test
public void testExtension() throws Exception {
QueryRoot queryTree = new QueryRoot(new Extension(new StatementPattern(new Var("x"), constant(TAKES), new Var("c")), new ExtensionElem(new Var("x"), "renamed"), new ExtensionElem(new ValueConstant(TAKES), "constant")));
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) queryTree.getArg();
Assert.assertEquals(Sets.newHashSet("x", "c", "renamed", "constant"), pipelineNode.getAssuredBindingNames());
}
use of org.openrdf.query.algebra.QueryRoot in project incubator-rya by apache.
the class SparqlToPipelineTransformVisitorTest method testJoin.
@Test
public void testJoin() throws Exception {
QueryRoot query = new QueryRoot(new Join(new StatementPattern(new Var("x"), constant(RDF.TYPE), constant(UNDERGRAD)), new StatementPattern(new Var("x"), constant(TAKES), new Var("course"))));
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
query.visit(visitor);
Assert.assertTrue(query.getArg() instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) query.getArg();
Assert.assertEquals(Sets.newHashSet("x", "course"), pipelineNode.getAssuredBindingNames());
}
Aggregations