Search in sources :

Example 76 with VisibilityBindingSet

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);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Example 77 with VisibilityBindingSet

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());
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Example 78 with VisibilityBindingSet

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);
}
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 79 with VisibilityBindingSet

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());
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) MapBindingSet(org.openrdf.query.impl.MapBindingSet)

Example 80 with VisibilityBindingSet

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

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