Search in sources :

Example 11 with Bytes

use of org.apache.fluo.api.data.Bytes in project incubator-rya by apache.

the class CreateDeletePeriodicPCJ method getFluoTableEntries.

private List<Bytes> getFluoTableEntries(final FluoClient fluoClient) {
    try (Snapshot snapshot = fluoClient.newSnapshot()) {
        final List<Bytes> rows = new ArrayList<>();
        final RowScanner rscanner = snapshot.scanner().over(Span.prefix("")).byRow().build();
        for (final ColumnScanner cscanner : rscanner) {
            rows.add(cscanner.getRow());
        }
        return rows;
    }
}
Also used : Snapshot(org.apache.fluo.api.client.Snapshot) Bytes(org.apache.fluo.api.data.Bytes) ArrayList(java.util.ArrayList) RowScanner(org.apache.fluo.api.client.scanner.RowScanner) ColumnScanner(org.apache.fluo.api.client.scanner.ColumnScanner)

Example 12 with Bytes

use of org.apache.fluo.api.data.Bytes in project incubator-rya by apache.

the class DeleteFluoPcj method deleteMetadataColumns.

/**
 * Deletes all metadata for a Query Node.
 *
 * @param tx - Transaction the deletes will be performed with. (not null)
 * @param nodeId - The Node ID of the query node to delete. (not null)
 * @param columns - The columns that will be deleted. (not null)
 */
private void deleteMetadataColumns(final Transaction tx, final String nodeId, final List<Column> columns) {
    requireNonNull(tx);
    requireNonNull(columns);
    requireNonNull(nodeId);
    final Bytes row = Bytes.of(nodeId);
    for (final Column column : columns) {
        tx.delete(row, column);
    }
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) Column(org.apache.fluo.api.data.Column)

Example 13 with Bytes

use of org.apache.fluo.api.data.Bytes 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 14 with Bytes

use of org.apache.fluo.api.data.Bytes in project incubator-rya by apache.

the class FilterResultUpdater method updateFilterResults.

/**
 * Updates the results of a Filter node when one of its child has added a
 * new Binding Set to its results.
 *
 * @param tx - The transaction all Fluo queries will use. (not null)
 * @param childBindingSet - A binding set that the query's child node has emitted. (not null)
 * @param filterMetadata - The metadata of the Filter whose results will be updated. (not null)
 * @throws Exception Something caused the update to fail.
 */
public void updateFilterResults(final TransactionBase tx, final VisibilityBindingSet childBindingSet, final FilterMetadata filterMetadata) throws Exception {
    checkNotNull(tx);
    checkNotNull(childBindingSet);
    checkNotNull(filterMetadata);
    log.trace("Transaction ID: {}\nFilter Node ID: {}\nBinding Set:\n{}\n", tx.getStartTimestamp(), filterMetadata.getNodeId(), childBindingSet);
    // Parse the original query and find the Filter that represents filterId.
    final String sparql = filterMetadata.getFilterSparql();
    final Filter filter = FilterSerializer.deserialize(sparql);
    // Evaluate whether the child BindingSet satisfies the filter's condition.
    final ValueExpr condition = filter.getCondition();
    if (isTrue(condition, childBindingSet)) {
        // Create the Row Key for the emitted binding set. It does not contain visibilities.
        final VariableOrder filterVarOrder = filterMetadata.getVariableOrder();
        final Bytes resultRow = makeRowKey(filterMetadata.getNodeId(), filterVarOrder, childBindingSet);
        // Serialize and emit BindingSet
        final Bytes nodeValueBytes = BS_SERDE.serialize(childBindingSet);
        log.trace("Transaction ID: {}\nNew Binding Set: {}\n", tx.getStartTimestamp(), childBindingSet);
        tx.set(resultRow, FluoQueryColumns.FILTER_BINDING_SET, nodeValueBytes);
    }
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) Bytes(org.apache.fluo.api.data.Bytes) Filter(org.openrdf.query.algebra.Filter) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)

Example 15 with Bytes

use of org.apache.fluo.api.data.Bytes in project incubator-rya by apache.

the class JoinResultUpdater method getSpan.

/**
 * Creates a Span for the sibling node to retrieve BindingSets to join with
 * @param tx
 * @param childId - Id of the node that was updated
 * @param childBindingSet - BindingSet update
 * @param siblingId - Id of the sibling node whose BindingSets will be retrieved and joined with the update
 * @return Span to retrieve sibling node's BindingSets to form join results
 */
private Span getSpan(TransactionBase tx, final String childId, final VisibilityBindingSet childBindingSet, final String siblingId) {
    // Get the common variable orders. These are used to build the prefix.
    final VariableOrder childVarOrder = getVarOrder(tx, childId);
    final VariableOrder siblingVarOrder = getVarOrder(tx, siblingId);
    final List<String> commonVars = getCommonVars(childVarOrder, siblingVarOrder);
    Bytes siblingScanPrefix = null;
    if (!commonVars.isEmpty()) {
        siblingScanPrefix = makeRowKey(siblingId, new VariableOrder(commonVars), childBindingSet);
    } else {
        siblingScanPrefix = makeRowKey(siblingId, siblingVarOrder, childBindingSet);
    }
    return Span.prefix(siblingScanPrefix);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)

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