Search in sources :

Example 1 with NodeType

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

Example 2 with NodeType

use of org.apache.rya.indexing.pcj.fluo.app.NodeType 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;
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType) RowScanner(org.apache.fluo.api.client.scanner.RowScanner) BigInteger(java.math.BigInteger) ColumnScanner(org.apache.fluo.api.client.scanner.ColumnScanner)

Example 3 with NodeType

use of org.apache.rya.indexing.pcj.fluo.app.NodeType in project incubator-rya by apache.

the class PeriodicNotificationProvider method getQueryIdFromPeriodicId.

private String getQueryIdFromPeriodicId(Snapshot sx, String nodeId) {
    NodeType nodeType = NodeType.fromNodeId(nodeId).orNull();
    String id = null;
    switch(nodeType) {
        case FILTER:
            id = getQueryIdFromPeriodicId(sx, sx.get(Bytes.of(nodeId), FluoQueryColumns.FILTER_PARENT_NODE_ID).toString());
            break;
        case PERIODIC_QUERY:
            id = getQueryIdFromPeriodicId(sx, sx.get(Bytes.of(nodeId), FluoQueryColumns.PERIODIC_QUERY_PARENT_NODE_ID).toString());
            break;
        case QUERY:
            id = FluoQueryUtils.convertFluoQueryIdToPcjId(nodeId);
            break;
        case AGGREGATION:
            id = getQueryIdFromPeriodicId(sx, sx.get(Bytes.of(nodeId), FluoQueryColumns.AGGREGATION_PARENT_NODE_ID).toString());
            break;
        case CONSTRUCT:
            id = getQueryIdFromPeriodicId(sx, sx.get(Bytes.of(nodeId), FluoQueryColumns.CONSTRUCT_PARENT_NODE_ID).toString());
            break;
        case PROJECTION:
            id = getQueryIdFromPeriodicId(sx, sx.get(Bytes.of(nodeId), FluoQueryColumns.PROJECTION_PARENT_NODE_ID).toString());
            break;
        default:
            throw new IllegalArgumentException("Invalid node type");
    }
    return id;
}
Also used : NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType)

Example 4 with NodeType

use of org.apache.rya.indexing.pcj.fluo.app.NodeType in project incubator-rya by apache.

the class BatchIT method createSpanBatches.

private void createSpanBatches(FluoClient fluoClient, List<String> ids, List<String> prefixes, int batchSize) {
    Preconditions.checkArgument(ids.size() == prefixes.size());
    try (Transaction tx = fluoClient.newTransaction()) {
        for (int i = 0; i < ids.size(); i++) {
            String id = ids.get(i);
            String bsPrefix = prefixes.get(i);
            URI uri = vf.createURI(bsPrefix);
            Bytes prefixBytes = BindingHashShardingFunction.getShardedScanPrefix(id, uri);
            NodeType type = NodeType.fromNodeId(id).get();
            Column bsCol = type.getResultColumn();
            SpanBatchDeleteInformation.Builder builder = SpanBatchDeleteInformation.builder().setBatchSize(batchSize).setColumn(bsCol);
            if (type == NodeType.JOIN) {
                builder.setSpan(Span.prefix(type.getNodeTypePrefix()));
                builder.setNodeId(java.util.Optional.of(id));
            } else {
                builder.setSpan(Span.prefix(prefixBytes));
            }
            BatchInformationDAO.addBatch(tx, id, builder.build());
        }
        tx.commit();
    }
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) Transaction(org.apache.fluo.api.client.Transaction) Column(org.apache.fluo.api.data.Column) NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) SpanBatchDeleteInformation(org.apache.rya.indexing.pcj.fluo.app.batch.SpanBatchDeleteInformation)

Example 5 with NodeType

use of org.apache.rya.indexing.pcj.fluo.app.NodeType 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;
    }
}
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) BindingSetRow(org.apache.rya.indexing.pcj.fluo.app.BindingSetRow) RowScanner(org.apache.fluo.api.client.scanner.RowScanner) ColumnScanner(org.apache.fluo.api.client.scanner.ColumnScanner) ColumnValue(org.apache.fluo.api.data.ColumnValue)

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