Search in sources :

Example 1 with EmptyBindingSet

use of org.eclipse.rdf4j.query.impl.EmptyBindingSet 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.createIRI("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" + "}";
    final Multiset<BindingSet> expectedSolutions = HashMultiset.create();
    expectedSolutions.add(new EmptyBindingSet());
    // Execute pipeline and verify results
    final QueryRoot queryTree = new QueryRoot(PARSER.parseQuery(query, null).getTupleExpr());
    final SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(getRyaCollection());
    queryTree.visit(visitor);
    Assert.assertTrue(queryTree.getArg() instanceof Projection);
    final Projection projection = (Projection) queryTree.getArg();
    Assert.assertTrue(projection.getArg() instanceof AggregationPipelineQueryNode);
    final AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) projection.getArg();
    final Multiset<BindingSet> solutions = HashMultiset.create();
    final CloseableIteration<BindingSet, QueryEvaluationException> iter = pipelineNode.evaluate(new QueryBindingSet());
    while (iter.hasNext()) {
        solutions.add(iter.next());
    }
    Assert.assertEquals(expectedSolutions, solutions);
}
Also used : ListBindingSet(org.eclipse.rdf4j.query.impl.ListBindingSet) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) EmptyBindingSet(org.eclipse.rdf4j.query.impl.EmptyBindingSet) BindingSet(org.eclipse.rdf4j.query.BindingSet) EmptyBindingSet(org.eclipse.rdf4j.query.impl.EmptyBindingSet) QueryRoot(org.eclipse.rdf4j.query.algebra.QueryRoot) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Projection(org.eclipse.rdf4j.query.algebra.Projection) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Aggregations

BindingSet (org.eclipse.rdf4j.query.BindingSet)1 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)1 Projection (org.eclipse.rdf4j.query.algebra.Projection)1 QueryRoot (org.eclipse.rdf4j.query.algebra.QueryRoot)1 QueryBindingSet (org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet)1 EmptyBindingSet (org.eclipse.rdf4j.query.impl.EmptyBindingSet)1 ListBindingSet (org.eclipse.rdf4j.query.impl.ListBindingSet)1 Test (org.junit.Test)1