Search in sources :

Example 1 with CompletionCandidate

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();
}
Also used : CompletionCandidate(org.apache.beam.examples.complete.AutoComplete.CompletionCandidate) KV(org.apache.beam.sdk.values.KV) ComputeTopCompletions(org.apache.beam.examples.complete.AutoComplete.ComputeTopCompletions) Test(org.junit.Test)

Example 2 with CompletionCandidate

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;
}
Also used : CompletionCandidate(org.apache.beam.examples.complete.AutoComplete.CompletionCandidate) ArrayList(java.util.ArrayList)

Example 3 with CompletionCandidate

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();
}
Also used : CompletionCandidate(org.apache.beam.examples.complete.AutoComplete.CompletionCandidate) TimestampedValue(org.apache.beam.sdk.values.TimestampedValue) Instant(org.joda.time.Instant) Duration(org.joda.time.Duration) KV(org.apache.beam.sdk.values.KV) ComputeTopCompletions(org.apache.beam.examples.complete.AutoComplete.ComputeTopCompletions) Test(org.junit.Test)

Aggregations

CompletionCandidate (org.apache.beam.examples.complete.AutoComplete.CompletionCandidate)3 ComputeTopCompletions (org.apache.beam.examples.complete.AutoComplete.ComputeTopCompletions)2 KV (org.apache.beam.sdk.values.KV)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 TimestampedValue (org.apache.beam.sdk.values.TimestampedValue)1 Duration (org.joda.time.Duration)1 Instant (org.joda.time.Instant)1