Search in sources :

Example 11 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast-jet by hazelcast.

the class GroupingSinkReducer method reduce.

@Override
public R reduce(StreamContext context, Pipe<? extends T> upstream) {
    DAG dag = new DAG();
    Vertex previous = upstream.buildDAG(dag);
    Vertex merger = dag.newVertex("group-and-accumulate", () -> new GroupAndAccumulateP<>(classifier, collector));
    Vertex combiner = dag.newVertex("combine-groups", () -> new CombineGroupsP<>(collector));
    Vertex writer = dag.newVertex(sinkName, metaSupplier);
    dag.edge(between(previous, merger).partitioned(classifier::apply, HASH_CODE)).edge(between(merger, combiner).distributed().partitioned(entryKey())).edge(between(combiner, writer));
    executeJob(context, dag);
    return toDistributedObject.apply(context.getJetInstance());
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) DAG(com.hazelcast.jet.core.DAG)

Example 12 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast-jet by hazelcast.

the class IListReducer method reduce.

@Override
public IListJet<T> reduce(StreamContext context, Pipe<? extends T> upstream) {
    IListJet<T> target = context.getJetInstance().getList(listName);
    DAG dag = new DAG();
    Vertex vertex = upstream.buildDAG(dag);
    Vertex writer = dag.newVertex("write-list-" + listName, SinkProcessors.writeListP(listName)).localParallelism(1);
    dag.edge(between(vertex, writer));
    executeJob(context, dag);
    return target;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) DAG(com.hazelcast.jet.core.DAG)

Example 13 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast-jet by hazelcast.

the class DistinctPipe method orderedGraph.

@Nonnull
private Vertex orderedGraph(DAG dag) {
    Vertex previous = upstream.buildDAG(dag);
    Vertex distinct = dag.newVertex(uniqueVertexName("distinct"), DistinctP::new).localParallelism(1);
    dag.edge(between(previous, distinct));
    return distinct;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Nonnull(javax.annotation.Nonnull)

Example 14 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast-jet by hazelcast.

the class WindowGroupTransform method addSlidingWindowTwoStage.

// ---------       ---------
// | source0 | ... | sourceN |
// ---------       ---------
// |               |
// local           local
// partitioned     partitioned
// v               v
// --------------------
// | accumulateByFrameP |
// --------------------
// |
// distributed
// partitioned
// v
// -------------------------
// | combineToSlidingWindowP |
// -------------------------
private void addSlidingWindowTwoStage(Planner p, SlidingWindowDef wDef) {
    String namePrefix = p.uniqueVertexName(name(), "-step");
    SlidingWindowPolicy winPolicy = wDef.toSlidingWindowPolicy();
    Vertex v1 = p.dag.newVertex(namePrefix + '1', accumulateByFrameP(keyFns, nCopies(keyFns.size(), (DistributedToLongFunction<JetEvent>) JetEvent::timestamp), TimestampKind.EVENT, winPolicy, aggrOp));
    v1.localParallelism(localParallelism());
    PlannerVertex pv2 = p.addVertex(this, namePrefix + '2', localParallelism(), combineToSlidingWindowP(winPolicy, aggrOp, mapToOutputFn));
    p.addEdges(this, v1, (e, ord) -> e.partitioned(keyFns.get(ord), HASH_CODE));
    p.dag.edge(between(v1, pv2.v).distributed().partitioned(entryKey()));
}
Also used : PlannerVertex(com.hazelcast.jet.impl.pipeline.Planner.PlannerVertex) Vertex(com.hazelcast.jet.core.Vertex) PlannerVertex(com.hazelcast.jet.impl.pipeline.Planner.PlannerVertex) SlidingWindowPolicy(com.hazelcast.jet.core.SlidingWindowPolicy) JetEvent(com.hazelcast.jet.impl.pipeline.JetEvent)

Example 15 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast-jet by hazelcast.

the class SkipPipe method buildDAG.

@Override
public Vertex buildDAG(DAG dag) {
    Vertex previous = upstream.buildDAG(dag);
    // required final for lambda variable capture
    final long skip = this.skip;
    Vertex skipVertex = dag.newVertex(uniqueVertexName("skip"), () -> new SkipP(skip)).localParallelism(1);
    Edge edge = between(previous, skipVertex);
    // if upstream is not ordered, we need to shuffle data to one node
    if (!upstream.isOrdered()) {
        edge = edge.distributed().allToOne();
    }
    dag.edge(edge);
    return skipVertex;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) SkipP(com.hazelcast.jet.stream.impl.processor.SkipP) Edge(com.hazelcast.jet.core.Edge)

Aggregations

Vertex (com.hazelcast.jet.core.Vertex)189 DAG (com.hazelcast.jet.core.DAG)130 Test (org.junit.Test)95 QuickTest (com.hazelcast.test.annotation.QuickTest)57 Job (com.hazelcast.jet.Job)53 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)48 Entry (java.util.Map.Entry)41 List (java.util.List)28 Edge.between (com.hazelcast.jet.core.Edge.between)26 Map (java.util.Map)26 Assert.assertEquals (org.junit.Assert.assertEquals)23 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)21 IntStream (java.util.stream.IntStream)21 Assert.assertTrue (org.junit.Assert.assertTrue)19 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)18 Category (org.junit.experimental.categories.Category)18 Collectors.toList (java.util.stream.Collectors.toList)17 Nonnull (javax.annotation.Nonnull)17 FunctionEx (com.hazelcast.function.FunctionEx)15 Edge (com.hazelcast.jet.core.Edge)15