use of org.apache.rya.indexing.pcj.fluo.app.NodeType in project incubator-rya by apache.
the class DeleteFluoPcj method deleteData.
/**
* Deletes all results (BindingSets or Statements) associated with the specified nodeId.
*
* @param nodeId - nodeId whose {@link BindingSet}s will be deleted. (not null)
* @param client - Used to delete the data. (not null)
*/
private void deleteData(final FluoClient client, final String nodeId) {
requireNonNull(client);
requireNonNull(nodeId);
final NodeType type = NodeType.fromNodeId(nodeId).get();
Transaction tx = client.newTransaction();
Bytes prefixBytes = Bytes.of(type.getNodeTypePrefix());
SpanBatchDeleteInformation batch = SpanBatchDeleteInformation.builder().setColumn(type.getResultColumn()).setSpan(Span.prefix(prefixBytes)).setBatchSize(batchSize).setNodeId(Optional.of(nodeId)).build();
BatchInformationDAO.addBatch(tx, nodeId, batch);
tx.commit();
}
use of org.apache.rya.indexing.pcj.fluo.app.NodeType in project incubator-rya by apache.
the class FluoQueryMetadataDAO method addChildMetadata.
private void addChildMetadata(final SnapshotBase sx, final FluoQuery.Builder builder, final String childNodeId) {
requireNonNull(sx);
requireNonNull(builder);
requireNonNull(childNodeId);
final NodeType childType = NodeType.fromNodeId(childNodeId).get();
switch(childType) {
case QUERY:
// Add this node's metadata.
final QueryMetadata.Builder queryBuilder = readQueryMetadataBuilder(sx, childNodeId);
builder.setQueryMetadata(queryBuilder);
// Add it's child's metadata.
addChildMetadata(sx, builder, queryBuilder.build().getChildNodeId());
break;
case PROJECTION:
// Add this node's metadata
final ProjectionMetadata.Builder projectionBuilder = readProjectionMetadataBuilder(sx, childNodeId);
builder.addProjectionBuilder(projectionBuilder);
// Add it's child's metadata
addChildMetadata(sx, builder, projectionBuilder.build().getChildNodeId());
break;
case CONSTRUCT:
final ConstructQueryMetadata.Builder constructBuilder = readConstructQueryMetadataBuilder(sx, childNodeId);
builder.setConstructQueryMetadata(constructBuilder);
// Add it's child's metadata.
addChildMetadata(sx, builder, constructBuilder.build().getChildNodeId());
break;
case PERIODIC_QUERY:
// Add this node's metadata.
final PeriodicQueryMetadata.Builder periodicQueryBuilder = readPeriodicQueryMetadataBuilder(sx, childNodeId);
builder.addPeriodicQueryMetadata(periodicQueryBuilder);
// Add it's child's metadata.
addChildMetadata(sx, builder, periodicQueryBuilder.build().getChildNodeId());
break;
case AGGREGATION:
// Add this node's metadata.
final AggregationMetadata.Builder aggregationBuilder = readAggregationMetadataBuilder(sx, childNodeId);
builder.addAggregateMetadata(aggregationBuilder);
// Add it's child's metadata.
addChildMetadata(sx, builder, aggregationBuilder.build().getChildNodeId());
break;
case JOIN:
// Add this node's metadata.
final JoinMetadata.Builder joinBuilder = readJoinMetadataBuilder(sx, childNodeId);
builder.addJoinMetadata(joinBuilder);
// Add it's children's metadata.
final JoinMetadata joinMetadata = joinBuilder.build();
addChildMetadata(sx, builder, joinMetadata.getLeftChildNodeId());
addChildMetadata(sx, builder, joinMetadata.getRightChildNodeId());
break;
case FILTER:
// Add this node's metadata.
final FilterMetadata.Builder filterBuilder = readFilterMetadataBuilder(sx, childNodeId);
builder.addFilterMetadata(filterBuilder);
// Add it's child's metadata.
addChildMetadata(sx, builder, filterBuilder.build().getChildNodeId());
break;
case STATEMENT_PATTERN:
// Add this node's metadata.
final StatementPatternMetadata.Builder spBuilder = readStatementPatternMetadataBuilder(sx, childNodeId);
builder.addStatementPatternBuilder(spBuilder);
break;
default:
break;
}
}
use of org.apache.rya.indexing.pcj.fluo.app.NodeType 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.rya.indexing.pcj.fluo.app.NodeType in project incubator-rya by apache.
the class PeriodicQueryUtil method getPeriodicQueryNodeAncestorIds.
/**
* Collects all Metadata node Ids that are ancestors of the PeriodicQueryNode and contain the variable
* {@link IncrementalUpdateConstants#PERIODIC_BIN_ID}.
* @param sx - Fluo Snapshot for scanning Fluo
* @param nodeId - root node of the PeriodicQuery
* @param ids - query ids of all metadata nodes appearing between root and PeriodicQueryMetadata node
*/
public static void getPeriodicQueryNodeAncestorIds(SnapshotBase sx, String nodeId, Set<String> ids) {
NodeType nodeType = NodeType.fromNodeId(nodeId).orNull();
checkArgument(nodeType != null, "Invalid nodeId: " + nodeId + ". NodeId does not correspond to a valid NodeType.");
switch(nodeType) {
case FILTER:
ids.add(nodeId);
getPeriodicQueryNodeAncestorIds(sx, sx.get(Bytes.of(nodeId), FluoQueryColumns.FILTER_CHILD_NODE_ID).toString(), ids);
break;
case PERIODIC_QUERY:
ids.add(nodeId);
break;
case PROJECTION:
ids.add(nodeId);
getPeriodicQueryNodeAncestorIds(sx, sx.get(Bytes.of(nodeId), FluoQueryColumns.PROJECTION_CHILD_NODE_ID).toString(), ids);
break;
case QUERY:
ids.add(nodeId);
getPeriodicQueryNodeAncestorIds(sx, sx.get(Bytes.of(nodeId), FluoQueryColumns.QUERY_CHILD_NODE_ID).toString(), ids);
break;
case AGGREGATION:
ids.add(nodeId);
getPeriodicQueryNodeAncestorIds(sx, sx.get(Bytes.of(nodeId), FluoQueryColumns.AGGREGATION_CHILD_NODE_ID).toString(), ids);
break;
default:
throw new RuntimeException("Invalid NodeType.");
}
}
use of org.apache.rya.indexing.pcj.fluo.app.NodeType in project incubator-rya by apache.
the class ConstructQueryResultObserver method process.
@Override
public void process(TransactionBase tx, Bytes row, Column col) throws Exception {
// Build row for parent that result will be written to
BindingSetRow bsRow = BindingSetRow.makeFromShardedRow(Bytes.of(CONSTRUCT_PREFIX), row);
String constructNodeId = bsRow.getNodeId();
String bsString = bsRow.getBindingSetString();
String parentNodeId = queryDao.readMetadadataEntry(tx, constructNodeId, FluoQueryColumns.CONSTRUCT_PARENT_NODE_ID).toString();
Bytes rowBytes = BindingHashShardingFunction.getShardedScanPrefix(parentNodeId, bsString);
// Get NodeType of the parent node
NodeType parentType = NodeType.fromNodeId(parentNodeId).get();
// Get data for the ConstructQuery result
Bytes bytes = tx.get(row, col);
// Write result to parent
tx.set(rowBytes, parentType.getResultColumn(), bytes);
}
Aggregations