Search in sources :

Example 36 with VisibilityBindingSet

use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.

the class LazyJoiningIterator method next.

@Override
public VisibilityBindingSet next() {
    final MapBindingSet bs = new MapBindingSet();
    for (final Binding binding : newResult) {
        bs.addBinding(binding);
    }
    final VisibilityBindingSet joinResult = joinedResults.next();
    for (final Binding binding : joinResult) {
        bs.addBinding(binding);
    }
    // We want to make sure the visibilities are always written the same way,
    // so figure out which are on the left side and which are on the right side.
    final String leftVisi;
    final String rightVisi;
    if (newResultSide == Side.LEFT) {
        leftVisi = newResult.getVisibility();
        rightVisi = joinResult.getVisibility();
    } else {
        leftVisi = joinResult.getVisibility();
        rightVisi = newResult.getVisibility();
    }
    final String visibility = VisibilitySimplifier.unionAndSimplify(leftVisi, rightVisi);
    return new VisibilityBindingSet(bs, visibility);
}
Also used : Binding(org.openrdf.query.Binding) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) MapBindingSet(org.openrdf.query.impl.MapBindingSet)

Example 37 with VisibilityBindingSet

use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.

the class LeftOuterJoinTest method newRightResult_noLeftMatches.

@Test
public void newRightResult_noLeftMatches() {
    final IterativeJoin leftOuterJoin = new LeftOuterJoin();
    // There are no left results.
    final Iterator<VisibilityBindingSet> leftResults = new ArrayList<VisibilityBindingSet>().iterator();
    // There is a new right result.
    final MapBindingSet newRightResult = new MapBindingSet();
    newRightResult.addBinding("name", vf.createLiteral("Bob"));
    // Therefore, there are no new join results.
    final Iterator<VisibilityBindingSet> newJoinResultsIt = leftOuterJoin.newRightResult(leftResults, new VisibilityBindingSet(newRightResult));
    assertFalse(newJoinResultsIt.hasNext());
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Example 38 with VisibilityBindingSet

use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.

the class LeftOuterJoinTest method newLeftResult_joinsWithRightResults.

@Test
public void newLeftResult_joinsWithRightResults() {
    final IterativeJoin leftOuterJoin = new LeftOuterJoin();
    // There is a new left result.
    final MapBindingSet mapLeftResult = new MapBindingSet();
    mapLeftResult.addBinding("name", vf.createLiteral("Bob"));
    mapLeftResult.addBinding("height", vf.createLiteral("5'9\""));
    final VisibilityBindingSet newLeftResult = new VisibilityBindingSet(mapLeftResult);
    // There are a few right results that join with the left result.
    final MapBindingSet nameAge = new MapBindingSet();
    nameAge.addBinding("name", vf.createLiteral("Bob"));
    nameAge.addBinding("age", vf.createLiteral(56));
    final VisibilityBindingSet visiAge = new VisibilityBindingSet(nameAge);
    final MapBindingSet nameHair = new MapBindingSet();
    nameHair.addBinding("name", vf.createLiteral("Bob"));
    nameHair.addBinding("hairColor", vf.createLiteral("Brown"));
    final VisibilityBindingSet visiHair = new VisibilityBindingSet(nameHair);
    final Iterator<VisibilityBindingSet> rightResults = Lists.<VisibilityBindingSet>newArrayList(visiAge, visiHair).iterator();
    // Therefore, there are a few new join results that mix the two together.
    final Iterator<VisibilityBindingSet> newJoinResultsIt = leftOuterJoin.newLeftResult(newLeftResult, rightResults);
    final Set<BindingSet> newJoinResults = new HashSet<>();
    while (newJoinResultsIt.hasNext()) {
        newJoinResults.add(newJoinResultsIt.next());
    }
    final Set<BindingSet> expected = Sets.<BindingSet>newHashSet();
    final MapBindingSet nameHeightAge = new MapBindingSet();
    nameHeightAge.addBinding("name", vf.createLiteral("Bob"));
    nameHeightAge.addBinding("height", vf.createLiteral("5'9\""));
    nameHeightAge.addBinding("age", vf.createLiteral(56));
    expected.add(new VisibilityBindingSet(nameHeightAge));
    final MapBindingSet nameHeightHair = new MapBindingSet();
    nameHeightHair.addBinding("name", vf.createLiteral("Bob"));
    nameHeightHair.addBinding("height", vf.createLiteral("5'9\""));
    nameHeightHair.addBinding("hairColor", vf.createLiteral("Brown"));
    expected.add(new VisibilityBindingSet(nameHeightHair));
    assertEquals(expected, newJoinResults);
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) MapBindingSet(org.openrdf.query.impl.MapBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 39 with VisibilityBindingSet

use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.

the class FilterEvaluatorTest method matches.

@Test
public void matches() throws Exception {
    // Read the filter object from a SPARQL query.
    final Filter filter = getFilter("SELECT * " + "WHERE { " + "FILTER(?age < 10)" + "?person <urn:age> ?age " + "}");
    // Create the input binding set.
    final ValueFactory vf = new ValueFactoryImpl();
    final MapBindingSet bs = new MapBindingSet();
    bs.addBinding("person", vf.createURI("urn:Alice"));
    bs.addBinding("age", vf.createLiteral(9));
    final VisibilityBindingSet visBs = new VisibilityBindingSet(bs);
    // Test the evaluator.
    assertTrue(FilterEvaluator.make(filter).filter(visBs));
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) Filter(org.openrdf.query.algebra.Filter) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Example 40 with VisibilityBindingSet

use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.

the class ProjectionEvaluatorTest method addsBlankNodeBinding.

/**
 * This projection creates a Binding Set that represents a Statement that has a blank node added to it.
 */
@Test
public void addsBlankNodeBinding() throws Exception {
    // Read the projection object from a SPARQL query.
    final Projection projection = getProjection("CONSTRUCT { ?person <urn:hasChild> _:b } " + "WHERE {" + "?person <urn:hasGrandchild> ?grandchild ." + "}");
    // Create a Binding Set that contains the result of the WHERE clause.
    final ValueFactory vf = new ValueFactoryImpl();
    MapBindingSet bs = new MapBindingSet();
    bs.addBinding("person", vf.createURI("urn:Alice"));
    bs.addBinding("hasGrandchild", vf.createURI("urn:Bob"));
    final VisibilityBindingSet original = new VisibilityBindingSet(bs, "a|b");
    // Execute the projection.
    final VisibilityBindingSet result = ProjectionEvaluator.make(projection).project(original);
    // The expected binding set represents a statement. We need to get the blank node's id from the
    // result since that is different every time.
    bs = new MapBindingSet();
    bs.addBinding("subject", vf.createURI("urn:Alice"));
    bs.addBinding("predicate", vf.createURI("urn:hasChild"));
    bs.addBinding("object", result.getValue("object"));
    final VisibilityBindingSet expected = new VisibilityBindingSet(bs, "a|b");
    assertEquals(expected, result);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Projection(org.openrdf.query.algebra.Projection) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Aggregations

VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)140 Test (org.junit.Test)105 MapBindingSet (org.openrdf.query.impl.MapBindingSet)93 ValueFactory (org.openrdf.model.ValueFactory)66 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)66 HashSet (java.util.HashSet)52 ArrayList (java.util.ArrayList)31 UUID (java.util.UUID)28 VisibilityStatement (org.apache.rya.api.model.VisibilityStatement)28 TopologyFactory (org.apache.rya.streams.kafka.topology.TopologyFactory)24 BindingSet (org.openrdf.query.BindingSet)24 TopologyBuilder (org.apache.kafka.streams.processor.TopologyBuilder)23 RandomUUIDFactory (org.apache.rya.api.function.projection.RandomUUIDFactory)23 URIImpl (org.openrdf.model.impl.URIImpl)19 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)19 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)18 Bytes (org.apache.fluo.api.data.Bytes)16 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)15 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)12 Statement (org.openrdf.model.Statement)12