use of org.apache.fluo.api.data.ColumnValue in project incubator-rya by apache.
the class PeriodicNotificationProvider method getNotifications.
/**
* Retrieve all of the information about Periodic Query results already registered
* with Fluo. This is returned in the form of {@link CommandNotification}s that
* can be registered with the {@link NotificationCoordinatorExecutor}.
* @param sx - snapshot for reading results from Fluo
* @return - collection of CommandNotifications that indicate Periodic Query information registered with system
*/
public Collection<CommandNotification> getNotifications(Snapshot sx) {
Set<PeriodicQueryMetadata> periodicMetadata = new HashSet<>();
RowScanner scanner = sx.scanner().fetch(FluoQueryColumns.PERIODIC_QUERY_NODE_ID).over(Span.prefix(IncrementalUpdateConstants.PERIODIC_QUERY_PREFIX)).byRow().build();
Iterator<ColumnScanner> colScannerIter = scanner.iterator();
while (colScannerIter.hasNext()) {
ColumnScanner colScanner = colScannerIter.next();
Iterator<ColumnValue> values = colScanner.iterator();
while (values.hasNext()) {
PeriodicQueryMetadata metadata = dao.readPeriodicQueryMetadata(sx, values.next().getsValue());
periodicMetadata.add(metadata);
}
}
return getCommandNotifications(sx, periodicMetadata);
}
use of org.apache.fluo.api.data.ColumnValue in project incubator-rya by apache.
the class BatchIT method countResults.
private int countResults(FluoClient fluoClient, String nodeId, Column bsColumn) {
try (Transaction tx = fluoClient.newTransaction()) {
int count = 0;
Optional<NodeType> type = NodeType.fromNodeId(nodeId);
Bytes prefixBytes = Bytes.of(type.get().getNodeTypePrefix());
RowScanner scanner = tx.scanner().over(Span.prefix(prefixBytes)).fetch(bsColumn).byRow().build();
Iterator<ColumnScanner> colScanners = scanner.iterator();
while (colScanners.hasNext()) {
ColumnScanner colScanner = colScanners.next();
BindingSetRow bsRow = BindingSetRow.makeFromShardedRow(prefixBytes, colScanner.getRow());
if (bsRow.getNodeId().equals(nodeId)) {
Iterator<ColumnValue> vals = colScanner.iterator();
while (vals.hasNext()) {
vals.next();
count++;
}
}
}
tx.commit();
return count;
}
}
use of org.apache.fluo.api.data.ColumnValue in project incubator-rya by apache.
the class PeriodicNotificationBinPrunerIT method compareFluoCounts.
private void compareFluoCounts(FluoClient client, String pcjId, long bin) {
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding(IncrementalUpdateConstants.PERIODIC_BIN_ID, new LiteralImpl(Long.toString(bin), XMLSchema.LONG));
VariableOrder varOrder = new VariableOrder(IncrementalUpdateConstants.PERIODIC_BIN_ID);
try (Snapshot sx = client.newSnapshot()) {
String fluoQueryId = NodeType.generateNewIdForType(NodeType.QUERY, pcjId);
Set<String> ids = new HashSet<>();
PeriodicQueryUtil.getPeriodicQueryNodeAncestorIds(sx, fluoQueryId, ids);
for (String id : ids) {
NodeType optNode = NodeType.fromNodeId(id).orNull();
if (optNode == null)
throw new RuntimeException("Invalid NodeType.");
Bytes prefix = RowKeyUtil.makeRowKey(id, varOrder, bs);
RowScanner scanner = sx.scanner().fetch(optNode.getResultColumn()).over(Span.prefix(prefix)).byRow().build();
int count = 0;
Iterator<ColumnScanner> colScannerIter = scanner.iterator();
while (colScannerIter.hasNext()) {
ColumnScanner colScanner = colScannerIter.next();
String row = colScanner.getRow().toString();
Iterator<ColumnValue> values = colScanner.iterator();
while (values.hasNext()) {
values.next();
count++;
}
}
Assert.assertEquals(0, count);
}
}
}
use of org.apache.fluo.api.data.ColumnValue 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();
}
}
use of org.apache.fluo.api.data.ColumnValue in project incubator-rya by apache.
the class SpanBatchBindingSetUpdater method deleteBatch.
private Optional<RowColumn> deleteBatch(TransactionBase tx, Optional<String> nodeId, Span span, Column column, int batchSize) {
log.trace("Deleting batch of size: " + batchSize + " using Span: " + span + " and Column: " + column);
RowScanner rs = tx.scanner().over(span).fetch(column).byRow().build();
try {
Iterator<ColumnScanner> colScannerIter = rs.iterator();
int count = 0;
boolean batchLimitMet = false;
Bytes row = span.getStart().getRow();
// get prefix if nodeId is specified
Optional<Bytes> prefixBytes = Optional.empty();
if (nodeId.isPresent()) {
NodeType type = NodeType.fromNodeId(nodeId.get()).get();
prefixBytes = Optional.ofNullable(Bytes.of(type.getNodeTypePrefix()));
}
while (colScannerIter.hasNext() && !batchLimitMet) {
ColumnScanner colScanner = colScannerIter.next();
row = colScanner.getRow();
// extract the nodeId from the returned row if a nodeId was passed
// into the SpanBatchInformation. This is to ensure that the returned
// row nodeId is equal to the nodeId passed in to the span batch information
Optional<String> rowNodeId = Optional.empty();
if (prefixBytes.isPresent()) {
rowNodeId = Optional.of(BindingSetRow.makeFromShardedRow(prefixBytes.get(), row).getNodeId());
}
// on the nodeId. This occurs when the hash is not included in the span
if (!rowNodeId.isPresent() || rowNodeId.equals(nodeId)) {
Iterator<ColumnValue> iter = colScanner.iterator();
while (iter.hasNext()) {
if (count >= batchSize) {
batchLimitMet = true;
break;
}
ColumnValue colVal = iter.next();
tx.delete(row, colVal.getColumn());
count++;
}
}
}
if (batchLimitMet) {
return Optional.of(new RowColumn(row));
} else {
return Optional.empty();
}
} catch (Exception e) {
return Optional.empty();
}
}
Aggregations