use of org.apache.beam.examples.complete.AutoComplete.CompletionCandidate in project beam by apache.
the class AutoCompleteTest method testTinyAutoComplete.
@Test
public void testTinyAutoComplete() {
List<String> words = Arrays.asList("x", "x", "x", "xy", "xy", "xyz");
PCollection<String> input = p.apply(Create.of(words));
PCollection<KV<String, List<CompletionCandidate>>> output = input.apply(new ComputeTopCompletions(2, recursive));
PAssert.that(output).containsInAnyOrder(KV.of("x", parseList("x:3", "xy:2")), KV.of("xy", parseList("xy:2", "xyz:1")), KV.of("xyz", parseList("xyz:1")));
p.run().waitUntilFinish();
}
use of org.apache.beam.examples.complete.AutoComplete.CompletionCandidate in project beam by apache.
the class AutoCompleteTest method parseList.
private static List<CompletionCandidate> parseList(String... entries) {
List<CompletionCandidate> all = new ArrayList<>();
for (String s : entries) {
String[] countValue = s.split(":");
all.add(new CompletionCandidate(countValue[0], Integer.valueOf(countValue[1])));
}
return all;
}
use of org.apache.beam.examples.complete.AutoComplete.CompletionCandidate in project beam by apache.
the class AutoCompleteTest method testWindowedAutoComplete.
@Test
public void testWindowedAutoComplete() {
List<TimestampedValue<String>> words = Arrays.asList(TimestampedValue.of("xA", new Instant(1)), TimestampedValue.of("xA", new Instant(1)), TimestampedValue.of("xB", new Instant(1)), TimestampedValue.of("xB", new Instant(2)), TimestampedValue.of("xB", new Instant(2)));
PCollection<String> input = p.apply(Create.of(words)).apply(new ReifyTimestamps<String>());
PCollection<KV<String, List<CompletionCandidate>>> output = input.apply(Window.<String>into(SlidingWindows.of(new Duration(2)))).apply(new ComputeTopCompletions(2, recursive));
PAssert.that(output).containsInAnyOrder(// Window [0, 2)
KV.of("x", parseList("xA:2", "xB:1")), KV.of("xA", parseList("xA:2")), KV.of("xB", parseList("xB:1")), // Window [1, 3)
KV.of("x", parseList("xB:3", "xA:2")), KV.of("xA", parseList("xA:2")), KV.of("xB", parseList("xB:3")), // Window [2, 3)
KV.of("x", parseList("xB:2")), KV.of("xB", parseList("xB:2")));
p.run().waitUntilFinish();
}
Aggregations