Search in sources :

Example 1 with Bytes

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();
    }
}
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 Bytes

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;
}
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 Bytes

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);
    }
}
Also used : Task(org.apache.rya.indexing.pcj.fluo.app.batch.BatchInformation.Task) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) RowColumn(org.apache.fluo.api.data.RowColumn) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) IterativeJoin(org.apache.rya.api.function.join.IterativeJoin) JoinMetadata(org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata) Span(org.apache.fluo.api.data.Span) Bytes(org.apache.fluo.api.data.Bytes) RowColumn(org.apache.fluo.api.data.RowColumn) Column(org.apache.fluo.api.data.Column) NaturalJoin(org.apache.rya.api.function.join.NaturalJoin) LeftOuterJoin(org.apache.rya.api.function.join.LeftOuterJoin) HashSet(java.util.HashSet)

Example 4 with Bytes

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);
    }
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) RyaSubGraph(org.apache.rya.api.domain.RyaSubGraph) Column(org.apache.fluo.api.data.Column) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) RyaStatement(org.apache.rya.api.domain.RyaStatement)

Example 5 with Bytes

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);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Test(org.junit.Test)

Aggregations

Bytes (org.apache.fluo.api.data.Bytes)43 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)16 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)14 Column (org.apache.fluo.api.data.Column)9 Test (org.junit.Test)9 ColumnScanner (org.apache.fluo.api.client.scanner.ColumnScanner)8 RowScanner (org.apache.fluo.api.client.scanner.RowScanner)8 NodeType (org.apache.rya.indexing.pcj.fluo.app.NodeType)8 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)6 FluoClient (org.apache.fluo.api.client.FluoClient)5 ColumnValue (org.apache.fluo.api.data.ColumnValue)5 RowColumn (org.apache.fluo.api.data.RowColumn)5 Span (org.apache.fluo.api.data.Span)5 Transaction (org.apache.fluo.api.client.Transaction)4 RyaStatement (org.apache.rya.api.domain.RyaStatement)4 HashSet (java.util.HashSet)3 Snapshot (org.apache.fluo.api.client.Snapshot)3 RyaURI (org.apache.rya.api.domain.RyaURI)3 JoinBatchInformation (org.apache.rya.indexing.pcj.fluo.app.batch.JoinBatchInformation)3 SpanBatchDeleteInformation (org.apache.rya.indexing.pcj.fluo.app.batch.SpanBatchDeleteInformation)3