use of com.hazelcast.jet.datamodel.TimestampedEntry in project hazelcast-jet by hazelcast.
the class WindowGroupTransform_IntegrationTest method testSliding_windowFirst_aggregate2.
@Test
public void testSliding_windowFirst_aggregate2() {
IMap<Long, String> map = instance.getMap("source");
// key is timestamp
map.put(0L, "foo");
map.put(2L, "taz");
map.put(10L, "flush-item");
IMap<Long, String> map2 = instance.getMap("source1");
// key is timestamp
map2.put(0L, "faa");
map2.put(2L, "tuu");
map2.put(10L, "flush-item");
Pipeline p = Pipeline.create();
StreamStageWithGrouping<Entry<Long, String>, Character> stage1 = p.drawFrom(Sources.<Long, String>mapJournal("source1", START_FROM_OLDEST)).addTimestamps(Entry::getKey, 0).groupingKey(entry -> entry.getValue().charAt(0));
p.drawFrom(Sources.<Long, String>mapJournal("source", START_FROM_OLDEST)).addTimestamps(Entry::getKey, 0).window(WindowDefinition.tumbling(2)).groupingKey(entry -> entry.getValue().charAt(0)).aggregate2(stage1, toTwoBags()).peek().drainTo(Sinks.list("sink"));
instance.newJob(p);
assertTrueEventually(() -> {
assertEquals(listToString(asList(new TimestampedEntry<>(2, 'f', TwoBags.twoBags(asList(entry(0L, "foo")), asList(entry(0L, "faa")))), new TimestampedEntry<>(4, 't', TwoBags.twoBags(asList(entry(2L, "taz")), asList(entry(2L, "tuu")))))), listToString(instance.getHazelcastInstance().getList("sink")));
}, 5);
}
use of com.hazelcast.jet.datamodel.TimestampedEntry in project hazelcast-jet by hazelcast.
the class WindowGroupTransform_IntegrationTest method testSliding_windowFirst_aggregate3_with_aggregateBuilder.
@Test
public void testSliding_windowFirst_aggregate3_with_aggregateBuilder() {
IMap<Long, String> map = instance.getMap("source");
// key is timestamp
map.put(0L, "foo");
map.put(2L, "taz");
map.put(10L, "flush-item");
IMap<Long, String> map1 = instance.getMap("source1");
// key is timestamp
map1.put(0L, "faa");
map1.put(2L, "tuu");
map1.put(10L, "flush-item");
IMap<Long, String> map2 = instance.getMap("source2");
// key is timestamp
map2.put(0L, "fzz");
map2.put(2L, "tcc");
map2.put(10L, "flush-item");
Pipeline p = Pipeline.create();
StreamStageWithGrouping<Entry<Long, String>, Character> stage1 = p.drawFrom(Sources.<Long, String>mapJournal("source1", START_FROM_OLDEST)).addTimestamps(Entry::getKey, 0).groupingKey(entry -> entry.getValue().charAt(0));
StreamStageWithGrouping<Entry<Long, String>, Character> stage2 = p.drawFrom(Sources.<Long, String>mapJournal("source2", START_FROM_OLDEST)).addTimestamps(Entry::getKey, 0).groupingKey(entry -> entry.getValue().charAt(0));
WindowGroupAggregateBuilder<Entry<Long, String>, Character> b = p.drawFrom(Sources.<Long, String>mapJournal("source", START_FROM_OLDEST)).addTimestamps(Entry::getKey, 0).window(WindowDefinition.tumbling(2)).groupingKey(entry -> entry.getValue().charAt(0)).aggregateBuilder();
Tag<Entry<Long, String>> tag0 = b.tag0();
Tag<Entry<Long, String>> tag1 = b.add(stage1);
Tag<Entry<Long, String>> tag2 = b.add(stage2);
b.build(AggregateOperation.withCreate(ThreeBags::threeBags).andAccumulate(tag0, (acc, item0) -> acc.bag0().add(item0)).andAccumulate(tag1, (acc, item1) -> acc.bag1().add(item1)).andAccumulate(tag2, (acc, item2) -> acc.bag2().add(item2)).andCombine(ThreeBags::combineWith).andDeduct(ThreeBags::deduct).andFinish(ThreeBags::finish)).peek().drainTo(Sinks.list("sink"));
instance.newJob(p);
assertTrueEventually(() -> {
assertEquals(listToString(asList(new TimestampedEntry<>(2, 'f', ThreeBags.threeBags(asList(entry(0L, "foo")), asList(entry(0L, "faa")), asList(entry(0L, "fzz")))), new TimestampedEntry<>(4, 't', ThreeBags.threeBags(asList(entry(2L, "taz")), asList(entry(2L, "tuu")), asList(entry(2L, "tcc")))))), listToString(instance.getHazelcastInstance().getList("sink")));
}, 5);
}
use of com.hazelcast.jet.datamodel.TimestampedEntry in project hazelcast-jet by hazelcast.
the class SlidingWindowP_CoGroupTest method test.
@Test
public void test() {
DistributedSupplier supplier = Processors.aggregateToSlidingWindowP(asList(entryKey(), entryKey()), asList(t -> 1L, t -> 1L), TimestampKind.FRAME, tumblingWinPolicy(1), AggregateOperations.toTwoBags(), TimestampedEntry::new);
Entry<String, String> entry1 = entry("k1", "a");
Entry<String, String> entry2 = entry("k2", "b");
Entry<String, String> entry3 = entry("k1", "c");
Entry<String, String> entry4 = entry("k3", "d");
Entry<String, String> entry5 = entry("k1", "e");
TestSupport.verifyProcessor(supplier).inputs(asList(asList(entry1, entry2), asList(entry3, entry4, entry5))).expectOutput(asList(new TimestampedEntry<>(1, "k1", twoBags(singletonList(entry1), asList(entry3, entry5))), new TimestampedEntry<>(1, "k2", twoBags(singletonList(entry2), emptyList())), new TimestampedEntry<>(1, "k3", twoBags(emptyList(), singletonList(entry4)))));
}
use of com.hazelcast.jet.datamodel.TimestampedEntry in project hazelcast-jet by hazelcast.
the class SlidingWindowP_failoverTest method init.
private void init(ProcessingGuarantee guarantee) {
SlidingWindowPolicy wDef = SlidingWindowPolicy.tumblingWinPolicy(1);
AggregateOperation1<Object, LongAccumulator, Long> aggrOp = counting();
p = new SlidingWindowP<>(singletonList(entryKey()), singletonList((DistributedToLongFunction<Entry<?, Long>>) Entry::getValue), wDef, aggrOp, TimestampedEntry::new, true);
Outbox outbox = new TestOutbox(128);
Context context = new TestProcessorContext().setProcessingGuarantee(guarantee);
p.init(outbox, context);
}
Aggregations