Search in sources :

Example 26 with Edge

use of com.hazelcast.jet.core.Edge in project hazelcast by hazelcast.

the class RebalanceStreamStageTest method assertSingleStageAggregation.

private void assertSingleStageAggregation() {
    DAG dag = p.toDag();
    try {
        Edge srcToAggregate = dag.getOutboundEdges("add-timestamps").get(0);
        assertTrue("Outbound edge after rebalancing must be distributed", srcToAggregate.isDistributed());
        Edge aggregateToSink = dag.getOutboundEdges(srcToAggregate.getDestName()).get(0);
        List<Edge> sinkOutbound = dag.getOutboundEdges(aggregateToSink.getDestName());
        assertEquals("Aggregation after rebalancing must be single-stage", 0, sinkOutbound.size());
    } catch (AssertionError e) {
        System.err.println(dag.toDotString());
        throw e;
    }
}
Also used : DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge)

Example 27 with Edge

use of com.hazelcast.jet.core.Edge in project hazelcast by hazelcast.

the class Planner method addEdges.

public void addEdges(Transform transform, Vertex toVertex, ObjIntConsumer<Edge> configureEdgeFn) {
    int destOrdinal = 0;
    for (Transform fromTransform : transform.upstream()) {
        PlannerVertex fromPv = xform2vertex.get(fromTransform);
        Edge edge = from(fromPv.v, fromPv.nextAvailableOrdinal()).to(toVertex, destOrdinal);
        dag.edge(edge);
        configureEdgeFn.accept(edge, destOrdinal);
        applyRebalancing(edge, transform);
        destOrdinal++;
    }
}
Also used : SinkTransform(com.hazelcast.jet.impl.pipeline.transform.SinkTransform) MapTransform(com.hazelcast.jet.impl.pipeline.transform.MapTransform) TimestampTransform(com.hazelcast.jet.impl.pipeline.transform.TimestampTransform) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) StreamSourceTransform(com.hazelcast.jet.impl.pipeline.transform.StreamSourceTransform) FlatMapTransform(com.hazelcast.jet.impl.pipeline.transform.FlatMapTransform) Edge(com.hazelcast.jet.core.Edge)

Example 28 with Edge

use of com.hazelcast.jet.core.Edge in project hazelcast by hazelcast.

the class FlatMapTransform method addToDag.

@Override
public void addToDag(Planner p, Context context) {
    determineLocalParallelism(LOCAL_PARALLELISM_USE_DEFAULT, context, p.isPreserveOrder());
    PlannerVertex pv = p.addVertex(this, name(), determinedLocalParallelism(), flatMapP(flatMapFn()));
    if (p.isPreserveOrder()) {
        p.addEdges(this, pv.v, Edge::isolated);
    } else {
        p.addEdges(this, pv.v);
    }
}
Also used : PlannerVertex(com.hazelcast.jet.impl.pipeline.Planner.PlannerVertex) Edge(com.hazelcast.jet.core.Edge)

Example 29 with Edge

use of com.hazelcast.jet.core.Edge in project hazelcast by hazelcast.

the class HashJoinTransform method addToDag.

// ---------           ----------           ----------
// | primary |         | joined-1 |         | joined-2 |
// ---------           ----------           ----------
// |                   |                     |
// |              distributed          distributed
// |               broadcast            broadcast
// |                   v                     v
// |             -------------         -------------
// |            | collector-1 |       | collector-2 |
// |            | localPara=1 |       | localPara=1 |
// |             -------------         -------------
// |                   |                     |
// |                 local                 local
// local             broadcast             broadcast
// unicast           prioritized           prioritized
// ordinal 0           ordinal 1             ordinal 2
// \                   |                     |
// ----------------\  |   /----------------/
// v  v  v
// --------
// | joiner |
// --------
@Override
@SuppressWarnings("unchecked")
public void addToDag(Planner p, Context context) {
    determineLocalParallelism(LOCAL_PARALLELISM_USE_DEFAULT, context, p.isPreserveOrder());
    PlannerVertex primary = p.xform2vertex.get(this.upstream().get(0));
    List keyFns = toList(this.clauses, JoinClause::leftKeyFn);
    List<Tag> tags = this.tags;
    BiFunctionEx mapToOutputBiFn = this.mapToOutputBiFn;
    TriFunction mapToOutputTriFn = this.mapToOutputTriFn;
    // must be extracted to variable, probably because of serialization bug
    BiFunctionEx<List<Tag>, Object[], ItemsByTag> tupleToItems = tupleToItemsByTag(whereNullsNotAllowed);
    Vertex joiner = p.addVertex(this, name() + "-joiner", determinedLocalParallelism(), () -> new HashJoinP<>(keyFns, tags, mapToOutputBiFn, mapToOutputTriFn, tupleToItems)).v;
    Edge edgeToJoiner = from(primary.v, primary.nextAvailableOrdinal()).to(joiner, 0);
    if (p.isPreserveOrder()) {
        edgeToJoiner.isolated();
    } else {
        applyRebalancing(edgeToJoiner, this);
    }
    p.dag.edge(edgeToJoiner);
    String collectorName = name() + "-collector";
    int collectorOrdinal = 1;
    for (Transform fromTransform : tailList(this.upstream())) {
        PlannerVertex fromPv = p.xform2vertex.get(fromTransform);
        JoinClause<?, ?, ?, ?> clause = this.clauses.get(collectorOrdinal - 1);
        FunctionEx<Object, Object> getKeyFn = (FunctionEx<Object, Object>) clause.rightKeyFn();
        FunctionEx<Object, Object> projectFn = (FunctionEx<Object, Object>) clause.rightProjectFn();
        Vertex collector = p.dag.newVertex(collectorName + collectorOrdinal, () -> new HashJoinCollectP(getKeyFn, projectFn));
        collector.localParallelism(1);
        p.dag.edge(from(fromPv.v, fromPv.nextAvailableOrdinal()).to(collector, 0).distributed().broadcast());
        p.dag.edge(from(collector, 0).to(joiner, collectorOrdinal).broadcast().priority(-1));
        collectorOrdinal++;
    }
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) PlannerVertex(com.hazelcast.jet.impl.pipeline.Planner.PlannerVertex) HashJoinCollectP(com.hazelcast.jet.impl.processor.HashJoinCollectP) HashJoinP(com.hazelcast.jet.impl.processor.HashJoinP) ItemsByTag(com.hazelcast.jet.datamodel.ItemsByTag) PlannerVertex(com.hazelcast.jet.impl.pipeline.Planner.PlannerVertex) FunctionEx(com.hazelcast.function.FunctionEx) BiFunctionEx(com.hazelcast.function.BiFunctionEx) TriFunction(com.hazelcast.jet.function.TriFunction) Util.toList(com.hazelcast.jet.impl.util.Util.toList) List(java.util.List) Planner.tailList(com.hazelcast.jet.impl.pipeline.Planner.tailList) Tag(com.hazelcast.jet.datamodel.Tag) ItemsByTag(com.hazelcast.jet.datamodel.ItemsByTag) JoinClause(com.hazelcast.jet.pipeline.JoinClause) Edge(com.hazelcast.jet.core.Edge) BiFunctionEx(com.hazelcast.function.BiFunctionEx)

Example 30 with Edge

use of com.hazelcast.jet.core.Edge in project hazelcast by hazelcast.

the class ProcessorTransform method addToDag.

@Override
public void addToDag(Planner p, Context context) {
    determineLocalParallelism(processorSupplier.preferredLocalParallelism(), context, p.isPreserveOrder());
    PlannerVertex pv = p.addVertex(this, name(), determinedLocalParallelism(), processorSupplier);
    if (p.isPreserveOrder()) {
        p.addEdges(this, pv.v, Edge::isolated);
    } else {
        p.addEdges(this, pv.v);
    }
}
Also used : PlannerVertex(com.hazelcast.jet.impl.pipeline.Planner.PlannerVertex) Edge(com.hazelcast.jet.core.Edge)

Aggregations

Edge (com.hazelcast.jet.core.Edge)39 DAG (com.hazelcast.jet.core.DAG)22 FunctionEx (com.hazelcast.function.FunctionEx)16 List (java.util.List)16 Test (org.junit.Test)16 JetException (com.hazelcast.jet.JetException)12 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)12 AggregateOperation1 (com.hazelcast.jet.aggregate.AggregateOperation1)12 AggregateOperations (com.hazelcast.jet.aggregate.AggregateOperations)12 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)12 QuickTest (com.hazelcast.test.annotation.QuickTest)12 AggregateOperation (com.hazelcast.jet.aggregate.AggregateOperation)11 Collections.singletonList (java.util.Collections.singletonList)11 Function (java.util.function.Function)11 Function.identity (java.util.function.Function.identity)10 Assert.assertEquals (org.junit.Assert.assertEquals)10 Assert.assertNotNull (org.junit.Assert.assertNotNull)10 Assert.assertNull (org.junit.Assert.assertNull)10 Assert.assertTrue (org.junit.Assert.assertTrue)10 ItemsByTag (com.hazelcast.jet.datamodel.ItemsByTag)9