Search in sources :

Example 6 with Jet

use of com.hazelcast.jet.Jet 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 7 with Jet

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

the class ImdgConnectors method s14.

static void s14() {
    JetInstance jet = Jet.newJetInstance();
    // tag::s14[]
    IList<Integer> inputList = jet.getList("inputList");
    for (int i = 0; i < 10; i++) {
        inputList.add(i);
    }
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<Integer>list("inputList")).map(i -> "item" + i).drainTo(Sinks.list("resultList"));
    jet.newJob(p).join();
    IList<String> resultList = jet.getList("resultList");
    System.out.println("Results: " + new ArrayList<>(resultList));
// end::s14[]
}
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) JetInstance(com.hazelcast.jet.JetInstance) ArrayList(java.util.ArrayList) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 8 with Jet

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

the class LogDebug method s3.

static void s3() {
    // tag::s3[]
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<String>list("inputList")).flatMap(line -> traverseArray(line.toLowerCase().split("\\W+"))).filter(word -> !word.isEmpty()).peek().groupingKey(wholeItem()).aggregate(counting()).drainTo(Sinks.map("counts"));
    // end::s3[]
    // tag::s4[]
    JetInstance jet = Jet.newJetInstance();
    try {
        jet.getList("inputList").addAll(asList("The quick brown fox", "jumped over the lazy dog"));
        jet.newJob(p).join();
    } finally {
        Jet.shutdownAll();
    }
// end::s4[]
}
Also used : Sources(com.hazelcast.jet.pipeline.Sources) JetConfig(com.hazelcast.jet.config.JetConfig) AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) JetInstance(com.hazelcast.jet.JetInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Arrays.asList(java.util.Arrays.asList) 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 9 with Jet

use of com.hazelcast.jet.Jet in project gora by apache.

the class JetTest method jetWordCount.

@Test
public void jetWordCount() throws GoraException {
    dataStoreOut = DataStoreFactory.getDataStore(Long.class, ResultPageView.class, utility.getConfiguration());
    Query<Long, ResultPageView> query = dataStoreOut.newQuery();
    JetEngine<Long, ResultPageView, Long, ResultPageView> jetEngine = new JetEngine<>();
    Pattern delimiter = Pattern.compile("\\W+");
    Pipeline p = Pipeline.create();
    p.drawFrom(jetEngine.createDataSource(dataStoreOut, query)).flatMap(e -> traverseArray(delimiter.split(e.getValue().getUrl().toString()))).filter(word -> !word.isEmpty()).groupingKey(wholeItem()).aggregate(counting()).drainTo(Sinks.map("COUNTS"));
    JetInstance jet = Jet.newJetInstance();
    ;
    jet.newJob(p).join();
    IMap<String, Long> counts = jet.getMap("COUNTS");
    assertEquals(3L, (long) counts.get("the"));
}
Also used : AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) JetInstance(com.hazelcast.jet.JetInstance) BatchSource(com.hazelcast.jet.pipeline.BatchSource) BeforeClass(org.junit.BeforeClass) Pipeline(com.hazelcast.jet.pipeline.Pipeline) DataStore(org.apache.gora.store.DataStore) Functions.wholeItem(com.hazelcast.jet.function.Functions.wholeItem) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) Pageview(org.apache.gora.jet.generated.Pageview) ResultPageView(org.apache.gora.jet.generated.ResultPageView) Result(org.apache.gora.query.Result) DataStoreFactory(org.apache.gora.store.DataStoreFactory) IMap(com.hazelcast.core.IMap) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) Query(org.apache.gora.query.Query) Traversers.traverseArray(com.hazelcast.jet.Traversers.traverseArray) Jet(com.hazelcast.jet.Jet) Pattern(java.util.regex.Pattern) GoraException(org.apache.gora.util.GoraException) Assert.assertEquals(org.junit.Assert.assertEquals) Pattern(java.util.regex.Pattern) ResultPageView(org.apache.gora.jet.generated.ResultPageView) JetInstance(com.hazelcast.jet.JetInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Aggregations

Jet (com.hazelcast.jet.Jet)9 JetInstance (com.hazelcast.jet.JetInstance)9 Sources (com.hazelcast.jet.pipeline.Sources)6 IMap (com.hazelcast.core.IMap)5 DistributedFunctions.wholeItem (com.hazelcast.jet.function.DistributedFunctions.wholeItem)5 Pipeline (com.hazelcast.jet.pipeline.Pipeline)5 Sinks (com.hazelcast.jet.pipeline.Sinks)5 Map (java.util.Map)5 IList (com.hazelcast.core.IList)4 Traversers.traverseArray (com.hazelcast.jet.Traversers.traverseArray)4 AggregateOperations.counting (com.hazelcast.jet.aggregate.AggregateOperations.counting)4 Collectors (java.util.stream.Collectors)4 IMapJet (com.hazelcast.jet.IMapJet)3 DistributedCollectors (com.hazelcast.jet.stream.DistributedCollectors)3 DistributedCollectors.toMap (com.hazelcast.jet.stream.DistributedCollectors.toMap)3 DistributedStream (com.hazelcast.jet.stream.DistributedStream)3 Arrays (java.util.Arrays)3 Stream (java.util.stream.Stream)3 JetConfig (com.hazelcast.jet.config.JetConfig)2 Functions.wholeItem (com.hazelcast.jet.function.Functions.wholeItem)2