Search in sources :

Example 1 with Aggregator

use of org.apache.storm.trident.operation.Aggregator in project storm by apache.

the class ChainedAggregatorDeclarer method chainEnd.

public Stream chainEnd() {
    Fields[] inputFields = new Fields[_aggs.size()];
    Aggregator[] aggs = new Aggregator[_aggs.size()];
    int[] outSizes = new int[_aggs.size()];
    List<String> allOutFields = new ArrayList<>();
    Set<String> allInFields = new HashSet<>();
    for (int i = 0; i < _aggs.size(); i++) {
        AggSpec spec = _aggs.get(i);
        Fields infields = spec.inFields;
        if (infields == null)
            infields = new Fields();
        Fields outfields = spec.outFields;
        if (outfields == null)
            outfields = new Fields();
        inputFields[i] = infields;
        aggs[i] = spec.agg;
        outSizes[i] = outfields.size();
        allOutFields.addAll(outfields.toList());
        allInFields.addAll(infields.toList());
    }
    if (new HashSet(allOutFields).size() != allOutFields.size()) {
        throw new IllegalArgumentException("Output fields for chained aggregators must be distinct: " + allOutFields.toString());
    }
    Fields inFields = new Fields(new ArrayList<>(allInFields));
    Fields outFields = new Fields(allOutFields);
    Aggregator combined = new ChainedAggregatorImpl(aggs, inputFields, new ComboList.Factory(outSizes));
    if (_type != AggType.FULL) {
        _stream = _stream.partitionAggregate(inFields, combined, outFields);
    }
    if (_type != AggType.PARTITION) {
        _stream = _globalScheme.aggPartition(_stream);
        BatchToPartition singleEmit = _globalScheme.singleEmitPartitioner();
        Aggregator toAgg = combined;
        if (singleEmit != null) {
            toAgg = new SingleEmitAggregator(combined, singleEmit);
        }
        // this assumes that inFields and outFields are the same for combineragg
        // assumption also made above
        _stream = _stream.partitionAggregate(inFields, toAgg, outFields);
    }
    return _stream.toStream();
}
Also used : ComboList(org.apache.storm.trident.tuple.ComboList) ArrayList(java.util.ArrayList) SingleEmitAggregator(org.apache.storm.trident.operation.impl.SingleEmitAggregator) ReducerAggregator(org.apache.storm.trident.operation.ReducerAggregator) Aggregator(org.apache.storm.trident.operation.Aggregator) CombinerAggregator(org.apache.storm.trident.operation.CombinerAggregator) SingleEmitAggregator(org.apache.storm.trident.operation.impl.SingleEmitAggregator) Fields(org.apache.storm.tuple.Fields) ChainedAggregatorImpl(org.apache.storm.trident.operation.impl.ChainedAggregatorImpl) BatchToPartition(org.apache.storm.trident.operation.impl.SingleEmitAggregator.BatchToPartition) HashSet(java.util.HashSet)

Example 2 with Aggregator

use of org.apache.storm.trident.operation.Aggregator in project storm by apache.

the class GroupedStream method partitionAggregate.

@Override
public IAggregatableStream partitionAggregate(Fields inputFields, Aggregator agg, Fields functionFields) {
    Aggregator groupedAgg = new GroupedAggregator(agg, _groupFields, inputFields, functionFields.size());
    Fields allInFields = TridentUtils.fieldsUnion(_groupFields, inputFields);
    Fields allOutFields = TridentUtils.fieldsConcat(_groupFields, functionFields);
    Stream s = _stream.partitionAggregate(allInFields, groupedAgg, allOutFields);
    return new GroupedStream(s, _groupFields);
}
Also used : Fields(org.apache.storm.tuple.Fields) GroupedAggregator(org.apache.storm.trident.operation.impl.GroupedAggregator) ReducerAggregator(org.apache.storm.trident.operation.ReducerAggregator) GroupedAggregator(org.apache.storm.trident.operation.impl.GroupedAggregator) Aggregator(org.apache.storm.trident.operation.Aggregator) CombinerAggregator(org.apache.storm.trident.operation.CombinerAggregator) Stream(org.apache.storm.trident.Stream)

Aggregations

Aggregator (org.apache.storm.trident.operation.Aggregator)2 CombinerAggregator (org.apache.storm.trident.operation.CombinerAggregator)2 ReducerAggregator (org.apache.storm.trident.operation.ReducerAggregator)2 Fields (org.apache.storm.tuple.Fields)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Stream (org.apache.storm.trident.Stream)1 ChainedAggregatorImpl (org.apache.storm.trident.operation.impl.ChainedAggregatorImpl)1 GroupedAggregator (org.apache.storm.trident.operation.impl.GroupedAggregator)1 SingleEmitAggregator (org.apache.storm.trident.operation.impl.SingleEmitAggregator)1 BatchToPartition (org.apache.storm.trident.operation.impl.SingleEmitAggregator.BatchToPartition)1 ComboList (org.apache.storm.trident.tuple.ComboList)1