[Streaming] Streaming filter transform (#6816)

* add filter transform

* lint

* add new line
This commit is contained in:
chaokunyang
2020-01-17 22:05:47 +08:00
committed by Qing Wang
parent e143f85ca0
commit fa3c513276
6 changed files with 66 additions and 7 deletions
@@ -44,6 +44,7 @@ public class WordCountTest extends BaseUnitTest implements Serializable {
collector.collect(new WordAndCount(record, 1));
}
})
.filter(pair -> !pair.word.contains("world"))
.keyBy(pair -> pair.word)
.reduce((ReduceFunction<WordAndCount>) (oldValue, newValue) ->
new WordAndCount(oldValue.word, oldValue.count + newValue.count))
@@ -53,14 +54,14 @@ public class WordCountTest extends BaseUnitTest implements Serializable {
streamingContext.execute("testWordCount");
// Sleep until the count for every word is computed.
while (wordCount.size() < 3) {
while (wordCount.size() < 2) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
LOGGER.warn("Got an exception while sleeping.", e);
}
}
Assert.assertEquals(wordCount, ImmutableMap.of("eagle", 3, "hello", 1, "world", 1));
Assert.assertEquals(wordCount, ImmutableMap.of("eagle", 3, "hello", 1));
}
private static class WordAndCount implements Serializable {