Search in sources :

Example 16 with ListBindingSet

use of org.openrdf.query.impl.ListBindingSet in project incubator-rya by apache.

the class PipelineQueryIT method testRequiredTimestamp.

@Test
public void testRequiredTimestamp() throws Exception {
    // Insert data
    URI person = VF.createURI("urn:Person");
    URI livingThing = VF.createURI("urn:LivingThing");
    URI human = VF.createURI("urn:Human");
    URI programmer = VF.createURI("urn:Programmer");
    URI thing = VF.createURI("urn:Thing");
    insert(programmer, RDFS.SUBCLASSOF, person);
    insert(person, RDFS.SUBCLASSOF, FOAF.PERSON, 2);
    insert(FOAF.PERSON, RDFS.SUBCLASSOF, person);
    insert(person, OWL.EQUIVALENTCLASS, human);
    insert(person, RDFS.SUBCLASSOF, livingThing);
    insert(livingThing, RDFS.SUBCLASSOF, thing);
    insert(thing, RDFS.SUBCLASSOF, OWL.THING);
    insert(OWL.THING, RDFS.SUBCLASSOF, thing);
    dao.flush();
    // Define query and expected results
    final String query = "SELECT ?A ?B WHERE {\n" + "  ?A rdfs:subClassOf ?B .\n" + "  ?B rdfs:subClassOf ?A .\n" + "}";
    List<String> varNames = Arrays.asList("A", "B");
    Multiset<BindingSet> expectedSolutions = HashMultiset.create();
    expectedSolutions.add(new ListBindingSet(varNames, person, FOAF.PERSON));
    expectedSolutions.add(new ListBindingSet(varNames, FOAF.PERSON, person));
    expectedSolutions.add(new ListBindingSet(varNames, thing, OWL.THING));
    expectedSolutions.add(new ListBindingSet(varNames, OWL.THING, thing));
    // Prepare query and convert to pipeline
    QueryRoot queryTree = new QueryRoot(PARSER.parseQuery(query, null).getTupleExpr());
    SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(getRyaCollection());
    queryTree.visit(visitor);
    Assert.assertTrue(queryTree.getArg() instanceof AggregationPipelineQueryNode);
    AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) queryTree.getArg();
    // Extend the pipeline by requiring a timestamp of zero (should have no effect)
    pipelineNode.requireSourceTimestamp(0);
    Multiset<BindingSet> solutions = HashMultiset.create();
    CloseableIteration<BindingSet, QueryEvaluationException> iter = pipelineNode.evaluate(new QueryBindingSet());
    while (iter.hasNext()) {
        solutions.add(iter.next());
    }
    Assert.assertEquals(expectedSolutions, solutions);
    // Extend the pipeline by requiring a future timestamp (should produce no results)
    long delta = 1000 * 60 * 60 * 24;
    pipelineNode.requireSourceTimestamp(System.currentTimeMillis() + delta);
    iter = pipelineNode.evaluate(new QueryBindingSet());
    Assert.assertFalse(iter.hasNext());
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) ListBindingSet(org.openrdf.query.impl.ListBindingSet) EmptyBindingSet(org.openrdf.query.impl.EmptyBindingSet) ListBindingSet(org.openrdf.query.impl.ListBindingSet) URI(org.openrdf.model.URI) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) QueryRoot(org.openrdf.query.algebra.QueryRoot) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Test(org.junit.Test)

Aggregations

BindingSet (org.openrdf.query.BindingSet)16 ListBindingSet (org.openrdf.query.impl.ListBindingSet)16 Test (org.junit.Test)14 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)8 HashSet (java.util.HashSet)7 URI (org.openrdf.model.URI)7 EmptyBindingSet (org.openrdf.query.impl.EmptyBindingSet)7 LinkedList (java.util.LinkedList)5 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)2 QueryRoot (org.openrdf.query.algebra.QueryRoot)2 HashMap (java.util.HashMap)1 StandardizingSPARQLParser (openrdffork.StandardizingSPARQLParser)1 Document (org.bson.Document)1 Value (org.openrdf.model.Value)1 Binding (org.openrdf.query.Binding)1 ParsedQuery (org.openrdf.query.parser.ParsedQuery)1 NoURIException (utility.NoURIException)1