Search in sources :

Example 86 with VisibilityBindingSet

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

the class StatementPatternObserver method parseObservation.

@Override
public Observation parseObservation(final TransactionBase tx, final Bytes row) throws Exception {
    requireNonNull(tx);
    requireNonNull(row);
    // Make nodeId and get the Statement Pattern metadata.
    final String spNodeId = BindingSetRow.makeFromShardedRow(Bytes.of(SP_PREFIX), row).getNodeId();
    final StatementPatternMetadata spMetadata = queryDao.readStatementPatternMetadata(tx, spNodeId);
    // Read the Visibility Binding Set from the value.
    final Bytes valueBytes = tx.get(row, FluoQueryColumns.STATEMENT_PATTERN_BINDING_SET);
    final VisibilityBindingSet spBindingSet = BS_SERDE.deserialize(valueBytes);
    // Figure out which node needs to handle the new metadata.
    final String parentNodeId = spMetadata.getParentNodeId();
    return new Observation(spNodeId, spBindingSet, parentNodeId);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) StatementPatternMetadata(org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata)

Example 87 with VisibilityBindingSet

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

the class AggregationObserver method parseObservation.

@Override
public Observation parseObservation(final TransactionBase tx, final Bytes row) {
    requireNonNull(tx);
    requireNonNull(row);
    // Make nodeId and fetch the Aggregation node's metadata.
    final String nodeId = BindingSetRow.makeFromShardedRow(Bytes.of(AGGREGATION_PREFIX), row).getNodeId();
    final AggregationMetadata metadata = queryDao.readAggregationMetadata(tx, nodeId);
    // Read the Visibility Binding Set from the value.
    final Bytes stateBytes = tx.get(row, FluoQueryColumns.AGGREGATION_BINDING_SET);
    final AggregationState state = STATE_SERDE.deserialize(stateBytes.toArray());
    final VisibilityBindingSet aggBindingSet = new VisibilityBindingSet(state.getBindingSet(), state.getVisibility());
    // Figure out which node needs to handle the new metadata.
    final String parentNodeId = metadata.getParentNodeId();
    return new Observation(nodeId, aggBindingSet, parentNodeId);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) AggregationMetadata(org.apache.rya.indexing.pcj.fluo.app.query.AggregationMetadata) AggregationState(org.apache.rya.api.function.aggregation.AggregationState)

Example 88 with VisibilityBindingSet

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

the class ProjectionResultUpdater method updateProjectionResults.

/**
 * Updates the results of a Projection node when one of its children has added a
 * new Binding Set to its results.
 *
 * @param tx - The transaction all Fluo queries will use. (not null)
 * @param childBindingSet - A binding set that the query's child node has emmitted. (not null)
 * @param projectionMetadata - The metadata of the Query whose results will be updated. (not null)
 * @throws Exception A problem caused the update to fail.
 */
public void updateProjectionResults(final TransactionBase tx, final VisibilityBindingSet childBindingSet, final ProjectionMetadata projectionMetadata) throws Exception {
    checkNotNull(tx);
    checkNotNull(childBindingSet);
    checkNotNull(projectionMetadata);
    log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "Node ID: " + projectionMetadata.getNodeId() + "\n" + "Parent Node ID: " + projectionMetadata.getParentNodeId() + "\n" + "Child Node ID: " + projectionMetadata.getChildNodeId() + "\n" + "Child Binding Set:\n" + childBindingSet + "\n");
    // Create the query's Binding Set from the child node's binding set.
    final VariableOrder queryVarOrder = projectionMetadata.getVariableOrder();
    final VariableOrder projectionVarOrder = projectionMetadata.getProjectedVars();
    final BindingSet queryBindingSet = BindingSetUtil.keepBindings(projectionVarOrder, childBindingSet);
    VisibilityBindingSet projectedBs = new VisibilityBindingSet(queryBindingSet, childBindingSet.getVisibility());
    // Create the Row Key for the result. If the child node groups results, then the key must only contain the Group By variables.
    Bytes resultRow = makeRowKey(projectionMetadata.getNodeId(), queryVarOrder, projectedBs);
    // Create the Binding Set that goes in the Node Value. It does contain visibilities.
    final Bytes nodeValueBytes = BS_SERDE.serialize(projectedBs);
    log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "New Binding Set: " + childBindingSet + "\n");
    tx.set(resultRow, FluoQueryColumns.PROJECTION_BINDING_SET, nodeValueBytes);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) Bytes(org.apache.fluo.api.data.Bytes) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)

Example 89 with VisibilityBindingSet

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

the class LeftOuterJoinTest method newLeftResult_noRightMatches.

@Test
public void newLeftResult_noRightMatches() {
    final IterativeJoin leftOuterJoin = new LeftOuterJoin();
    // There is a new left result.
    final MapBindingSet mapLeftResult = new MapBindingSet();
    mapLeftResult.addBinding("name", vf.createLiteral("Bob"));
    final VisibilityBindingSet newLeftResult = new VisibilityBindingSet(mapLeftResult);
    // There are no right results that join with the left result.
    final Iterator<VisibilityBindingSet> rightResults = new ArrayList<VisibilityBindingSet>().iterator();
    // Therefore, the left result is a new join result.
    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(newLeftResult);
    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 90 with VisibilityBindingSet

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

the class LeftOuterJoinTest method newRightResult_joinsWithLeftResults.

@Test
public void newRightResult_joinsWithLeftResults() {
    final IterativeJoin leftOuterJoin = new LeftOuterJoin();
    // 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 = leftOuterJoin.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)

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