Search in sources :

Example 11 with Stream

use of storm.trident.Stream in project jstorm by alibaba.

the class TridentMinMaxOfDevicesTest method testTridentMinMaxOfDevices.

@Test
public void testTridentMinMaxOfDevices() {
    Fields fields = new Fields("device-id", "count");
    List<Values> content = new ArrayList<Values>();
    for (int i = 0; i < SPOUT_BATCH_SIZE; i++) content.add(new Values(i + 1));
    ShuffleValuesBatchSpout spout = new ShuffleValuesBatchSpout(fields, content, content);
    TridentTopology tridentTopology = new TridentTopology();
    Stream stream = tridentTopology.newStream("device-gen-spout", spout).each(fields, new Debug("#### devices"));
    stream.minBy("device-id").each(fields, new AssertMinDebug());
    stream.maxBy("count").each(fields, new AssertMaxDebug());
    Map config = new HashMap();
    config.put(Config.TOPOLOGY_NAME, "TridentMinMaxOfDevicesTest");
    //the test can pass if the 2 AssertDebug pass throughout the test
    JStormUnitTestRunner.submitTopology(tridentTopology.build(), config, 120, null);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Values(backtype.storm.tuple.Values) Fields(backtype.storm.tuple.Fields) TridentTopology(storm.trident.TridentTopology) Stream(storm.trident.Stream) HashMap(java.util.HashMap) Map(java.util.Map) Debug(storm.trident.operation.builtin.Debug) Test(org.junit.Test)

Example 12 with Stream

use of storm.trident.Stream in project storm by nathanmarz.

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(backtype.storm.tuple.Fields) GroupedAggregator(storm.trident.operation.impl.GroupedAggregator) CombinerAggregator(storm.trident.operation.CombinerAggregator) Aggregator(storm.trident.operation.Aggregator) ReducerAggregator(storm.trident.operation.ReducerAggregator) GroupedAggregator(storm.trident.operation.impl.GroupedAggregator) Stream(storm.trident.Stream)

Aggregations

Fields (backtype.storm.tuple.Fields)12 Stream (storm.trident.Stream)12 TridentTopology (storm.trident.TridentTopology)10 Values (backtype.storm.tuple.Values)7 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Debug (storm.trident.operation.builtin.Debug)5 CountAsAggregator (storm.trident.testing.CountAsAggregator)5 Split (storm.trident.testing.Split)5 InMemoryWindowsStoreFactory (storm.trident.windowing.InMemoryWindowsStoreFactory)4 WindowsStoreFactory (storm.trident.windowing.WindowsStoreFactory)4 FixedBatchSpout (storm.trident.testing.FixedBatchSpout)3 Aggregator (storm.trident.operation.Aggregator)2 CombinerAggregator (storm.trident.operation.CombinerAggregator)2 ReducerAggregator (storm.trident.operation.ReducerAggregator)2 GroupedAggregator (storm.trident.operation.impl.GroupedAggregator)2 ArrayList (java.util.ArrayList)1 RandomNumberGeneratorSpout (org.apache.storm.starter.spout.RandomNumberGeneratorSpout)1 Consumer (storm.trident.operation.Consumer)1