Search in sources :

Example 1 with Fields

use of backtype.storm.tuple.Fields in project storm by nathanmarz.

the class TridentTopology method multiReduce.

public Stream multiReduce(List<Fields> inputFields, List<GroupedStream> groupedStreams, GroupedMultiReducer function, Fields outputFields) {
    List<Fields> fullInputFields = new ArrayList<Fields>();
    List<Stream> streams = new ArrayList<Stream>();
    List<Fields> fullGroupFields = new ArrayList<Fields>();
    for (int i = 0; i < groupedStreams.size(); i++) {
        GroupedStream gs = groupedStreams.get(i);
        Fields groupFields = gs.getGroupFields();
        fullGroupFields.add(groupFields);
        streams.add(gs.toStream().partitionBy(groupFields));
        fullInputFields.add(TridentUtils.fieldsUnion(groupFields, inputFields.get(i)));
    }
    return multiReduce(fullInputFields, streams, new GroupedMultiReducerExecutor(function, fullGroupFields, inputFields), outputFields);
}
Also used : Fields(backtype.storm.tuple.Fields) GroupedStream(storm.trident.fluent.GroupedStream) GroupedMultiReducerExecutor(storm.trident.operation.impl.GroupedMultiReducerExecutor) ArrayList(java.util.ArrayList) GroupedStream(storm.trident.fluent.GroupedStream) IAggregatableStream(storm.trident.fluent.IAggregatableStream)

Example 2 with Fields

use of backtype.storm.tuple.Fields in project storm by nathanmarz.

the class TridentTopology method newStaticState.

public TridentState newStaticState(StateSpec spec) {
    String stateId = getUniqueStateId();
    Node n = new Node(getUniqueStreamId(), null, new Fields());
    n.stateInfo = new NodeStateInfo(stateId, spec);
    registerNode(n);
    return new TridentState(this, n);
}
Also used : Fields(backtype.storm.tuple.Fields) NodeStateInfo(storm.trident.planner.NodeStateInfo) SpoutNode(storm.trident.planner.SpoutNode) ProcessorNode(storm.trident.planner.ProcessorNode) PartitionNode(storm.trident.planner.PartitionNode) Node(storm.trident.planner.Node)

Example 3 with Fields

use of backtype.storm.tuple.Fields in project storm by nathanmarz.

the class TridentTopology method completeDRPC.

private static void completeDRPC(DefaultDirectedGraph<Node, IndexedEdge> graph, Map<String, List<Node>> colocate, UniqueIdGen gen) {
    List<Set<Node>> connectedComponents = new ConnectivityInspector<Node, IndexedEdge>(graph).connectedSets();
    for (Set<Node> g : connectedComponents) {
        checkValidJoins(g);
    }
    TridentTopology helper = new TridentTopology(graph, colocate, gen);
    for (Set<Node> g : connectedComponents) {
        SpoutNode drpcNode = getDRPCSpoutNode(g);
        if (drpcNode != null) {
            Stream lastStream = new Stream(helper, null, getLastAddedNode(g));
            Stream s = new Stream(helper, null, drpcNode);
            helper.multiReduce(s.project(new Fields("return-info")).batchGlobal(), lastStream.batchGlobal(), new ReturnResultsReducer(), new Fields());
        }
    }
}
Also used : IndexedEdge(storm.trident.util.IndexedEdge) Set(java.util.Set) HashSet(java.util.HashSet) Fields(backtype.storm.tuple.Fields) SpoutNode(storm.trident.planner.SpoutNode) SpoutNode(storm.trident.planner.SpoutNode) ProcessorNode(storm.trident.planner.ProcessorNode) PartitionNode(storm.trident.planner.PartitionNode) Node(storm.trident.planner.Node) GroupedStream(storm.trident.fluent.GroupedStream) IAggregatableStream(storm.trident.fluent.IAggregatableStream) ReturnResultsReducer(storm.trident.drpc.ReturnResultsReducer)

Example 4 with Fields

use of backtype.storm.tuple.Fields in project storm by nathanmarz.

the class TridentTopology method newDRPCStream.

private Stream newDRPCStream(DRPCSpout spout) {
    // TODO: consider adding a shuffle grouping after the spout to avoid so much routing of the args/return-info all over the place
    // (at least until its possible to just pack bolt logic into the spout itself)
    Node n = new SpoutNode(getUniqueStreamId(), TridentUtils.getSingleOutputStreamFields(spout), null, spout, SpoutNode.SpoutType.DRPC);
    Stream nextStream = addNode(n);
    // later on, this will be joined back with return-info and all the results
    return nextStream.project(new Fields("args"));
}
Also used : Fields(backtype.storm.tuple.Fields) SpoutNode(storm.trident.planner.SpoutNode) SpoutNode(storm.trident.planner.SpoutNode) ProcessorNode(storm.trident.planner.ProcessorNode) PartitionNode(storm.trident.planner.PartitionNode) Node(storm.trident.planner.Node) GroupedStream(storm.trident.fluent.GroupedStream) IAggregatableStream(storm.trident.fluent.IAggregatableStream)

Example 5 with Fields

use of backtype.storm.tuple.Fields in project storm by nathanmarz.

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<String>();
    Set<String> allInFields = new HashSet<String>();
    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<String>(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(storm.trident.tuple.ComboList) ArrayList(java.util.ArrayList) SingleEmitAggregator(storm.trident.operation.impl.SingleEmitAggregator) CombinerAggregator(storm.trident.operation.CombinerAggregator) Aggregator(storm.trident.operation.Aggregator) ReducerAggregator(storm.trident.operation.ReducerAggregator) SingleEmitAggregator(storm.trident.operation.impl.SingleEmitAggregator) Fields(backtype.storm.tuple.Fields) ChainedAggregatorImpl(storm.trident.operation.impl.ChainedAggregatorImpl) BatchToPartition(storm.trident.operation.impl.SingleEmitAggregator.BatchToPartition) HashSet(java.util.HashSet)

Aggregations

Fields (backtype.storm.tuple.Fields)130 TopologyBuilder (backtype.storm.topology.TopologyBuilder)41 Config (backtype.storm.Config)24 TridentTopology (storm.trident.TridentTopology)21 Map (java.util.Map)20 HashMap (java.util.HashMap)18 Test (org.junit.Test)17 JStormHelper (com.alibaba.starter.utils.JStormHelper)16 Values (backtype.storm.tuple.Values)15 ArrayList (java.util.ArrayList)13 LocalCluster (backtype.storm.LocalCluster)12 Stream (storm.trident.Stream)12 StreamInfo (backtype.storm.generated.StreamInfo)10 FixedBatchSpout (storm.trident.testing.FixedBatchSpout)9 HashSet (java.util.HashSet)8 LocalDRPC (backtype.storm.LocalDRPC)7 TridentState (storm.trident.TridentState)7 Count (storm.trident.operation.builtin.Count)7 GroupedStream (storm.trident.fluent.GroupedStream)6 IAggregatableStream (storm.trident.fluent.IAggregatableStream)6