Search in sources :

Example 41 with Vertex

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

the class CreateDagVisitor method onHashJoin.

public Vertex onHashJoin(JoinHashPhysicalRel rel) {
    JetJoinInfo joinInfo = rel.joinInfo(parameterMetadata);
    Vertex joinVertex = dag.newUniqueVertex("Hash Join", SqlHashJoinP.supplier(joinInfo, rel.getRight().getRowType().getFieldCount()));
    connectJoinInput(joinInfo, rel.getLeft(), rel.getRight(), joinVertex);
    return joinVertex;
}
Also used : JetJoinInfo(com.hazelcast.jet.sql.impl.JetJoinInfo) Vertex(com.hazelcast.jet.core.Vertex)

Example 42 with Vertex

use of com.hazelcast.jet.core.Vertex 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 43 with Vertex

use of com.hazelcast.jet.core.Vertex 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 44 with Vertex

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

the class CreateDagVisitor method onFilter.

public Vertex onFilter(FilterPhysicalRel rel) {
    Expression<Boolean> filter = rel.filter(parameterMetadata);
    Vertex vertex = dag.newUniqueVertex("Filter", filterUsingServiceP(ServiceFactories.nonSharedService(ctx -> ExpressionUtil.filterFn(filter, ExpressionEvalContext.from(ctx))), (Predicate<JetSqlRow> filterFn, JetSqlRow row) -> filterFn.test(row)));
    connectInputPreserveCollation(rel, vertex);
    return vertex;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow)

Example 45 with Vertex

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

the class CreateDagVisitor method onAccumulateByKey.

public Vertex onAccumulateByKey(AggregateAccumulateByKeyPhysicalRel rel) {
    FunctionEx<JetSqlRow, ?> groupKeyFn = rel.groupKeyFn();
    AggregateOperation<?, JetSqlRow> aggregateOperation = rel.aggrOp();
    Vertex vertex = dag.newUniqueVertex("AccumulateByKey", Processors.accumulateByKeyP(singletonList(groupKeyFn), aggregateOperation));
    connectInput(rel.getInput(), vertex, edge -> edge.partitioned(groupKeyFn));
    return vertex;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow)

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