Search in sources :

Example 1 with AggregationMetadata

use of org.apache.rya.indexing.pcj.fluo.app.query.AggregationMetadata 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 2 with AggregationMetadata

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

the class BindingSetUpdater method process.

@Override
public final void process(final TransactionBase tx, final Bytes row, final Column col) {
    checkNotNull(tx);
    checkNotNull(row);
    checkNotNull(col);
    final Observation observation;
    try {
        observation = parseObservation(tx, row);
    } catch (final Exception e) {
        log.error("Unable to parse an Observation from a Row and Column pair, so this notification will be skipped. " + "Row: " + row + " Column: " + col, e);
        return;
    }
    final String observedNodeId = observation.getObservedNodeId();
    final VisibilityBindingSet observedBindingSet = observation.getObservedBindingSet();
    final String parentNodeId = observation.getParentId();
    // Figure out which node needs to handle the new metadata.
    final NodeType parentNodeType = NodeType.fromNodeId(parentNodeId).get();
    switch(parentNodeType) {
        case QUERY:
            final QueryMetadata parentQuery = queryDao.readQueryMetadata(tx, parentNodeId);
            try {
                queryUpdater.updateQueryResults(tx, observedBindingSet, parentQuery);
            } catch (final Exception e) {
                throw new RuntimeException("Could not process a Query node.", e);
            }
            break;
        case PROJECTION:
            final ProjectionMetadata projectionQuery = queryDao.readProjectionMetadata(tx, parentNodeId);
            try {
                projectionUpdater.updateProjectionResults(tx, observedBindingSet, projectionQuery);
            } catch (final Exception e) {
                throw new RuntimeException("Could not process a Query node.", e);
            }
            break;
        case CONSTRUCT:
            final ConstructQueryMetadata constructQuery = queryDao.readConstructQueryMetadata(tx, parentNodeId);
            try {
                constructUpdater.updateConstructQueryResults(tx, observedBindingSet, constructQuery);
            } catch (final Exception e) {
                throw new RuntimeException("Could not process a Query node.", e);
            }
            break;
        case FILTER:
            final FilterMetadata parentFilter = queryDao.readFilterMetadata(tx, parentNodeId);
            try {
                filterUpdater.updateFilterResults(tx, observedBindingSet, parentFilter);
            } catch (final Exception e) {
                throw new RuntimeException("Could not process a Filter node.", e);
            }
            break;
        case JOIN:
            final JoinMetadata parentJoin = queryDao.readJoinMetadata(tx, parentNodeId);
            try {
                joinUpdater.updateJoinResults(tx, observedNodeId, observedBindingSet, parentJoin);
            } catch (final Exception e) {
                throw new RuntimeException("Could not process a Join node.", e);
            }
            break;
        case PERIODIC_QUERY:
            final PeriodicQueryMetadata parentPeriodicQuery = queryDao.readPeriodicQueryMetadata(tx, parentNodeId);
            try {
                periodicQueryUpdater.updatePeriodicBinResults(tx, observedBindingSet, parentPeriodicQuery);
            } catch (Exception e) {
                throw new RuntimeException("Could not process PeriodicBin node.", e);
            }
            break;
        case AGGREGATION:
            final AggregationMetadata parentAggregation = queryDao.readAggregationMetadata(tx, parentNodeId);
            try {
                aggregationUpdater.updateAggregateResults(tx, observedBindingSet, parentAggregation);
            } catch (final Exception e) {
                throw new RuntimeException("Could not process an Aggregation node.", e);
            }
            break;
        default:
            throw new IllegalArgumentException("The parent node's NodeType must be of type Aggregation, Projection, ConstructQuery, Filter, Join, PeriodicBin or Query, but was " + parentNodeType);
    }
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ConstructQueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.ConstructQueryMetadata) QueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.QueryMetadata) PeriodicQueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryMetadata) PeriodicQueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryMetadata) ProjectionMetadata(org.apache.rya.indexing.pcj.fluo.app.query.ProjectionMetadata) JoinMetadata(org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata) NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType) FilterMetadata(org.apache.rya.indexing.pcj.fluo.app.query.FilterMetadata) AggregationMetadata(org.apache.rya.indexing.pcj.fluo.app.query.AggregationMetadata) ConstructQueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.ConstructQueryMetadata)

Aggregations

VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)2 AggregationMetadata (org.apache.rya.indexing.pcj.fluo.app.query.AggregationMetadata)2 Bytes (org.apache.fluo.api.data.Bytes)1 AggregationState (org.apache.rya.api.function.aggregation.AggregationState)1 NodeType (org.apache.rya.indexing.pcj.fluo.app.NodeType)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 ProjectionMetadata (org.apache.rya.indexing.pcj.fluo.app.query.ProjectionMetadata)1 QueryMetadata (org.apache.rya.indexing.pcj.fluo.app.query.QueryMetadata)1