use of org.apache.fluo.api.data.Bytes in project incubator-rya by apache.
the class FluoBinPruner method pruneBindingSetBin.
/**
* This method deletes BindingSets in the specified bin from the BindingSet
* Column of the indicated Fluo nodeId
*
* @param id
* - Fluo nodeId
* @param bin
* - bin id
*/
@Override
public void pruneBindingSetBin(final NodeBin nodeBin) {
final String id = nodeBin.getNodeId();
final long bin = nodeBin.getBin();
try (Transaction tx = client.newTransaction()) {
final Optional<NodeType> type = NodeType.fromNodeId(id);
if (!type.isPresent()) {
log.trace("Unable to determine NodeType from id: " + id);
throw new RuntimeException();
}
final Column batchInfoColumn = type.get().getResultColumn();
final Bytes batchInfoSpanPrefix = BindingHashShardingFunction.getShardedScanPrefix(id, vf.createLiteral(bin));
final SpanBatchDeleteInformation batchInfo = SpanBatchDeleteInformation.builder().setColumn(batchInfoColumn).setSpan(Span.prefix(batchInfoSpanPrefix)).build();
BatchInformationDAO.addBatch(tx, id, batchInfo);
tx.commit();
}
}
use of org.apache.fluo.api.data.Bytes in project incubator-rya by apache.
the class GetQueryReport method countBindingSets.
private BigInteger countBindingSets(final SnapshotBase sx, final String nodeId, final Column bindingSetColumn) {
checkNotNull(sx);
checkNotNull(nodeId);
checkNotNull(bindingSetColumn);
NodeType type = NodeType.fromNodeId(nodeId).get();
Bytes prefixBytes = Bytes.of(type.getNodeTypePrefix());
// Limit the scan to the binding set column and node id.
final RowScanner rows = sx.scanner().over(Span.prefix(prefixBytes)).fetch(bindingSetColumn).byRow().build();
BigInteger count = BigInteger.valueOf(0L);
for (ColumnScanner columns : rows) {
String row = BindingSetRow.makeFromShardedRow(prefixBytes, columns.getRow()).getNodeId();
if (row.equals(nodeId)) {
count = count.add(BigInteger.ONE);
}
}
return count;
}
use of org.apache.fluo.api.data.Bytes in project incubator-rya by apache.
the class JoinBatchBindingSetUpdater method processBatch.
/**
* Processes {@link JoinBatchInformation}. Updates the BindingSets
* associated with the specified nodeId. The BindingSets are processed in
* batch fashion, where the number of results is indicated by
* {@link JoinBatchInformation#getBatchSize()}. BindingSets are either
* Added, Deleted, or Updated according to
* {@link JoinBatchInformation#getTask()}. In the event that the number of
* entries that need to be updated exceeds the batch size, the row of the
* first unprocessed BindingSets is used to create a new JoinBatch job to
* process the remaining BindingSets.
* @throws Exception
*/
@Override
public void processBatch(final TransactionBase tx, final Bytes row, final BatchInformation batch) throws Exception {
super.processBatch(tx, row, batch);
final String nodeId = BatchRowKeyUtil.getNodeId(row);
Preconditions.checkArgument(batch instanceof JoinBatchInformation);
final JoinBatchInformation joinBatch = (JoinBatchInformation) batch;
final Task task = joinBatch.getTask();
// Figure out which join algorithm we are going to use.
final IterativeJoin joinAlgorithm;
switch(joinBatch.getJoinType()) {
case NATURAL_JOIN:
joinAlgorithm = new NaturalJoin();
break;
case LEFT_OUTER_JOIN:
joinAlgorithm = new LeftOuterJoin();
break;
default:
throw new RuntimeException("Unsupported JoinType: " + joinBatch.getJoinType());
}
final Set<VisibilityBindingSet> bsSet = new HashSet<>();
final Optional<RowColumn> rowCol = fillSiblingBatch(tx, joinBatch, bsSet);
// Iterates over the resulting BindingSets from the join.
final Iterator<VisibilityBindingSet> newJoinResults;
final VisibilityBindingSet bs = joinBatch.getBs();
if (joinBatch.getSide() == Side.LEFT) {
newJoinResults = joinAlgorithm.newLeftResult(bs, bsSet.iterator());
} else {
newJoinResults = joinAlgorithm.newRightResult(bsSet.iterator(), bs);
}
// Read join metadata, create new join BindingSets and insert them into the Fluo table.
final JoinMetadata joinMetadata = CACHE.readJoinMetadata(tx, nodeId);
final VariableOrder joinVarOrder = joinMetadata.getVariableOrder();
while (newJoinResults.hasNext()) {
final VisibilityBindingSet newJoinResult = newJoinResults.next();
// create BindingSet value
final Bytes bsBytes = BS_SERDE.serialize(newJoinResult);
// make rowId
Bytes rowKey = BindingHashShardingFunction.addShard(nodeId, joinVarOrder, newJoinResult);
final Column col = FluoQueryColumns.JOIN_BINDING_SET;
processTask(tx, task, rowKey, col, bsBytes);
}
// update the span and register updated batch job
if (rowCol.isPresent()) {
final Span newSpan = getNewSpan(rowCol.get(), joinBatch.getSpan());
joinBatch.setSpan(newSpan);
BatchInformationDAO.addBatch(tx, nodeId, joinBatch);
}
}
use of org.apache.fluo.api.data.Bytes in project incubator-rya by apache.
the class ConstructQueryResultUpdater method updateConstructQueryResults.
/**
* Updates the Construct Query results by applying the {@link ConnstructGraph} to
* create a {@link RyaSubGraph} and then writing the subgraph to {@link FluoQueryColumns#CONSTRUCT_STATEMENTS}.
* @param tx - transaction used to write the subgraph
* @param bs - BindingSet that the ConstructProjection expands into a subgraph
* @param metadata - metadata that the ConstructProjection is extracted from
*/
public void updateConstructQueryResults(TransactionBase tx, VisibilityBindingSet bs, ConstructQueryMetadata metadata) {
String nodeId = metadata.getNodeId();
VariableOrder varOrder = metadata.getVariableOrder();
Column column = FluoQueryColumns.CONSTRUCT_STATEMENTS;
ConstructGraph graph = metadata.getConstructGraph();
String parentId = metadata.getParentNodeId();
// Create the Row Key for the emitted binding set. It does not contain visibilities.
final Bytes resultRow = makeRowKey(nodeId, varOrder, bs);
// If this is a new binding set, then emit it.
if (tx.get(resultRow, column) == null || varOrder.getVariableOrders().size() < bs.size()) {
Set<RyaStatement> statements = graph.createGraphFromBindingSet(bs);
RyaSubGraph subgraph = new RyaSubGraph(parentId, statements);
final Bytes nodeValueBytes = Bytes.of(serializer.toBytes(subgraph));
log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "New Binding Set: " + subgraph + "\n");
tx.set(resultRow, column, nodeValueBytes);
}
}
use of org.apache.fluo.api.data.Bytes in project incubator-rya by apache.
the class VisibilityBindingSetSerDeTest method rejectUnexpectedClass.
/**
* Tests that deserializing an ArrayList should throw an error.
* if VisibilityBindingSet changes to include ArrayList, then this will need changing.
*
* @throws Exception
*/
@Test
public void rejectUnexpectedClass() throws Exception {
// cannot use VisibilityBindingSetSerDe.serialize here since it only serializes VisibilityBindingSet.
final ByteArrayOutputStream boas = new ByteArrayOutputStream();
try (final ObjectOutputStream oos = new ObjectOutputStream(boas)) {
oos.writeObject(new ArrayList<Integer>());
}
final Bytes bytes = Bytes.of(boas.toByteArray());
final VisibilityBindingSetSerDe serde = new VisibilityBindingSetSerDe();
// Should throw an InvalidClassException when deserializing the wrong class.
exception.expect(InvalidClassException.class);
serde.deserialize(bytes);
}
Aggregations