Search in sources :

Example 6 with NodeType

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();
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) Transaction(org.apache.fluo.api.client.Transaction) NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType) SpanBatchDeleteInformation(org.apache.rya.indexing.pcj.fluo.app.batch.SpanBatchDeleteInformation)

Example 7 with NodeType

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;
    }
}
Also used : NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType)

Example 8 with NodeType

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);
        }
    }
}
Also used : VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) ColumnScanner(org.apache.fluo.api.client.scanner.ColumnScanner) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) Snapshot(org.apache.fluo.api.client.Snapshot) Bytes(org.apache.fluo.api.data.Bytes) NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType) RowScanner(org.apache.fluo.api.client.scanner.RowScanner) ColumnValue(org.apache.fluo.api.data.ColumnValue) HashSet(java.util.HashSet)

Example 9 with NodeType

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.");
    }
}
Also used : NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType)

Example 10 with 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);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType) BindingSetRow(org.apache.rya.indexing.pcj.fluo.app.BindingSetRow)

Aggregations

NodeType (org.apache.rya.indexing.pcj.fluo.app.NodeType)15 Bytes (org.apache.fluo.api.data.Bytes)8 Transaction (org.apache.fluo.api.client.Transaction)5 ColumnScanner (org.apache.fluo.api.client.scanner.ColumnScanner)4 RowScanner (org.apache.fluo.api.client.scanner.RowScanner)4 ColumnValue (org.apache.fluo.api.data.ColumnValue)3 SpanBatchDeleteInformation (org.apache.rya.indexing.pcj.fluo.app.batch.SpanBatchDeleteInformation)3 HashSet (java.util.HashSet)2 Column (org.apache.fluo.api.data.Column)2 BindingSetRow (org.apache.rya.indexing.pcj.fluo.app.BindingSetRow)2 BigInteger (java.math.BigInteger)1 Snapshot (org.apache.fluo.api.client.Snapshot)1 RowColumn (org.apache.fluo.api.data.RowColumn)1 RyaURI (org.apache.rya.api.domain.RyaURI)1 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)1 AggregationMetadata (org.apache.rya.indexing.pcj.fluo.app.query.AggregationMetadata)1 ConstructQueryMetadata (org.apache.rya.indexing.pcj.fluo.app.query.ConstructQueryMetadata)1 FilterMetadata (org.apache.rya.indexing.pcj.fluo.app.query.FilterMetadata)1 JoinMetadata (org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata)1 PeriodicQueryMetadata (org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryMetadata)1