Search in sources :

Example 41 with TridentTopology

use of org.apache.storm.trident.TridentTopology in project storm by apache.

the class TridentHBaseWindowingStoreTopology method buildTopology.

public static StormTopology buildTopology(WindowsStoreFactory windowsStore) throws Exception {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3, new Values("the cow jumped over the moon"), new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"), new Values("how many apples can you eat"), new Values("to be or not to be the person"));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"), new Split(), new Fields("word")).window(TumblingCountWindow.of(1000), windowsStore, new Fields("word"), new CountAsAggregator(), new Fields("count")).peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            LOG.info("Received tuple: [{}]", input);
        }
    });
    return topology.build();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) Consumer(org.apache.storm.trident.operation.Consumer) TridentTopology(org.apache.storm.trident.TridentTopology) CountAsAggregator(org.apache.storm.trident.testing.CountAsAggregator) Values(org.apache.storm.tuple.Values) Stream(org.apache.storm.trident.Stream) Split(org.apache.storm.trident.testing.Split) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Example 42 with TridentTopology

use of org.apache.storm.trident.TridentTopology in project storm by apache.

the class TridentMinMaxOfDevicesTopology method buildVehiclesTopology.

/**
 * Creates a topology which demonstrates min/max operations on tuples of stream which contain vehicle and driver fields
 * with values {@link TridentMinMaxOfDevicesTopology.Vehicle} and {@link TridentMinMaxOfDevicesTopology.Driver} respectively.
 */
public static StormTopology buildVehiclesTopology() {
    Fields driverField = new Fields(Driver.FIELD_NAME);
    Fields vehicleField = new Fields(Vehicle.FIELD_NAME);
    Fields allFields = new Fields(Vehicle.FIELD_NAME, Driver.FIELD_NAME);
    FixedBatchSpout spout = new FixedBatchSpout(allFields, 10, Vehicle.generateVehicles(20));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    Stream vehiclesStream = topology.newStream("spout1", spout).each(allFields, new Debug("##### vehicles"));
    Stream slowVehiclesStream = vehiclesStream.min(new SpeedComparator()).each(vehicleField, new Debug("#### slowest vehicle"));
    Stream slowDriversStream = slowVehiclesStream.project(driverField).each(driverField, new Debug("##### slowest driver"));
    vehiclesStream.max(new SpeedComparator()).each(vehicleField, new Debug("#### fastest vehicle")).project(driverField).each(driverField, new Debug("##### fastest driver"));
    vehiclesStream.max(new EfficiencyComparator()).each(vehicleField, new Debug("#### efficient vehicle"));
    return topology.build();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) Stream(org.apache.storm.trident.Stream) Debug(org.apache.storm.trident.operation.builtin.Debug)

Example 43 with TridentTopology

use of org.apache.storm.trident.TridentTopology in project storm by apache.

the class TridentMinMaxOfDevicesTopology method buildDevicesTopology.

/**
 * Creates a topology with device-id and count (which are whole numbers) as tuple fields in a stream and it finally
 * generates result stream based on min amd max with device-id and count values.
 */
public static StormTopology buildDevicesTopology() {
    String deviceId = "device-id";
    String count = "count";
    Fields allFields = new Fields(deviceId, count);
    RandomNumberGeneratorSpout spout = new RandomNumberGeneratorSpout(allFields, 10, 1000);
    TridentTopology topology = new TridentTopology();
    Stream devicesStream = topology.newStream("devicegen-spout", spout).each(allFields, new Debug("##### devices"));
    devicesStream.minBy(deviceId).each(allFields, new Debug("#### device with min id"));
    devicesStream.maxBy(count).each(allFields, new Debug("#### device with max count"));
    return topology.build();
}
Also used : Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) Stream(org.apache.storm.trident.Stream) RandomNumberGeneratorSpout(org.apache.storm.starter.spout.RandomNumberGeneratorSpout) Debug(org.apache.storm.trident.operation.builtin.Debug)

Example 44 with TridentTopology

use of org.apache.storm.trident.TridentTopology in project storm by apache.

the class TridentMapExample method buildTopology.

public static StormTopology buildTopology() {
    FixedBatchSpout spout = new FixedBatchSpout(new Fields("word"), 3, new Values("the cow jumped over the moon"), new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"), new Values("how many apples can you eat"), new Values("to be or not to be the person"));
    spout.setCycle(true);
    TridentTopology topology = new TridentTopology();
    TridentState wordCounts = topology.newStream("spout1", spout).parallelismHint(16).flatMap(split).map(toUpper, new Fields("uppercased")).filter(theFilter).peek(new Consumer() {

        @Override
        public void accept(TridentTuple input) {
            System.out.println(input.getString(0));
        }
    }).groupBy(new Fields("uppercased")).persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")).parallelismHint(16);
    topology.newDRPCStream("words").flatMap(split, new Fields("word")).groupBy(new Fields("word")).stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count")).filter(new FilterNull()).aggregate(new Fields("count"), new Sum(), new Fields("sum"));
    return topology.build();
}
Also used : FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) FilterNull(org.apache.storm.trident.operation.builtin.FilterNull) Fields(org.apache.storm.tuple.Fields) Consumer(org.apache.storm.trident.operation.Consumer) TridentTopology(org.apache.storm.trident.TridentTopology) TridentState(org.apache.storm.trident.TridentState) Values(org.apache.storm.tuple.Values) MapGet(org.apache.storm.trident.operation.builtin.MapGet) Sum(org.apache.storm.trident.operation.builtin.Sum) Count(org.apache.storm.trident.operation.builtin.Count) TridentTuple(org.apache.storm.trident.tuple.TridentTuple)

Aggregations

TridentTopology (org.apache.storm.trident.TridentTopology)44 Fields (org.apache.storm.tuple.Fields)38 Stream (org.apache.storm.trident.Stream)25 Values (org.apache.storm.tuple.Values)25 TridentState (org.apache.storm.trident.TridentState)22 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)19 StateFactory (org.apache.storm.trident.state.StateFactory)12 MapGet (org.apache.storm.trident.operation.builtin.MapGet)10 Sum (org.apache.storm.trident.operation.builtin.Sum)10 HashMap (java.util.HashMap)9 Count (org.apache.storm.trident.operation.builtin.Count)8 AbstractTridentProcessor (org.apache.storm.sql.AbstractTridentProcessor)7 QueryPlanner (org.apache.storm.sql.planner.trident.QueryPlanner)7 ISqlTridentDataSource (org.apache.storm.sql.runtime.ISqlTridentDataSource)7 TestUtils (org.apache.storm.sql.TestUtils)6 MockState.getCollectedValues (org.apache.storm.sql.TestUtils.MockState.getCollectedValues)6 Consumer (org.apache.storm.trident.operation.Consumer)6 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)6 Test (org.junit.Test)6 FilterNull (org.apache.storm.trident.operation.builtin.FilterNull)5