Search in sources :

Example 1 with Edge

use of com.hazelcast.jet.core.Edge 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)

Example 2 with Edge

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

the class CreateDagVisitor method connectInput.

/**
 * Converts the {@code inputRel} into a {@code Vertex} by visiting it and
 * create an edge from the input vertex into {@code thisVertex}.
 *
 * @param configureEdgeFn optional function to configure the edge
 * @return the input vertex
 */
private Vertex connectInput(RelNode inputRel, Vertex thisVertex, @Nullable Consumer<Edge> configureEdgeFn) {
    Vertex inputVertex = ((PhysicalRel) inputRel).accept(this);
    Edge edge = between(inputVertex, thisVertex);
    if (configureEdgeFn != null) {
        configureEdgeFn.accept(edge);
    }
    dag.edge(edge);
    return inputVertex;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Edge(com.hazelcast.jet.core.Edge)

Example 3 with Edge

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

the class CreateDagVisitor method onSlidingWindowAggregate.

public Vertex onSlidingWindowAggregate(SlidingWindowAggregatePhysicalRel rel) {
    FunctionEx<JetSqlRow, ?> groupKeyFn = rel.groupKeyFn();
    AggregateOperation<?, JetSqlRow> aggregateOperation = rel.aggrOp();
    Expression<?> timestampExpression = rel.timestampExpression();
    ToLongFunctionEx<JetSqlRow> timestampFn = row -> WindowUtils.extractMillis(timestampExpression.eval(row.getRow(), MOCK_EEC));
    SlidingWindowPolicy windowPolicy = rel.windowPolicyProvider().apply(MOCK_EEC);
    KeyedWindowResultFunction<? super Object, ? super JetSqlRow, ?> resultMapping = rel.outputValueMapping();
    if (rel.numStages() == 1) {
        Vertex vertex = dag.newUniqueVertex("Sliding-Window-AggregateByKey", Processors.aggregateToSlidingWindowP(singletonList(groupKeyFn), singletonList(timestampFn), TimestampKind.EVENT, windowPolicy, 0, aggregateOperation, resultMapping));
        connectInput(rel.getInput(), vertex, edge -> edge.distributeTo(localMemberAddress).allToOne(""));
        return vertex;
    } else {
        assert rel.numStages() == 2;
        Vertex vertex1 = dag.newUniqueVertex("Sliding-Window-AccumulateByKey", Processors.accumulateByFrameP(singletonList(groupKeyFn), singletonList(timestampFn), TimestampKind.EVENT, windowPolicy, aggregateOperation));
        Vertex vertex2 = dag.newUniqueVertex("Sliding-Window-CombineByKey", Processors.combineToSlidingWindowP(windowPolicy, aggregateOperation, resultMapping));
        connectInput(rel.getInput(), vertex1, edge -> edge.partitioned(groupKeyFn));
        dag.edge(between(vertex1, vertex2).distributed().partitioned(entryKey()));
        return vertex2;
    }
}
Also used : Address(com.hazelcast.cluster.Address) Traverser(com.hazelcast.jet.Traverser) ExpressionValues(com.hazelcast.jet.sql.impl.opt.ExpressionValues) PlanObjectKey(com.hazelcast.sql.impl.optimizer.PlanObjectKey) Processors.mapP(com.hazelcast.jet.core.processor.Processors.mapP) SourceProcessors.convenientSourceP(com.hazelcast.jet.core.processor.SourceProcessors.convenientSourceP) QueryParameterMetadata(com.hazelcast.sql.impl.QueryParameterMetadata) Collections.singletonList(java.util.Collections.singletonList) BiFunctionEx(com.hazelcast.function.BiFunctionEx) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) ObjectArrayKey(com.hazelcast.jet.sql.impl.ObjectArrayKey) SlidingWindowPolicy(com.hazelcast.jet.core.SlidingWindowPolicy) SqlConnectorUtil(com.hazelcast.jet.sql.impl.connector.SqlConnectorUtil) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) Functions.entryKey(com.hazelcast.function.Functions.entryKey) SqlConnectorUtil.getJetSqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnectorUtil.getJetSqlConnector) DAG(com.hazelcast.jet.core.DAG) RootResultConsumerSink.rootResultConsumerSink(com.hazelcast.jet.sql.impl.processors.RootResultConsumerSink.rootResultConsumerSink) ServiceFactories(com.hazelcast.jet.pipeline.ServiceFactories) FunctionEx(com.hazelcast.function.FunctionEx) KeyedWindowResultFunction(com.hazelcast.jet.core.function.KeyedWindowResultFunction) Predicate(java.util.function.Predicate) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) ConsumerEx(com.hazelcast.function.ConsumerEx) IMapSqlConnector(com.hazelcast.jet.sql.impl.connector.map.IMapSqlConnector) ExpressionUtil(com.hazelcast.jet.sql.impl.ExpressionUtil) Processors.filterUsingServiceP(com.hazelcast.jet.core.processor.Processors.filterUsingServiceP) List(java.util.List) ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) Processors.mapUsingServiceP(com.hazelcast.jet.core.processor.Processors.mapUsingServiceP) Table(com.hazelcast.sql.impl.schema.Table) ComparatorEx(com.hazelcast.function.ComparatorEx) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) Processors(com.hazelcast.jet.core.processor.Processors) Processors.flatMapUsingServiceP(com.hazelcast.jet.core.processor.Processors.flatMapUsingServiceP) TimestampKind(com.hazelcast.jet.core.TimestampKind) Function(java.util.function.Function) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) HashSet(java.util.HashSet) Edge.from(com.hazelcast.jet.core.Edge.from) Edge(com.hazelcast.jet.core.Edge) Expression(com.hazelcast.sql.impl.expression.Expression) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) VertexWithInputConfig(com.hazelcast.jet.sql.impl.connector.SqlConnector.VertexWithInputConfig) SingleRel(org.apache.calcite.rel.SingleRel) Nullable(javax.annotation.Nullable) JetJoinInfo(com.hazelcast.jet.sql.impl.JetJoinInfo) NodeEngine(com.hazelcast.spi.impl.NodeEngine) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) RelNode(org.apache.calcite.rel.RelNode) Consumer(java.util.function.Consumer) Vertex(com.hazelcast.jet.core.Vertex) ToLongFunctionEx(com.hazelcast.function.ToLongFunctionEx) SqlHashJoinP(com.hazelcast.jet.sql.impl.processors.SqlHashJoinP) ConstantExpression(com.hazelcast.sql.impl.expression.ConstantExpression) Processors.sortP(com.hazelcast.jet.core.processor.Processors.sortP) DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) WindowUtils(com.hazelcast.jet.sql.impl.aggregate.WindowUtils) Edge.between(com.hazelcast.jet.core.Edge.between) Vertex(com.hazelcast.jet.core.Vertex) SlidingWindowPolicy(com.hazelcast.jet.core.SlidingWindowPolicy) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow)

Example 4 with Edge

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

the class AggregateTransform method addToDagTwoStage.

// WHEN PRESERVE ORDER IS NOT ACTIVE
// ---------       ---------
// | source0 | ... | sourceN |
// ---------       ---------
// |              |
// local          local
// unicast        unicast
// v              v
// -------------------
// |    accumulateP    |
// -------------------
// |
// distributed
// all-to-one
// v
// ----------------
// |    combineP    | local parallelism = 1
// ----------------
// WHEN PRESERVE ORDER IS ACTIVE
// ---------       ---------
// | source0 | ... | sourceN |
// ---------       ---------
// |              |
// isolated       isolated
// v              v
// -------------------
// |    accumulateP    |
// -------------------
// |
// distributed
// all-to-one
// v
// ----------------
// |    combineP    | local parallelism = 1
// ----------------
private void addToDagTwoStage(Planner p, Context context) {
    String vertexName = name();
    determineLocalParallelism(LOCAL_PARALLELISM_USE_DEFAULT, context, p.isPreserveOrder());
    Vertex v1 = p.dag.newVertex(vertexName + FIRST_STAGE_VERTEX_NAME_SUFFIX, accumulateP(aggrOp)).localParallelism(determinedLocalParallelism());
    if (p.isPreserveOrder()) {
        p.addEdges(this, v1, Edge::isolated);
    } else {
        p.addEdges(this, v1);
    }
    determinedLocalParallelism(1);
    PlannerVertex pv2 = p.addVertex(this, vertexName, determinedLocalParallelism(), ProcessorMetaSupplier.forceTotalParallelismOne(ProcessorSupplier.of(combineP(aggrOp)), vertexName));
    p.dag.edge(between(v1, pv2.v).distributed().allToOne(vertexName));
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) PlannerVertex(com.hazelcast.jet.impl.pipeline.Planner.PlannerVertex) PlannerVertex(com.hazelcast.jet.impl.pipeline.Planner.PlannerVertex) Edge(com.hazelcast.jet.core.Edge)

Example 5 with Edge

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

the class MapTransform 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(), mapP(mapFn()));
    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