Search in sources :

Example 6 with Sources

use of com.hazelcast.jet.pipeline.Sources in project hazelcast-jet by hazelcast.

the class WindowGroupTransform_IntegrationTest method testSliding_groupingFirst_withNonStreamingSource.

@Test
public void testSliding_groupingFirst_withNonStreamingSource() {
    IList<Entry<Long, String>> list = instance.getList("source");
    list.add(entry(0L, "foo"));
    list.add(entry(1L, "bar"));
    list.add(entry(2L, "baz"));
    list.add(entry(3L, "booze"));
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<Entry<Long, String>>list("source")).addTimestamps(Entry::getKey, 0).groupingKey(entry -> entry.getValue().charAt(0)).window(WindowDefinition.tumbling(2)).aggregate(toSet()).drainTo(Sinks.list("sink"));
    instance.newJob(p).join();
    assertTrueEventually(() -> {
        assertEquals(set(new TimestampedEntry<>(2, 'f', set(entry(0L, "foo"))), new TimestampedEntry<>(2, 'b', set(entry(1L, "bar"))), new TimestampedEntry<>(4, 'b', set(entry(2L, "baz"), entry(3L, "booze")))), new HashSet<>(instance.getHazelcastInstance().getList("sink")));
    }, 5);
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) GroupProperty(com.hazelcast.spi.properties.GroupProperty) RunWith(org.junit.runner.RunWith) EventJournalConfig(com.hazelcast.config.EventJournalConfig) TestUtil.set(com.hazelcast.jet.core.TestUtil.set) HashSet(java.util.HashSet) ThreeBags(com.hazelcast.jet.datamodel.ThreeBags) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) SlidingWindowDef(com.hazelcast.jet.pipeline.SlidingWindowDef) Util.entry(com.hazelcast.jet.Util.entry) Arrays.asList(java.util.Arrays.asList) WindowGroupAggregateBuilder(com.hazelcast.jet.pipeline.WindowGroupAggregateBuilder) StageWithGroupingAndWindow(com.hazelcast.jet.pipeline.StageWithGroupingAndWindow) IList(com.hazelcast.core.IList) Before(org.junit.Before) AggregateOperations.toThreeBags(com.hazelcast.jet.aggregate.AggregateOperations.toThreeBags) JetConfig(com.hazelcast.jet.config.JetConfig) WindowDefinition(com.hazelcast.jet.pipeline.WindowDefinition) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) AggregateOperations.toTwoBags(com.hazelcast.jet.aggregate.AggregateOperations.toTwoBags) AggregateOperations.toSet(com.hazelcast.jet.aggregate.AggregateOperations.toSet) Tag(com.hazelcast.jet.datamodel.Tag) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) ParallelTest(com.hazelcast.test.annotation.ParallelTest) Category(org.junit.experimental.categories.Category) Sources(com.hazelcast.jet.pipeline.Sources) IMap(com.hazelcast.core.IMap) JournalInitialPosition(com.hazelcast.jet.pipeline.JournalInitialPosition) StreamStageWithGrouping(com.hazelcast.jet.pipeline.StreamStageWithGrouping) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) Entry(java.util.Map.Entry) TwoBags(com.hazelcast.jet.datamodel.TwoBags) Assert.assertEquals(org.junit.Assert.assertEquals) TimestampedEntry(com.hazelcast.jet.datamodel.TimestampedEntry) WindowResult(com.hazelcast.jet.datamodel.WindowResult) TestSupport.listToString(com.hazelcast.jet.core.test.TestSupport.listToString) Entry(java.util.Map.Entry) TimestampedEntry(com.hazelcast.jet.datamodel.TimestampedEntry) TimestampedEntry(com.hazelcast.jet.datamodel.TimestampedEntry) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with Sources

use of com.hazelcast.jet.pipeline.Sources in project hazelcast-jet-reference-manual by hazelcast.

the class BuildComputation method s5.

static void s5() {
    // tag::s5[]
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<String>list("text")).flatMap(line -> traverseArray(line.toLowerCase().split("\\W+"))).filter(word -> !word.isEmpty()).aggregate(counting()).drainTo(Sinks.list("result"));
// end::s5[]
}
Also used : AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) Delivery(datamodel.Delivery) MINUTES(java.util.concurrent.TimeUnit.MINUTES) Tweet(datamodel.Tweet) JoinClause.joinMapEntries(com.hazelcast.jet.pipeline.JoinClause.joinMapEntries) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) BatchStage(com.hazelcast.jet.pipeline.BatchStage) Util.mapEventNewValue(com.hazelcast.jet.Util.mapEventNewValue) PageVisit(datamodel.PageVisit) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) START_FROM_CURRENT(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_CURRENT) DAG(com.hazelcast.jet.core.DAG) StreamHashJoinBuilder(com.hazelcast.jet.pipeline.StreamHashJoinBuilder) Tuple2(com.hazelcast.jet.datamodel.Tuple2) AddToCart(datamodel.AddToCart) Tuple3(com.hazelcast.jet.datamodel.Tuple3) StreamStage(com.hazelcast.jet.pipeline.StreamStage) StageWithGrouping(com.hazelcast.jet.pipeline.StageWithGrouping) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Market(datamodel.Market) AggregateOperation2(com.hazelcast.jet.aggregate.AggregateOperation2) Tag(com.hazelcast.jet.datamodel.Tag) Sinks(com.hazelcast.jet.pipeline.Sinks) Payment(datamodel.Payment) Sources(com.hazelcast.jet.pipeline.Sources) Product(datamodel.Product) TimeUnit(java.util.concurrent.TimeUnit) BagsByTag(com.hazelcast.jet.datamodel.BagsByTag) WindowDefinition.sliding(com.hazelcast.jet.pipeline.WindowDefinition.sliding) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Traversers.traverseArray(com.hazelcast.jet.Traversers.traverseArray) ItemsByTag(com.hazelcast.jet.datamodel.ItemsByTag) Entry(java.util.Map.Entry) Trade(datamodel.Trade) TweetWord(datamodel.TweetWord) Util.mapPutEvents(com.hazelcast.jet.Util.mapPutEvents) AggregateOperations.toBagsByTag(com.hazelcast.jet.aggregate.AggregateOperations.toBagsByTag) GroupAggregateBuilder(com.hazelcast.jet.pipeline.GroupAggregateBuilder) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Broker(datamodel.Broker) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 8 with Sources

use of com.hazelcast.jet.pipeline.Sources in project hazelcast-jet-reference-manual by hazelcast.

the class BuildComputation method s6.

static void s6() {
    // tag::s6[]
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<String>list("text")).flatMap(line -> traverseArray(line.toLowerCase().split("\\W+"))).filter(word -> !word.isEmpty()).groupingKey(wholeItem()).aggregate(counting()).drainTo(Sinks.list("result"));
// end::s6[]
}
Also used : AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) Delivery(datamodel.Delivery) MINUTES(java.util.concurrent.TimeUnit.MINUTES) Tweet(datamodel.Tweet) JoinClause.joinMapEntries(com.hazelcast.jet.pipeline.JoinClause.joinMapEntries) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) BatchStage(com.hazelcast.jet.pipeline.BatchStage) Util.mapEventNewValue(com.hazelcast.jet.Util.mapEventNewValue) PageVisit(datamodel.PageVisit) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) START_FROM_CURRENT(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_CURRENT) DAG(com.hazelcast.jet.core.DAG) StreamHashJoinBuilder(com.hazelcast.jet.pipeline.StreamHashJoinBuilder) Tuple2(com.hazelcast.jet.datamodel.Tuple2) AddToCart(datamodel.AddToCart) Tuple3(com.hazelcast.jet.datamodel.Tuple3) StreamStage(com.hazelcast.jet.pipeline.StreamStage) StageWithGrouping(com.hazelcast.jet.pipeline.StageWithGrouping) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Market(datamodel.Market) AggregateOperation2(com.hazelcast.jet.aggregate.AggregateOperation2) Tag(com.hazelcast.jet.datamodel.Tag) Sinks(com.hazelcast.jet.pipeline.Sinks) Payment(datamodel.Payment) Sources(com.hazelcast.jet.pipeline.Sources) Product(datamodel.Product) TimeUnit(java.util.concurrent.TimeUnit) BagsByTag(com.hazelcast.jet.datamodel.BagsByTag) WindowDefinition.sliding(com.hazelcast.jet.pipeline.WindowDefinition.sliding) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Traversers.traverseArray(com.hazelcast.jet.Traversers.traverseArray) ItemsByTag(com.hazelcast.jet.datamodel.ItemsByTag) Entry(java.util.Map.Entry) Trade(datamodel.Trade) TweetWord(datamodel.TweetWord) Util.mapPutEvents(com.hazelcast.jet.Util.mapPutEvents) AggregateOperations.toBagsByTag(com.hazelcast.jet.aggregate.AggregateOperations.toBagsByTag) GroupAggregateBuilder(com.hazelcast.jet.pipeline.GroupAggregateBuilder) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Broker(datamodel.Broker) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 9 with Sources

use of com.hazelcast.jet.pipeline.Sources in project hazelcast-jet-reference-manual by hazelcast.

the class ImdgConnectors method s4.

static void s4() {
    // tag::s4[]
    Pipeline pipeline = Pipeline.create();
    pipeline.drawFrom(Sources.<String, Long>map("inMap")).drainTo(Sinks.<Entry<String, Long>, String, Long>mapWithUpdating("outMap", Entry::getKey, (oldV, item) -> (oldV != null ? oldV : 0L) + item.getValue()));
// end::s4[]
}
Also used : EventJournalCacheEvent(com.hazelcast.cache.journal.EventJournalCacheEvent) JetConfig(com.hazelcast.jet.config.JetConfig) StreamStage(com.hazelcast.jet.pipeline.StreamStage) Person(datamodel.Person) JetInstance(com.hazelcast.jet.JetInstance) DistributedFunctions(com.hazelcast.jet.function.DistributedFunctions) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Sinks(com.hazelcast.jet.pipeline.Sinks) IListJet(com.hazelcast.jet.IListJet) EntryBackupProcessor(com.hazelcast.map.EntryBackupProcessor) ArrayList(java.util.ArrayList) BatchStage(com.hazelcast.jet.pipeline.BatchStage) Sources(com.hazelcast.jet.pipeline.Sources) EntryProcessor(com.hazelcast.map.EntryProcessor) Entry(java.util.Map.Entry) START_FROM_CURRENT(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_CURRENT) ClientConfig(com.hazelcast.client.config.ClientConfig) IList(com.hazelcast.core.IList) Jet(com.hazelcast.jet.Jet) DistributedFunction(com.hazelcast.jet.function.DistributedFunction) EventJournalMapEvent(com.hazelcast.map.journal.EventJournalMapEvent) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 10 with Sources

use of com.hazelcast.jet.pipeline.Sources in project hazelcast-jet-reference-manual by hazelcast.

the class ImdgConnectors method s3.

static void s3() {
    // tag::s3[]
    Pipeline pipeline = Pipeline.create();
    pipeline.drawFrom(Sources.<String, Long>map("inMap")).drainTo(Sinks.mapWithMerging("outMap", Entry::getKey, Entry::getValue, (oldValue, newValue) -> oldValue + newValue));
// end::s3[]
}
Also used : EventJournalCacheEvent(com.hazelcast.cache.journal.EventJournalCacheEvent) JetConfig(com.hazelcast.jet.config.JetConfig) StreamStage(com.hazelcast.jet.pipeline.StreamStage) Person(datamodel.Person) JetInstance(com.hazelcast.jet.JetInstance) DistributedFunctions(com.hazelcast.jet.function.DistributedFunctions) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Sinks(com.hazelcast.jet.pipeline.Sinks) IListJet(com.hazelcast.jet.IListJet) EntryBackupProcessor(com.hazelcast.map.EntryBackupProcessor) ArrayList(java.util.ArrayList) BatchStage(com.hazelcast.jet.pipeline.BatchStage) Sources(com.hazelcast.jet.pipeline.Sources) EntryProcessor(com.hazelcast.map.EntryProcessor) Entry(java.util.Map.Entry) START_FROM_CURRENT(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_CURRENT) ClientConfig(com.hazelcast.client.config.ClientConfig) IList(com.hazelcast.core.IList) Jet(com.hazelcast.jet.Jet) DistributedFunction(com.hazelcast.jet.function.DistributedFunction) EventJournalMapEvent(com.hazelcast.map.journal.EventJournalMapEvent) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Aggregations

Pipeline (com.hazelcast.jet.pipeline.Pipeline)24 Sources (com.hazelcast.jet.pipeline.Sources)24 Sinks (com.hazelcast.jet.pipeline.Sinks)23 JetInstance (com.hazelcast.jet.JetInstance)18 Entry (java.util.Map.Entry)18 JetConfig (com.hazelcast.jet.config.JetConfig)15 Test (org.junit.Test)14 IList (com.hazelcast.core.IList)12 Arrays.asList (java.util.Arrays.asList)12 Assert.assertEquals (org.junit.Assert.assertEquals)12 AggregateOperation (com.hazelcast.jet.aggregate.AggregateOperation)11 Tag (com.hazelcast.jet.datamodel.Tag)11 Before (org.junit.Before)11 Category (org.junit.experimental.categories.Category)11 RunWith (org.junit.runner.RunWith)11 Util.entry (com.hazelcast.jet.Util.entry)10 JetTestSupport (com.hazelcast.jet.core.JetTestSupport)10 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)10 EventJournalConfig (com.hazelcast.config.EventJournalConfig)9 IMap (com.hazelcast.core.IMap)9