use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class IterativeJoinTest method naturalJoin_sideDoesNotMatter.
/**
* This test ensures the same binding sets are created as the result of a
* {@link IterativeJoin} regardless of which side the notification is triggered on.
*/
@Test
public void naturalJoin_sideDoesNotMatter() {
// Create the binding sets that will be joined.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bs1 = new MapBindingSet();
bs1.addBinding("id", vf.createLiteral("some_uid"));
bs1.addBinding("name", vf.createLiteral("Alice"));
final VisibilityBindingSet vbs1 = new VisibilityBindingSet(bs1, "a");
final MapBindingSet bs2 = new MapBindingSet();
bs2.addBinding("id", vf.createLiteral("some_uid"));
bs2.addBinding("hair", vf.createLiteral("brown"));
final VisibilityBindingSet vbs2 = new VisibilityBindingSet(bs2, "b");
// new vbs1 shows up on the left, matches vbs2 on the right
final Iterator<VisibilityBindingSet> newLeftIt = join.newLeftResult(vbs1, Collections.singleton(vbs2).iterator());
final VisibilityBindingSet newLeftResult = newLeftIt.next();
// new vbs2 shows up on the right, matches vbs1 on the left
final Iterator<VisibilityBindingSet> newRightIt = join.newRightResult(Collections.singleton(vbs1).iterator(), vbs2);
final VisibilityBindingSet newRightResult = newRightIt.next();
// Ensure those two results are the same.
assertEquals(newLeftResult, newRightResult);
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class NaturalJoinTest method newRightResult_noLeftMatches.
@Test
public void newRightResult_noLeftMatches() {
final IterativeJoin naturalJoin = new NaturalJoin();
// 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 = naturalJoin.newRightResult(leftResults, new VisibilityBindingSet(newRightResult));
assertFalse(newJoinResultsIt.hasNext());
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class NaturalJoinTest method newRightResult_joinsWithLeftResults.
@Test
public void newRightResult_joinsWithLeftResults() {
final IterativeJoin naturalJoin = new NaturalJoin();
// There are a few left results that join with the new right result.
final MapBindingSet nameAge = new MapBindingSet();
nameAge.addBinding("name", vf.createLiteral("Bob"));
nameAge.addBinding("age", vf.createLiteral(56));
final MapBindingSet nameHair = new MapBindingSet();
nameHair.addBinding("name", vf.createLiteral("Bob"));
nameHair.addBinding("hairColor", vf.createLiteral("Brown"));
final Iterator<VisibilityBindingSet> leftResults = Lists.<VisibilityBindingSet>newArrayList(new VisibilityBindingSet(nameAge), new VisibilityBindingSet(nameHair)).iterator();
// There is a new right result.
final MapBindingSet newRightResult = new MapBindingSet();
newRightResult.addBinding("name", vf.createLiteral("Bob"));
newRightResult.addBinding("height", vf.createLiteral("5'9\""));
// Therefore, there are a few new join results that mix the two together.
final Iterator<VisibilityBindingSet> newJoinResultsIt = naturalJoin.newRightResult(leftResults, new VisibilityBindingSet(newRightResult));
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 AggregationsEvaluator method update.
/**
* Update the aggregation values using information found within {@code newBs}.
*
* @param newBs - A binding set whose values need to be incorporated within the aggregations. (not null)
* @return A binding set containing the updated aggregation values.
*/
public VisibilityBindingSet update(final VisibilityBindingSet newBs) {
requireNonNull(newBs);
// Load the old state if one was previously stored; otherwise initialize the state.
final AggregationState state = aggStateStore.get(newBs).orElseGet(() -> {
// Initialize a new state.
final AggregationState newState = new AggregationState();
// If we have group by bindings, their values need to be added to the state's binding set.
final MapBindingSet bindingSet = newState.getBindingSet();
for (final String groupByVar : groupByVars) {
bindingSet.addBinding(newBs.getBinding(groupByVar));
}
return newState;
});
// Update the visibilities of the result binding set based on the new result's visibilities.
final String oldVisibility = state.getVisibility();
final String updateVisibilities = VisibilitySimplifier.unionAndSimplify(oldVisibility, newBs.getVisibility());
state.setVisibility(updateVisibilities);
// Update the Aggregation State with each Aggregation function included within this group.
for (final AggregationElement aggregation : aggregations) {
final AggregationType type = aggregation.getAggregationType();
final AggregationFunction function = FUNCTIONS.get(type);
if (function == null) {
throw new RuntimeException("Unrecognized aggregation function: " + type);
}
function.update(aggregation, state, newBs);
}
// Store the updated state. This will write on top of any old state that was present for the Group By values.
aggStateStore.store(state);
// Return the updated binding set from the updated state.
return new VisibilityBindingSet(state.getBindingSet(), state.getVisibility());
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class FilterEvaluatorTest method doesNotMatch.
@Test
public void doesNotMatch() 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(11));
final VisibilityBindingSet visBs = new VisibilityBindingSet(bs);
// Test the evaluator.
assertFalse(FilterEvaluator.make(filter).filter(visBs));
}
Aggregations