Search in sources :

Example 6 with Util

use of com.hazelcast.jet.Util in project hazelcast by hazelcast.

the class ReadFilesPTest method pipeline.

private Pipeline pipeline(String glob) {
    Pipeline p = Pipeline.create();
    p.readFrom(Sources.filesBuilder(directory.getPath()).glob(glob == null ? "*" : glob).build(Util::entry)).writeTo(Sinks.list(list));
    return p;
}
Also used : Util(com.hazelcast.jet.Util) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 7 with Util

use of com.hazelcast.jet.Util in project hazelcast-jet by hazelcast.

the class StreamFilesPTest method when_metaSupplier_then_returnsCorrectProcessors.

@Test
public void when_metaSupplier_then_returnsCorrectProcessors() {
    ProcessorMetaSupplier metaSupplier = streamFilesP(workDir.getAbsolutePath(), UTF_8, "*", Util::entry);
    Address a = new Address();
    ProcessorSupplier supplier = metaSupplier.get(singletonList(a)).apply(a);
    supplier.init(new TestProcessorContext());
    assertEquals(1, supplier.get(1).size());
    supplier.close(null);
}
Also used : Address(com.hazelcast.nio.Address) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) IOUtil(com.hazelcast.nio.IOUtil) Util(com.hazelcast.jet.Util) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Test(org.junit.Test)

Example 8 with Util

use of com.hazelcast.jet.Util in project hazelcast-jet by hazelcast.

the class StreamFilesP_integrationTest method buildDag.

private DAG buildDag() {
    DAG dag = new DAG();
    Vertex reader = dag.newVertex("reader", streamFilesP(directory.getPath(), UTF_8, "*", Util::entry)).localParallelism(1);
    Vertex writer = dag.newVertex("writer", writeListP(list.getName())).localParallelism(1);
    dag.edge(between(reader, writer));
    return dag;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Util(com.hazelcast.jet.Util) DAG(com.hazelcast.jet.core.DAG)

Example 9 with Util

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

the class TfIdfCoreApi method createDag.

private static DAG createDag() {
    DistributedFunction<Entry<Entry<?, String>, ?>, String> byWord = item -> item.getKey().getValue();
    DistributedBiFunction<Long, Object, Long> counter = (count, x) -> count + 1;
    DAG dag = new DAG();
    Vertex stopwordSource = // tag::s2[]
    dag.newVertex("stopword-source", StopwordsP::new);
    // end::s2[]
    Vertex docSource = // tag::s1[]
    dag.newVertex("doc-source", readMapP(DOCID_NAME));
    // end::s1[]
    Vertex docCount = // tag::s4[]
    dag.newVertex("doc-count", Processors.aggregateP(counting()));
    // end::s4[]
    // tag::s5[]
    Vertex docLines = dag.newVertex("doc-lines", nonCooperativeP(flatMapP((Entry<Long, String> e) -> traverseStream(docLines("books/" + e.getValue()).map(line -> entry(e.getKey(), line))))));
    // end::s5[]
    Vertex tokenize = // tag::s6[]
    dag.newVertex("tokenize", TokenizeP::new);
    // end::s6[]
    Vertex tf = // tag::s9[]
    dag.newVertex("tf", aggregateByKeyP(singletonList(wholeItem()), counting(), Util::entry));
    // end::s9[]
    Vertex tfidf = // tag::s10[]
    dag.newVertex("tf-idf", TfIdfP::new);
    // end::s10[]
    Vertex sink = // tag::s12[]
    dag.newVertex("sink", SinkProcessors.writeMapP(INVERTED_INDEX));
    // end::s12[]
    stopwordSource.localParallelism(1);
    docSource.localParallelism(1);
    docCount.localParallelism(1);
    docLines.localParallelism(1);
    // tag::s8[]
    dag.edge(between(stopwordSource, tokenize).broadcast().priority(-1)).edge(from(docLines).to(tokenize, 1));
    return dag.edge(between(docSource, docCount).distributed().broadcast()).edge(from(docSource, 1).to(docLines)).edge(between(tokenize, tf).partitioned(wholeItem(), HASH_CODE)).edge(between(docCount, tfidf).broadcast().priority(-1)).edge(from(tf).to(tfidf, 1).distributed().partitioned(byWord, HASH_CODE)).edge(between(tfidf, sink));
}
Also used : AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) Traverser(com.hazelcast.jet.Traverser) Arrays(java.util.Arrays) URISyntaxException(java.net.URISyntaxException) Processors(com.hazelcast.jet.core.processor.Processors) Traversers.traverseStream(com.hazelcast.jet.Traversers.traverseStream) HashMap(java.util.HashMap) SourceProcessors.readMapP(com.hazelcast.jet.core.processor.SourceProcessors.readMapP) DistributedBiFunction(com.hazelcast.jet.function.DistributedBiFunction) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Traversers.lazy(com.hazelcast.jet.Traversers.lazy) Traversers.traverseIterable(com.hazelcast.jet.Traversers.traverseIterable) Util.entry(com.hazelcast.jet.Util.entry) Map(java.util.Map) Processors.nonCooperativeP(com.hazelcast.jet.core.processor.Processors.nonCooperativeP) Edge.from(com.hazelcast.jet.core.Edge.from) DAG(com.hazelcast.jet.core.DAG) DistributedFunction(com.hazelcast.jet.function.DistributedFunction) Processors.flatMapP(com.hazelcast.jet.core.processor.Processors.flatMapP) Nonnull(javax.annotation.Nonnull) Collectors.toSet(java.util.stream.Collectors.toSet) Files(java.nio.file.Files) Set(java.util.Set) IOException(java.io.IOException) Vertex(com.hazelcast.jet.core.Vertex) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) Processors.aggregateByKeyP(com.hazelcast.jet.core.processor.Processors.aggregateByKeyP) SinkProcessors(com.hazelcast.jet.core.processor.SinkProcessors) Entry(java.util.Map.Entry) HASH_CODE(com.hazelcast.jet.core.Partitioner.HASH_CODE) Pattern(java.util.regex.Pattern) Util(com.hazelcast.jet.Util) Edge.between(com.hazelcast.jet.core.Edge.between) Vertex(com.hazelcast.jet.core.Vertex) Entry(java.util.Map.Entry) DAG(com.hazelcast.jet.core.DAG)

Aggregations

Util (com.hazelcast.jet.Util)9 DAG (com.hazelcast.jet.core.DAG)6 Vertex (com.hazelcast.jet.core.Vertex)5 Test (org.junit.Test)4 Util.entry (com.hazelcast.jet.Util.entry)3 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)3 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)3 ArrayList (java.util.ArrayList)3 Collections.singletonList (java.util.Collections.singletonList)3 List (java.util.List)3 FunctionEx (com.hazelcast.function.FunctionEx)2 Functions.wholeItem (com.hazelcast.function.Functions.wholeItem)2 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)2 AggregateOperations.counting (com.hazelcast.jet.aggregate.AggregateOperations.counting)2 Processors (com.hazelcast.jet.core.processor.Processors)2 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Arrays (java.util.Arrays)2 Entry (java.util.Map.Entry)2