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