Search in sources :

Example 26 with Bytes

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

the class StatementPatternObserver method parseObservation.

@Override
public Observation parseObservation(final TransactionBase tx, final Bytes row) throws Exception {
    requireNonNull(tx);
    requireNonNull(row);
    // Make nodeId and get the Statement Pattern metadata.
    final String spNodeId = BindingSetRow.makeFromShardedRow(Bytes.of(SP_PREFIX), row).getNodeId();
    final StatementPatternMetadata spMetadata = queryDao.readStatementPatternMetadata(tx, spNodeId);
    // Read the Visibility Binding Set from the value.
    final Bytes valueBytes = tx.get(row, FluoQueryColumns.STATEMENT_PATTERN_BINDING_SET);
    final VisibilityBindingSet spBindingSet = BS_SERDE.deserialize(valueBytes);
    // Figure out which node needs to handle the new metadata.
    final String parentNodeId = spMetadata.getParentNodeId();
    return new Observation(spNodeId, spBindingSet, parentNodeId);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) StatementPatternMetadata(org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata)

Example 27 with Bytes

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

the class AggregationObserver method parseObservation.

@Override
public Observation parseObservation(final TransactionBase tx, final Bytes row) {
    requireNonNull(tx);
    requireNonNull(row);
    // Make nodeId and fetch the Aggregation node's metadata.
    final String nodeId = BindingSetRow.makeFromShardedRow(Bytes.of(AGGREGATION_PREFIX), row).getNodeId();
    final AggregationMetadata metadata = queryDao.readAggregationMetadata(tx, nodeId);
    // Read the Visibility Binding Set from the value.
    final Bytes stateBytes = tx.get(row, FluoQueryColumns.AGGREGATION_BINDING_SET);
    final AggregationState state = STATE_SERDE.deserialize(stateBytes.toArray());
    final VisibilityBindingSet aggBindingSet = new VisibilityBindingSet(state.getBindingSet(), state.getVisibility());
    // Figure out which node needs to handle the new metadata.
    final String parentNodeId = metadata.getParentNodeId();
    return new Observation(nodeId, aggBindingSet, parentNodeId);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) AggregationMetadata(org.apache.rya.indexing.pcj.fluo.app.query.AggregationMetadata) AggregationState(org.apache.rya.api.function.aggregation.AggregationState)

Example 28 with Bytes

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

the class BindingHashShardingFunction method addShard.

/**
 * Generates a sharded rowId. The rowId is of the form: node_prefix:shardId:nodeId//Binding_values. For
 * example, the row key generated from nodeId = SP_123, varOrder = a;b, bs = [a = uri:Bob, b = uri:Doug] would be
 * SP:HASH(uri:Bob):123//uri:Bob;uri:Doug, where HASH(uri:Bob) indicates the shard id hash generated from the
 * Binding value "uri:Bob".
 *
 * @param nodeId - Node Id with type and UUID
 * @param varOrder - VarOrder used to order BindingSet values
 * @param bs - BindingSet with partially formed query values
 * @return - serialized Bytes rowId for storing BindingSet results in Fluo
 */
public static Bytes addShard(String nodeId, VariableOrder varOrder, VisibilityBindingSet bs) {
    checkNotNull(nodeId);
    checkNotNull(varOrder);
    checkNotNull(bs);
    String[] rowPrefixAndId = nodeId.split("_");
    Preconditions.checkArgument(rowPrefixAndId.length == 2);
    String prefix = rowPrefixAndId[0];
    String id = rowPrefixAndId[1];
    String firstBindingString = "";
    Bytes rowSuffix = Bytes.of(id);
    if (varOrder.getVariableOrders().size() > 0) {
        VariableOrder first = new VariableOrder(varOrder.getVariableOrders().get(0));
        firstBindingString = BS_CONVERTER.convert(bs, first);
        rowSuffix = RowKeyUtil.makeRowKey(id, varOrder, bs);
    }
    BytesBuilder builder = Bytes.builder();
    builder.append(Bytes.of(prefix + ":"));
    builder.append(genHash(Bytes.of(id + NODEID_BS_DELIM + firstBindingString)));
    builder.append(":");
    builder.append(rowSuffix);
    return builder.toBytes();
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) BytesBuilder(org.apache.fluo.api.data.Bytes.BytesBuilder)

Example 29 with Bytes

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

the class ProjectionResultUpdater method updateProjectionResults.

/**
 * Updates the results of a Projection node when one of its children 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 emmitted. (not null)
 * @param projectionMetadata - The metadata of the Query whose results will be updated. (not null)
 * @throws Exception A problem caused the update to fail.
 */
public void updateProjectionResults(final TransactionBase tx, final VisibilityBindingSet childBindingSet, final ProjectionMetadata projectionMetadata) throws Exception {
    checkNotNull(tx);
    checkNotNull(childBindingSet);
    checkNotNull(projectionMetadata);
    log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "Node ID: " + projectionMetadata.getNodeId() + "\n" + "Parent Node ID: " + projectionMetadata.getParentNodeId() + "\n" + "Child Node ID: " + projectionMetadata.getChildNodeId() + "\n" + "Child Binding Set:\n" + childBindingSet + "\n");
    // Create the query's Binding Set from the child node's binding set.
    final VariableOrder queryVarOrder = projectionMetadata.getVariableOrder();
    final VariableOrder projectionVarOrder = projectionMetadata.getProjectedVars();
    final BindingSet queryBindingSet = BindingSetUtil.keepBindings(projectionVarOrder, childBindingSet);
    VisibilityBindingSet projectedBs = new VisibilityBindingSet(queryBindingSet, childBindingSet.getVisibility());
    // Create the Row Key for the result. If the child node groups results, then the key must only contain the Group By variables.
    Bytes resultRow = makeRowKey(projectionMetadata.getNodeId(), queryVarOrder, projectedBs);
    // Create the Binding Set that goes in the Node Value. It does contain visibilities.
    final Bytes nodeValueBytes = BS_SERDE.serialize(projectedBs);
    log.trace("Transaction ID: " + tx.getStartTimestamp() + "\n" + "New Binding Set: " + childBindingSet + "\n");
    tx.set(resultRow, FluoQueryColumns.PROJECTION_BINDING_SET, nodeValueBytes);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) Bytes(org.apache.fluo.api.data.Bytes) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)

Example 30 with Bytes

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

the class JoinBatchBindingSetUpdater method fillSiblingBatch.

/**
 * Fetches batch to be processed by scanning over the Span specified by the
 * {@link JoinBatchInformation}. The number of results is less than or equal
 * to the batch size specified by the JoinBatchInformation.
 *
 * @param tx - Fluo transaction in which batch operation is performed
 * @param batch - batch order to be processed
 * @param bsSet- set that batch results are added to
 * @return Set - containing results of sibling scan.
 * @throws Exception
 */
private Optional<RowColumn> fillSiblingBatch(final TransactionBase tx, final JoinBatchInformation batch, final Set<VisibilityBindingSet> bsSet) throws Exception {
    final Span span = batch.getSpan();
    final Column column = batch.getColumn();
    final int batchSize = batch.getBatchSize();
    final RowScanner rs = tx.scanner().over(span).fetch(column).byRow().build();
    final Iterator<ColumnScanner> colScannerIter = rs.iterator();
    boolean batchLimitMet = false;
    Bytes row = span.getStart().getRow();
    while (colScannerIter.hasNext() && !batchLimitMet) {
        final ColumnScanner colScanner = colScannerIter.next();
        row = colScanner.getRow();
        final Iterator<ColumnValue> iter = colScanner.iterator();
        while (iter.hasNext()) {
            if (bsSet.size() >= batchSize) {
                batchLimitMet = true;
                break;
            }
            bsSet.add(BS_SERDE.deserialize(iter.next().getValue()));
        }
    }
    if (batchLimitMet) {
        return Optional.of(new RowColumn(row, column));
    } else {
        return Optional.empty();
    }
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) RowColumn(org.apache.fluo.api.data.RowColumn) Column(org.apache.fluo.api.data.Column) RowColumn(org.apache.fluo.api.data.RowColumn) RowScanner(org.apache.fluo.api.client.scanner.RowScanner) ColumnScanner(org.apache.fluo.api.client.scanner.ColumnScanner) ColumnValue(org.apache.fluo.api.data.ColumnValue) Span(org.apache.fluo.api.data.Span)

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