The "problem" is the coincidence of "getting the number of different words across all tweets" and Strom as a stream processor. The query you want to answer can only be computed on a finite set of Tweets. However, when processing a stream, you are processing a potential endless stream of input data.
If you have a finite set of tweets, you can use a batch processing infrastructure such as Flink, Spark, or MapReduce. If you really have an infinite number of tweets, you should rephrase your question ...
As you mentioned, you really want to "iterate over all tweets." Since you are handling the stream this way, there is no such concept. You have an infinite number of input tuples, and Storm applies execute() to each of them (i.e. you can think of it as if Storm "loops over the input" automatically - even in "looping" this is not the right term for This ) Since your calculations are “above all tweets,” you need to maintain a state in your Bolt code so that you can update this state for each tweet. The simple state form in Storm will be a member variable in your Bolt class.
public class MyBolt implements ??? {
Right now, this code is emitting nothing, because it is not clear what you really want to emit? Like in streaming processing, there is no end, you cannot say "emit the final number of words contained in allWords ". What could you do to emit the current counter after each update ... To do this, add collector.emit(new Values(this.allWords.size())); to the end of execute() .
In addition, I want to add that the presented solution works correctly if parallelism is not applied to MyBolt - otherwise different sets of instances may contain the same word. To resolve this, you would need to tokenize each text in your words in a stateless bolt and move these word streams to the accepted MyBolt , which uses the internal state of Set . The input for MyBolt must also receive data through fieldsGrouping to provide different sets of words for each instance.
Matthias J. Sax
source share