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