Search in sources :

Example 16 with Sources

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

the class WindowGroupTransform_IntegrationTest method testSliding_groupingFirst.

@Test
public void testSliding_groupingFirst() {
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<Long, String>mapJournal("source", JournalInitialPosition.START_FROM_OLDEST)).addTimestamps(Entry::getKey, 0).groupingKey(entry -> entry.getValue().charAt(0)).window(WindowDefinition.tumbling(2)).aggregate(toSet()).drainTo(Sinks.list("sink"));
    testSliding(p);
}
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) TestSupport.listToString(com.hazelcast.jet.core.test.TestSupport.listToString) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with Sources

use of com.hazelcast.jet.pipeline.Sources 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);
}
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) ThreeBags(com.hazelcast.jet.datamodel.ThreeBags) AggregateOperations.toThreeBags(com.hazelcast.jet.aggregate.AggregateOperations.toThreeBags) TestSupport.listToString(com.hazelcast.jet.core.test.TestSupport.listToString) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with Sources

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

the class WriteFilePTest method when_toStringF_then_used.

@Test
public void when_toStringF_then_used() throws Exception {
    // Given
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<String>list(list.getName())).drainTo(Sinks.files(directory.toString(), val -> Integer.toString(Integer.parseInt(val) - 1)));
    addItemsToList(1, 11);
    // When
    instance.newJob(p).join();
    // Then
    checkFileContents(StandardCharsets.UTF_8, 10);
}
Also used : AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) JetInstance(com.hazelcast.jet.JetInstance) IOUtil(com.hazelcast.nio.IOUtil) Util.uncheckRun(com.hazelcast.jet.impl.util.Util.uncheckRun) RunWith(org.junit.runner.RunWith) SourceProcessors.readListP(com.hazelcast.jet.core.processor.SourceProcessors.readListP) DirectoryStream(java.nio.file.DirectoryStream) Charset(java.nio.charset.Charset) After(org.junit.After) DAG(com.hazelcast.jet.core.DAG) DistributedFunction(com.hazelcast.jet.function.DistributedFunction) Path(java.nio.file.Path) Job(com.hazelcast.jet.Job) Before(org.junit.Before) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Files(java.nio.file.Files) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) BufferedWriter(java.io.BufferedWriter) Semaphore(java.util.concurrent.Semaphore) Sinks(com.hazelcast.jet.pipeline.Sinks) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) IListJet(com.hazelcast.jet.IListJet) StandardCharsets(java.nio.charset.StandardCharsets) Sources(com.hazelcast.jet.pipeline.Sources) Vertex(com.hazelcast.jet.core.Vertex) SinkProcessors.writeFileP(com.hazelcast.jet.core.processor.SinkProcessors.writeFileP) Ignore(org.junit.Ignore) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) Assert.assertEquals(org.junit.Assert.assertEquals) Edge.between(com.hazelcast.jet.core.Edge.between) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 19 with Sources

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

the class HelloWorld method main.

public static void main(String[] args) {
    // Create the specification of the computation pipeline. Note
    // it's a pure POJO: no instance of Jet needed to create it.
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<String>list("text")).flatMap(word -> traverseArray(word.toLowerCase().split("\\W+"))).filter(word -> !word.isEmpty()).groupingKey(wholeItem()).aggregate(counting()).drainTo(Sinks.map("counts"));
    // Start Jet, populate the input list
    JetInstance jet = Jet.newJetInstance();
    try {
        List<String> text = jet.getList("text");
        text.add("hello world hello hello world");
        text.add("world world hello world");
        // Perform the computation
        jet.newJob(p).join();
        // Check the results
        Map<String, Long> counts = jet.getMap("counts");
        System.out.println("Count of hello: " + counts.get("hello"));
        System.out.println("Count of world: " + counts.get("world"));
    } finally {
        Jet.shutdownAll();
    }
}
Also used : Sources(com.hazelcast.jet.pipeline.Sources) AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) List(java.util.List) JetInstance(com.hazelcast.jet.JetInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Map(java.util.Map) Traversers.traverseArray(com.hazelcast.jet.Traversers.traverseArray) Sinks(com.hazelcast.jet.pipeline.Sinks) Jet(com.hazelcast.jet.Jet) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) JetInstance(com.hazelcast.jet.JetInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 20 with Sources

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

the class ImdgConnectors method s8.

static void s8() {
    ClientConfig clientConfig = new ClientConfig();
    // tag::s8[]
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<Integer, String, Person>remoteMap("inputMap", clientConfig, e -> e.getValue().getAge() > 21, e -> e.getValue().getAge()));
// end::s8[]
}
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) ClientConfig(com.hazelcast.client.config.ClientConfig) 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