use of com.hazelcast.jet.datamodel.TwoBags in project hazelcast-jet by hazelcast.
the class WindowAggregateTransform_IntegrationTest method test_aggregate2_with_aggregateBuilder.
@Test
public void test_aggregate2_with_aggregateBuilder() {
IMap<Long, String> map = instance.getMap("source");
// key is timestamp
map.put(0L, "foo");
map.put(2L, "baz");
map.put(10L, "flush-item");
IMap<Long, String> map2 = instance.getMap("source1");
// key is timestamp
map2.put(0L, "faa");
map2.put(2L, "buu");
map2.put(10L, "flush-item");
Pipeline p = Pipeline.create();
StreamStage<Entry<Long, String>> stage1 = p.drawFrom(Sources.<Long, String>mapJournal("source1", START_FROM_OLDEST));
stage1.addTimestamps(Entry::getKey, 0);
WindowAggregateBuilder<Entry<Long, String>> b = p.drawFrom(Sources.<Long, String>mapJournal("source", START_FROM_OLDEST)).addTimestamps(Entry::getKey, 0).window(WindowDefinition.tumbling(2)).aggregateBuilder();
Tag<Entry<Long, String>> tag0 = b.tag0();
Tag<Entry<Long, String>> tag1 = b.add(stage1);
b.build(AggregateOperation.withCreate(TwoBags::twoBags).andAccumulate(tag0, (acc, item0) -> acc.bag0().add(item0)).andAccumulate(tag1, (acc, item1) -> acc.bag1().add(item1)).andCombine(TwoBags::combineWith).andDeduct(TwoBags::deduct).andFinish(TwoBags::finish)).peek().drainTo(Sinks.list("sink"));
instance.newJob(p);
assertTrueEventually(() -> assertEquals(listToString(asList(new TimestampedItem<>(2, TwoBags.twoBags(asList(entry(0L, "foo")), asList(entry(0L, "faa")))), new TimestampedItem<>(4, TwoBags.twoBags(asList(entry(2L, "baz")), asList(entry(2L, "buu")))))), listToString(instance.getHazelcastInstance().getList("sink"))), 5);
}
use of com.hazelcast.jet.datamodel.TwoBags in project hazelcast-jet by hazelcast.
the class AggregateTransform_IntegrationTest method test_aggregate2.
@Test
public void test_aggregate2() {
// Given
JetInstance instance = createJetMember();
IListJet<Integer> list = instance.getList("list");
list.add(1);
list.add(2);
list.add(3);
IListJet<String> list1 = instance.getList("list1");
list1.add("a");
list1.add("b");
list1.add("c");
// When
Pipeline p = Pipeline.create();
BatchStage<Integer> stage1 = p.drawFrom(Sources.list("list1"));
p.drawFrom(Sources.list("list")).aggregate2(stage1, toTwoBags()).drainTo(Sinks.list("sink"));
instance.newJob(p).join();
// Then
TwoBags twoBags = (TwoBags) instance.getHazelcastInstance().getList("sink").iterator().next();
assertNotNull(twoBags);
sort(twoBags);
assertEquals(TwoBags.twoBags(list, list1), twoBags);
}
Aggregations