本文整理汇总了Java中storm.trident.operation.builtin.Sum类的典型用法代码示例。如果您正苦于以下问题:Java Sum类的具体用法?Java Sum怎么用?Java Sum使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Sum类属于storm.trident.operation.builtin包,在下文中一共展示了Sum类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildTopology
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
public static StormTopology buildTopology(LocalDRPC drpc) {
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();
TridentState wordCounts = topology.newStream("spout1", spout).parallelismHint(16).each(new Fields("sentence"),
new Split(), new Fields("word")).groupBy(new Fields("word")).persistentAggregate(new MemoryMapState.Factory(),
new Count(), new Fields("count")).parallelismHint(16);
topology.newDRPCStream("words", drpc).each(new Fields("args"), new Split(), new Fields("word")).groupBy(new Fields(
"word")).stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count")).each(new Fields("count"),
new FilterNull()).aggregate(new Fields("count"), new Sum(), new Fields("sum"));
return topology.build();
}
示例2: buildTopology
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
public static StormTopology buildTopology(LocalDRPC drpc) {
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();
TridentState wordCounts = topology.newStream("spout1", spout)
.each(new Fields("sentence"), new Split(), new Fields("word"))
.groupBy(new Fields("word"))
.persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count"))
.parallelismHint(6);
topology.newDRPCStream("words", drpc).each(new Fields("args"), new Split(), new Fields("word"))
.groupBy(new Fields("word"))
.stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count"))
.each(new Fields("count"), new FilterNull())
.aggregate(new Fields("count"), new Sum(), new Fields("sum"));
return topology.build();
}
示例3: buildTopology
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
public static StormTopology buildTopology(LocalDRPC drpc) {
TridentTopology topology = new TridentTopology();
TridentState urlToTweeters =
topology.newStaticState(
new StaticSingleKeyMapState.Factory(TWEETERS_DB));
TridentState tweetersToFollowers =
topology.newStaticState(
new StaticSingleKeyMapState.Factory(FOLLOWERS_DB));
topology.newDRPCStream("reach", drpc)
.stateQuery(urlToTweeters, new Fields("args"), new MapGet(), new Fields("tweeters"))
.each(new Fields("tweeters"), new ExpandList(), new Fields("tweeter"))
.shuffle()
.stateQuery(tweetersToFollowers, new Fields("tweeter"), new MapGet(), new Fields("followers"))
.each(new Fields("followers"), new ExpandList(), new Fields("follower"))
.groupBy(new Fields("follower"))
.aggregate(new One(), new Fields("one"))
.aggregate(new Fields("one"), new Sum(), new Fields("reach"));
return topology.build();
}
示例4: buildTopology
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
public StormTopology buildTopology(LocalDRPC drpc) {
TridentKafkaConfig kafkaConfig = new TridentKafkaConfig(brokerHosts, "storm-sentence", "storm");
kafkaConfig.scheme = new SchemeAsMultiScheme(new StringScheme());
TransactionalTridentKafkaSpout kafkaSpout = new TransactionalTridentKafkaSpout(kafkaConfig);
TridentTopology topology = new TridentTopology();
TridentState wordCounts = topology.newStream("kafka", kafkaSpout).shuffle().
each(new Fields("str"), new WordSplit(), new Fields("word")).
groupBy(new Fields("word")).
persistentAggregate(new HazelCastStateFactory(), new Count(), new Fields("aggregates_words")).parallelismHint(2);
topology.newDRPCStream("words", drpc)
.each(new Fields("args"), new Split(), new Fields("word"))
.groupBy(new Fields("word"))
.stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count"))
.each(new Fields("count"), new FilterNull())
.aggregate(new Fields("count"), new Sum(), new Fields("sum"));
return topology.build();
}
示例5: buildTopology
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
public static StormTopology buildTopology(LocalDRPC drpc) {
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();
TridentState wordCounts = topology.newStream("spout1", spout).parallelismHint(16)
.each(new Fields("sentence"), new Split(), new Fields("word")).groupBy(new Fields("word"))
.persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count"))
.parallelismHint(16);
topology.newDRPCStream("words", drpc).each(new Fields("args"), new Split(), new Fields("word"))
.groupBy(new Fields("word"))
.stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count"))
.each(new Fields("count"), new FilterNull())
.aggregate(new Fields("count"), new Sum(), new Fields("sum"));
return topology.build();
}
示例6: buildTopology
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
public static StormTopology buildTopology(LocalDRPC drpc) {
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)
.filter(theFilter).peek(new Consumer() {
@Override
public void accept(TridentTuple input) {
System.out.println(input.getString(0));
}
}).groupBy(new Fields("word"))
.persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count"))
.parallelismHint(16);
topology.newDRPCStream("words", drpc).flatMap(split).groupBy(new Fields("args"))
.stateQuery(wordCounts, new Fields("args"), new MapGet(), new Fields("count")).filter(new FilterNull())
.aggregate(new Fields("count"), new Sum(), new Fields("sum"));
return topology.build();
}
示例7: buildTopology
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
private static StormTopology buildTopology(LocalDRPC drpc) {
TridentTopology topology = new TridentTopology();
TridentState urlToTweeters = topology.newStaticState(new StaticSingleKeyMapState.Factory(TWEETERS_DB));
TridentState tweetersToFollowers = topology.newStaticState(new StaticSingleKeyMapState.Factory(FOLLOWERS_DB));
topology.newDRPCStream("reach", drpc)
.stateQuery(urlToTweeters, new Fields("args"), new MapGet(), new Fields("tweeters"))
.each(new Fields("tweeters"), new ExpandList(), new Fields("tweeter")).shuffle()
.stateQuery(tweetersToFollowers, new Fields("tweeter"), new MapGet(), new Fields("followers"))
.each(new Fields("followers"), new ExpandList(), new Fields("follower"))
.groupBy(new Fields("follower")).aggregate(new One(), new Fields("one"))
.aggregate(new Fields("one"), new Sum(), new Fields("reach"));
return topology.build();
}
示例8: buildTopology
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
public static StormTopology buildTopology() {
LOG.info("Building topology.");
TridentTopology topology = new TridentTopology();
SalesSpout spout = new SalesSpout();
Stream inputStream = topology.newStream("sales", spout);
SalesMapper mapper = new SalesMapper();
inputStream.partitionPersist(
new CassandraCqlIncrementalStateFactory<String, Number>(new Sum(), mapper),
new Fields("price", "state", "product"),
new CassandraCqlIncrementalStateUpdater<String, Number>());
return topology.build();
}
示例9: buildWordCountAndSourceTopology
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static StormTopology buildWordCountAndSourceTopology(LocalDRPC drpc) {
LOG.info("Building topology.");
TridentTopology topology = new TridentTopology();
String source1 = "spout1";
String source2 = "spout2";
FixedBatchSpout spout1 = new FixedBatchSpout(new Fields("sentence", "source"), 3,
new Values("the cow jumped over the moon", source1),
new Values("the man went to the store and bought some candy", source1),
new Values("four score and four years ago", source2),
new Values("how much wood can a wood chuck chuck", source2));
spout1.setCycle(true);
TridentState wordCounts =
topology.newStream("spout1", spout1)
.each(new Fields("sentence"), new Split(), new Fields("word"))
.groupBy(new Fields("word", "source"))
.persistentAggregate(CassandraCqlMapState.nonTransactional(new WordCountAndSourceMapper()),
new IntegerCount(), new Fields("count"))
.parallelismHint(6);
topology.newDRPCStream("words", drpc)
.each(new Fields("args"), new Split(), new Fields("word"))
.groupBy(new Fields("word"))
.stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count"))
.each(new Fields("count"), new FilterNull())
.aggregate(new Fields("count"), new Sum(), new Fields("sum"));
return topology.build();
}
示例10: IncrementalStateTest
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
public IncrementalStateTest() {
super();
SalesMapper mapper = new SalesMapper();
stateFactory = new CassandraCqlIncrementalStateFactory<String, Number>(new Sum(), mapper);
stateFactory.setCqlClientFactory(clientFactory);
stateUpdater = new CassandraCqlIncrementalStateUpdater<String, Number>();
}
示例11: buildTopology
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
public static StormTopology buildTopology(LocalDRPC drpc) {
TridentTopology topology = new TridentTopology();
TridentState urlToTweeters = topology.newStaticState(new StaticSingleKeyMapState.Factory(TWEETERS_DB));
TridentState tweetersToFollowers = topology.newStaticState(new StaticSingleKeyMapState.Factory(FOLLOWERS_DB));
topology.newDRPCStream("reach", drpc).stateQuery(urlToTweeters, new Fields("args"), new MapGet(), new Fields(
"tweeters")).each(new Fields("tweeters"), new ExpandList(), new Fields("tweeter")).shuffle().stateQuery(
tweetersToFollowers, new Fields("tweeter"), new MapGet(), new Fields("followers")).each(new Fields("followers"),
new ExpandList(), new Fields("follower")).groupBy(new Fields("follower")).aggregate(new One(), new Fields(
"one")).aggregate(new Fields("one"), new Sum(), new Fields("reach"));
return topology.build();
}
示例12: buildTopology1
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
private static StormTopology buildTopology1(LocalDRPC drpc) {
FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 100,
new Values("the cow jumped over the moon"),
new Values("the man went to the store and bought some candy"),
new Values("to be or not to be the person"));
spout.setCycle(true);
AerospikeOptions options = new AerospikeOptions();
options.set = "words";
options.keyType = AerospikeOptions.AerospikeKeyType.STRING;
TridentTopology topology = new TridentTopology();
TridentState wordCounts =
topology.newStream("spout1", spout)
.parallelismHint(4)
.each(new Fields("sentence"), new Split(), new Fields("word"))
.groupBy(new Fields("word"))
.persistentAggregate(AerospikeSingleBinMapState.getTransactional("count", options),
new CountAggregator(), new Fields("count"))
.parallelismHint(4);
topology.newDRPCStream("words", drpc)
.each(new Fields("args"), new Split(), new Fields("word"))
.groupBy(new Fields("word"))
.stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count"))
.each(new Fields("count"), new FilterNull())
.aggregate(new Fields("count"), new Sum(), new Fields("sum"));
return topology.build();
}
示例13: buildTopology
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
public static StormTopology buildTopology(LocalDRPC drpc) {
TridentTopology topology = new TridentTopology();
TridentState urlToTweeters = topology.newStaticState(new StaticSingleKeyMapState.Factory(TWEETERS_DB));
TridentState tweetersToFollowers = topology.newStaticState(new StaticSingleKeyMapState.Factory(FOLLOWERS_DB));
topology.newDRPCStream("reach", drpc)
.stateQuery(urlToTweeters, new Fields("args"), new MapGet(), new Fields("tweeters"))
.each(new Fields("tweeters"), new ExpandList(), new Fields("tweeter")).shuffle()
.stateQuery(tweetersToFollowers, new Fields("tweeter"), new MapGet(), new Fields("followers"))
.each(new Fields("followers"), new ExpandList(), new Fields("follower")).groupBy(new Fields("follower"))
.aggregate(new One(), new Fields("one")).aggregate(new Fields("one"), new Sum(), new Fields("reach"));
return topology.build();
}
示例14: main
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
public static void main(String... args) throws AlreadyAliveException, InvalidTopologyException, AuthorizationException {
// starting to build topology
TridentTopology topology = new TridentTopology();
// Kafka as an opaque trident spout
OpaqueTridentKafkaSpout spout = new OpaqueTridentKafkaSpoutBuilder(Conf.zookeeper, Conf.inputTopic).build();
Stream stream = topology.newStream(kafkaSpout, spout);
// mapping transaction messages to pairs: (person,amount)
Stream atomicTransactions = stream.each(strF, Functions.mapToPersonAmount, personAmountF);
// bolt to println data
atomicTransactions.each(personAmountF, Functions.printlnFunction, emptyF);
// aggregating transactions and mapping to Kafka messages
Stream transactionsGroupped = atomicTransactions.groupBy(personF)
.persistentAggregate(new MemoryMapState.Factory(), amountF, new Sum(), sumF).newValuesStream()
.each(personSumF, Functions.mapToKafkaMessage, keyMessageF);
// Kafka as a bolt -- producing to outputTopic
TridentKafkaStateFactory stateFactory = new TridentKafkaStateFactory() //
.withKafkaTopicSelector(new DefaultTopicSelector(Conf.outputTopic)) //
.withTridentTupleToKafkaMapper(new FieldNameBasedTupleToKafkaMapper<String, String>(key, message));
transactionsGroupped.partitionPersist(stateFactory, keyMessageF, new TridentKafkaUpdater(), emptyF);
// submitting topology to local cluster
new LocalCluster().submitTopology(kafkaAccountsTopology, topologyConfig(), topology.build());
// waiting a while, then running Kafka producer
Sleep.seconds(5);
KafkaProduceExample.start(20);
}
示例15: advancedPrimitives
import storm.trident.operation.builtin.Sum; //导入依赖的package包/类
private static StormTopology advancedPrimitives(FeederBatchSpout spout) throws IOException {
TridentTopology topology = new TridentTopology();
// What if we want more than one aggregation? For that, we can use "chained" aggregations.
// Note how we calculate count and sum.
// The aggregated values can then be processed further, in this case into mean
topology
.newStream("aggregation", spout)
.groupBy(new Fields("city"))
.chainedAgg()
.aggregate(new Count(), new Fields("count"))
.aggregate(new Fields("age"), new Sum(), new Fields("age_sum"))
.chainEnd()
.each(new Fields("age_sum", "count"), new DivideAsDouble(), new Fields("mean_age"))
.each(new Fields("city", "mean_age"), new Print())
;
// What if we want to persist results of an aggregation, but want to further process these
// results? You can use "newValuesStream" for that
topology
.newStream("further",spout)
.groupBy(new Fields("city"))
.persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count"))
.newValuesStream()
.each(new Fields("city", "count"), new Print());
return topology.build();
}