Search in sources :

Example 1 with Jet

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

the class JUS method s3.

static void s3() {
    JetInstance jet = Jet.newJetInstance();
    // tag::s3[]
    // <1>
    IMapJet<String, String> map = jet.getMap("large_map");
    Map<String, String> result = DistributedStream.fromMap(map).map(e -> e.getKey() + e.getValue()).collect(// <2>
    DistributedCollectors.toMap(v -> v, v -> v));
// end::s3[]
}
Also used : Arrays(java.util.Arrays) JetInstance(com.hazelcast.jet.JetInstance) IMapJet(com.hazelcast.jet.IMapJet) Collectors(java.util.stream.Collectors) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) Sources(com.hazelcast.jet.pipeline.Sources) IMap(com.hazelcast.core.IMap) DistributedCollectors(com.hazelcast.jet.stream.DistributedCollectors) Stream(java.util.stream.Stream) Map(java.util.Map) IList(com.hazelcast.core.IList) DistributedStream(com.hazelcast.jet.stream.DistributedStream) Jet(com.hazelcast.jet.Jet) DistributedCollectors.toMap(com.hazelcast.jet.stream.DistributedCollectors.toMap) JetInstance(com.hazelcast.jet.JetInstance)

Example 2 with Jet

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

the class JUS method s4.

static void s4() {
    JetInstance jet = Jet.newJetInstance();
    // tag::s4[]
    IMap<String, Long> counts = DistributedStream.<String>fromList(jet.getList("text")).flatMap(line -> Stream.of(line.toLowerCase().split("\\W+"))).filter(word -> !word.isEmpty()).collect(DistributedCollectors.groupingByToIMap("counts", wholeItem(), DistributedCollectors.counting()));
// end::s4[]
}
Also used : Arrays(java.util.Arrays) JetInstance(com.hazelcast.jet.JetInstance) IMapJet(com.hazelcast.jet.IMapJet) Collectors(java.util.stream.Collectors) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) Sources(com.hazelcast.jet.pipeline.Sources) IMap(com.hazelcast.core.IMap) DistributedCollectors(com.hazelcast.jet.stream.DistributedCollectors) Stream(java.util.stream.Stream) Map(java.util.Map) IList(com.hazelcast.core.IList) DistributedStream(com.hazelcast.jet.stream.DistributedStream) Jet(com.hazelcast.jet.Jet) DistributedCollectors.toMap(com.hazelcast.jet.stream.DistributedCollectors.toMap) JetInstance(com.hazelcast.jet.JetInstance)

Example 3 with Jet

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

the class JUS method s1.

static void s1() {
    JetInstance jet = Jet.newJetInstance();
    try {
        // tag::s1[]
        IMapJet<String, Integer> map = jet.getMap("latitudes");
        map.put("London", 51);
        map.put("Paris", 48);
        map.put("NYC", 40);
        map.put("Sydney", -34);
        map.put("Sao Paulo", -23);
        map.put("Jakarta", -6);
        DistributedStream.fromMap(map).filter(e -> e.getValue() < 0).forEach(System.out::println);
    // end::s1[]
    } finally {
        Jet.shutdownAll();
    }
}
Also used : Arrays(java.util.Arrays) JetInstance(com.hazelcast.jet.JetInstance) IMapJet(com.hazelcast.jet.IMapJet) Collectors(java.util.stream.Collectors) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) Sources(com.hazelcast.jet.pipeline.Sources) IMap(com.hazelcast.core.IMap) DistributedCollectors(com.hazelcast.jet.stream.DistributedCollectors) Stream(java.util.stream.Stream) Map(java.util.Map) IList(com.hazelcast.core.IList) DistributedStream(com.hazelcast.jet.stream.DistributedStream) Jet(com.hazelcast.jet.Jet) DistributedCollectors.toMap(com.hazelcast.jet.stream.DistributedCollectors.toMap) JetInstance(com.hazelcast.jet.JetInstance)

Example 4 with Jet

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

the class S8 method main.

// end::s1[]
static void main() {
    // tag::s2[]
    JetInstance jet = Jet.newJetInstance();
    int upperBound = 10;
    DAG dag = new DAG();
    Vertex generateNumbers = dag.newVertex("generate-numbers", () -> new GenerateNumbersP(upperBound));
    Vertex logInput = dag.newVertex("log-input", DiagnosticProcessors.writeLoggerP(i -> "Received number: " + i));
    dag.edge(Edge.between(generateNumbers, logInput));
    try {
        jet.newJob(dag).join();
    } finally {
        Jet.shutdownAll();
    }
// end::s2[]
}
Also used : IntStream(java.util.stream.IntStream) AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) Traverser(com.hazelcast.jet.Traverser) DiagnosticProcessors(com.hazelcast.jet.core.processor.DiagnosticProcessors) JetInstance(com.hazelcast.jet.JetInstance) IntStream.range(java.util.stream.IntStream.range) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Processor(com.hazelcast.jet.core.Processor) Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) Traversers(com.hazelcast.jet.Traversers) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Vertex(com.hazelcast.jet.core.Vertex) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Map(java.util.Map) Context(com.hazelcast.jet.core.Processor.Context) Jet(com.hazelcast.jet.Jet) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) Nonnull(javax.annotation.Nonnull) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Vertex(com.hazelcast.jet.core.Vertex) JetInstance(com.hazelcast.jet.JetInstance) DAG(com.hazelcast.jet.core.DAG)

Example 5 with Jet

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

the class JetTest method testNewJetSource.

@Test
public void testNewJetSource() throws Exception {
    DataStore<Long, Pageview> dataStoreIn;
    dataStoreIn = DataStoreFactory.getDataStore(Long.class, Pageview.class, utility.getConfiguration());
    dataStoreOut = DataStoreFactory.getDataStore(Long.class, ResultPageView.class, utility.getConfiguration());
    query = dataStoreIn.newQuery();
    query.setStartKey(0L);
    query.setEndKey(55L);
    JetEngine<Long, Pageview, Long, ResultPageView> jetEngine = new JetEngine<>();
    BatchSource<JetInputOutputFormat<Long, Pageview>> fileSource = jetEngine.createDataSource(dataStoreIn, query);
    Pipeline p = Pipeline.create();
    p.drawFrom(fileSource).filter(item -> item.getValue().getIp().toString().equals("88.240.129.183")).map(e -> {
        ResultPageView resultPageView = new ResultPageView();
        resultPageView.setIp(e.getValue().getIp());
        resultPageView.setTimestamp(e.getValue().getTimestamp());
        resultPageView.setUrl(e.getValue().getUrl());
        return new JetInputOutputFormat<Long, ResultPageView>(e.getValue().getTimestamp(), resultPageView);
    }).drainTo(jetEngine.createDataSink(dataStoreOut));
    JetInstance jet = Jet.newJetInstance();
    Jet.newJetInstance();
    try {
        jet.newJob(p).join();
    } finally {
        Jet.shutdownAll();
    }
    Query<Long, ResultPageView> query = dataStoreOut.newQuery();
    Result<Long, ResultPageView> result = query.execute();
    int noOfOutputRecords = 0;
    String ip = "";
    while (result.next()) {
        noOfOutputRecords++;
        ip = result.get().getIp().toString();
        assertEquals("88.240.129.183", ip);
    }
    assertEquals(2, noOfOutputRecords);
}
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) JetInstance(com.hazelcast.jet.JetInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Pageview(org.apache.gora.jet.generated.Pageview) ResultPageView(org.apache.gora.jet.generated.ResultPageView) 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