use of org.apache.fluo.api.data.Bytes 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.fluo.api.data.Bytes 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.fluo.api.data.Bytes in project incubator-rya by apache.
the class BindingHashShardingFunction method addShard.
/**
* Generates a sharded rowId. The rowId is of the form: node_prefix:shardId:nodeId//Binding_values. For
* example, the row key generated from nodeId = SP_123, varOrder = a;b, bs = [a = uri:Bob, b = uri:Doug] would be
* SP:HASH(uri:Bob):123//uri:Bob;uri:Doug, where HASH(uri:Bob) indicates the shard id hash generated from the
* Binding value "uri:Bob".
*
* @param nodeId - Node Id with type and UUID
* @param varOrder - VarOrder used to order BindingSet values
* @param bs - BindingSet with partially formed query values
* @return - serialized Bytes rowId for storing BindingSet results in Fluo
*/
public static Bytes addShard(String nodeId, VariableOrder varOrder, VisibilityBindingSet bs) {
checkNotNull(nodeId);
checkNotNull(varOrder);
checkNotNull(bs);
String[] rowPrefixAndId = nodeId.split("_");
Preconditions.checkArgument(rowPrefixAndId.length == 2);
String prefix = rowPrefixAndId[0];
String id = rowPrefixAndId[1];
String firstBindingString = "";
Bytes rowSuffix = Bytes.of(id);
if (varOrder.getVariableOrders().size() > 0) {
VariableOrder first = new VariableOrder(varOrder.getVariableOrders().get(0));
firstBindingString = BS_CONVERTER.convert(bs, first);
rowSuffix = RowKeyUtil.makeRowKey(id, varOrder, bs);
}
BytesBuilder builder = Bytes.builder();
builder.append(Bytes.of(prefix + ":"));
builder.append(genHash(Bytes.of(id + NODEID_BS_DELIM + firstBindingString)));
builder.append(":");
builder.append(rowSuffix);
return builder.toBytes();
}
use of org.apache.fluo.api.data.Bytes 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.fluo.api.data.Bytes in project incubator-rya by apache.
the class JoinBatchBindingSetUpdater method fillSiblingBatch.
/**
* Fetches batch to be processed by scanning over the Span specified by the
* {@link JoinBatchInformation}. The number of results is less than or equal
* to the batch size specified by the JoinBatchInformation.
*
* @param tx - Fluo transaction in which batch operation is performed
* @param batch - batch order to be processed
* @param bsSet- set that batch results are added to
* @return Set - containing results of sibling scan.
* @throws Exception
*/
private Optional<RowColumn> fillSiblingBatch(final TransactionBase tx, final JoinBatchInformation batch, final Set<VisibilityBindingSet> bsSet) throws Exception {
final Span span = batch.getSpan();
final Column column = batch.getColumn();
final int batchSize = batch.getBatchSize();
final RowScanner rs = tx.scanner().over(span).fetch(column).byRow().build();
final Iterator<ColumnScanner> colScannerIter = rs.iterator();
boolean batchLimitMet = false;
Bytes row = span.getStart().getRow();
while (colScannerIter.hasNext() && !batchLimitMet) {
final ColumnScanner colScanner = colScannerIter.next();
row = colScanner.getRow();
final Iterator<ColumnValue> iter = colScanner.iterator();
while (iter.hasNext()) {
if (bsSet.size() >= batchSize) {
batchLimitMet = true;
break;
}
bsSet.add(BS_SERDE.deserialize(iter.next().getValue()));
}
}
if (batchLimitMet) {
return Optional.of(new RowColumn(row, column));
} else {
return Optional.empty();
}
}
Aggregations