Search in sources :

Example 36 with Edge

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

the class CreateDagVisitor method onUnion.

public Vertex onUnion(UnionPhysicalRel rel) {
    // UNION_TO_DISTINCT rule : Union[all=false] -> Union[all=true] + Aggregate.
    if (!rel.all) {
        throw new RuntimeException("Union[all=false] rel should never be produced");
    }
    Vertex merger = dag.newUniqueVertex("UnionMerger", ProcessorSupplier.of(mapP(FunctionEx.identity())));
    int ordinal = 0;
    for (RelNode input : rel.getInputs()) {
        Vertex inputVertex = ((PhysicalRel) input).accept(this);
        Edge edge = Edge.from(inputVertex).to(merger, ordinal++);
        dag.edge(edge);
    }
    return merger;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) RelNode(org.apache.calcite.rel.RelNode) Edge(com.hazelcast.jet.core.Edge)

Example 37 with Edge

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

the class CreateDagVisitor method connectJoinInput.

private void connectJoinInput(JetJoinInfo joinInfo, RelNode leftInputRel, RelNode rightInputRel, Vertex joinVertex) {
    Vertex leftInput = ((PhysicalRel) leftInputRel).accept(this);
    Vertex rightInput = ((PhysicalRel) rightInputRel).accept(this);
    Edge left = between(leftInput, joinVertex).priority(LOW_PRIORITY).broadcast().distributed();
    Edge right = from(rightInput).to(joinVertex, 1).priority(HIGH_PRIORITY).unicast().local();
    if (joinInfo.isLeftOuter()) {
        left = left.unicast().local();
        right = right.broadcast().distributed();
    }
    if (joinInfo.isEquiJoin()) {
        left = left.distributed().partitioned(ObjectArrayKey.projectFn(joinInfo.leftEquiJoinIndices()));
        right = right.distributed().partitioned(ObjectArrayKey.projectFn(joinInfo.rightEquiJoinIndices()));
    }
    dag.edge(left);
    dag.edge(right);
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Edge(com.hazelcast.jet.core.Edge)

Example 38 with Edge

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

the class RebalanceStreamStageTest method when_peekAndRebalanceAndMap_then_dagEdgeDistributed.

@Test
public void when_peekAndRebalanceAndMap_then_dagEdgeDistributed() {
    // Given
    List<Integer> input = sequence(itemCount);
    StreamStage<Integer> srcStage = streamStageFromList(input);
    FunctionEx<Integer, String> formatFn = i -> String.format("%04d-string", i);
    // When
    StreamStage<String> mapped = srcStage.peek().rebalance().map(formatFn);
    // Then
    mapped.writeTo(sink);
    DAG dag = p.toDag();
    Edge srcToMap = dag.getInboundEdges("map").get(0);
    assertTrue("Rebalancing should make the edge distributed", srcToMap.isDistributed());
    assertNull("Didn't rebalance by key, the edge must not be partitioned", srcToMap.getPartitioner());
    execute();
    assertEquals(streamToString(input.stream(), formatFn), streamToString(sinkStreamOf(String.class), identity()));
}
Also used : FunctionEx(com.hazelcast.function.FunctionEx) KeyedWindowResult(com.hazelcast.jet.datamodel.KeyedWindowResult) Assert.assertNotNull(org.junit.Assert.assertNotNull) AggregateOperations(com.hazelcast.jet.aggregate.AggregateOperations) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AggregateOperation1(com.hazelcast.jet.aggregate.AggregateOperation1) JetException(com.hazelcast.jet.JetException) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) WindowDefinition.tumbling(com.hazelcast.jet.pipeline.WindowDefinition.tumbling) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Function.identity(java.util.function.Function.identity) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) Assert.assertEquals(org.junit.Assert.assertEquals) WindowResult(com.hazelcast.jet.datamodel.WindowResult) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) Test(org.junit.Test)

Example 39 with Edge

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

the class RebalanceStreamStageTest method assertTwoStageAggregation.

private void assertTwoStageAggregation(boolean isRebalanceByKey) {
    DAG dag = p.toDag();
    try {
        Edge srcToAggregate = dag.getOutboundEdges("add-timestamps").get(0);
        assertEquals(isRebalanceByKey ? "Edge to aggregation after rebalancing by key must be partitioned" : "Rebalanced edge to global aggregation must be unicast", isRebalanceByKey, srcToAggregate.getPartitioner() != null);
        assertTrue("Outbound edge after rebalancing must be distributed", srcToAggregate.isDistributed());
        String accumulatingVertexName = srcToAggregate.getDestName();
        String aggregatePrepare = "sliding-window-prepare";
        assertEquals("Aggregation must be two-stage;", aggregatePrepare, accumulatingVertexName.substring(accumulatingVertexName.length() - aggregatePrepare.length()));
        Edge internalAggregationEdge = dag.getOutboundEdges(accumulatingVertexName).get(0);
        assertTrue("Internal aggregation edge must be distributed", internalAggregationEdge.isDistributed());
        assertNotNull("Internal aggregation edge must be partitioned", internalAggregationEdge.getPartitioner());
    } catch (AssertionError e) {
        System.err.println(dag.toDotString());
        throw e;
    }
}
Also used : DAG(com.hazelcast.jet.core.DAG) 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