Search in sources :

Example 6 with Transform

use of com.hazelcast.jet.impl.pipeline.transform.Transform in project hazelcast by hazelcast.

the class GrAggBuilder method buildStream.

public <A, R> StreamStage<KeyedWindowResult<K, R>> buildStream(@Nonnull AggregateOperation<A, ? extends R> aggrOp) {
    List<Transform> upstreamTransforms = toList(upstreamStages, s -> s.transform);
    FunctionAdapter fnAdapter = ADAPT_TO_JET_EVENT;
    // Casts in this expression are a workaround for JDK 8 compiler bug:
    @SuppressWarnings("unchecked") List<FunctionEx<?, ? extends K>> adaptedKeyFns = toList(keyFns, fn -> fnAdapter.adaptKeyFn((FunctionEx) fn));
    AbstractTransform transform = new WindowGroupTransform<K, R>(upstreamTransforms, wDef, adaptedKeyFns, fnAdapter.adaptAggregateOperation(aggrOp));
    pipelineImpl.connect(upstreamStages, transform);
    return new StreamStageImpl<>(transform, fnAdapter, pipelineImpl);
}
Also used : AbstractTransform(com.hazelcast.jet.impl.pipeline.transform.AbstractTransform) BiFunctionEx(com.hazelcast.function.BiFunctionEx) FunctionEx(com.hazelcast.function.FunctionEx) WindowGroupTransform(com.hazelcast.jet.impl.pipeline.transform.WindowGroupTransform) GroupTransform(com.hazelcast.jet.impl.pipeline.transform.GroupTransform) AbstractTransform(com.hazelcast.jet.impl.pipeline.transform.AbstractTransform) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) WindowGroupTransform(com.hazelcast.jet.impl.pipeline.transform.WindowGroupTransform)

Example 7 with Transform

use of com.hazelcast.jet.impl.pipeline.transform.Transform in project hazelcast by hazelcast.

the class GrAggBuilder method buildBatch.

public <A, R, OUT> BatchStage<OUT> buildBatch(@Nonnull AggregateOperation<A, ? extends R> aggrOp, @Nonnull BiFunctionEx<? super K, ? super R, OUT> mapToOutputFn) {
    checkSerializable(mapToOutputFn, "mapToOutputFn");
    List<Transform> upstreamTransforms = toList(upstreamStages, s -> s.transform);
    AbstractTransform transform = new GroupTransform<>(upstreamTransforms, keyFns, aggrOp, mapToOutputFn);
    pipelineImpl.connect(upstreamStages, transform);
    return new BatchStageImpl<>(transform, pipelineImpl);
}
Also used : AbstractTransform(com.hazelcast.jet.impl.pipeline.transform.AbstractTransform) WindowGroupTransform(com.hazelcast.jet.impl.pipeline.transform.WindowGroupTransform) GroupTransform(com.hazelcast.jet.impl.pipeline.transform.GroupTransform) WindowGroupTransform(com.hazelcast.jet.impl.pipeline.transform.WindowGroupTransform) GroupTransform(com.hazelcast.jet.impl.pipeline.transform.GroupTransform) AbstractTransform(com.hazelcast.jet.impl.pipeline.transform.AbstractTransform) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform)

Example 8 with Transform

use of com.hazelcast.jet.impl.pipeline.transform.Transform in project hazelcast by hazelcast.

the class Planner method findFusableChain.

private static List<Transform> findFusableChain(@Nonnull Transform transform, @Nonnull Map<Transform, List<Transform>> adjacencyMap) {
    ArrayList<Transform> chain = new ArrayList<>();
    for (; ; ) {
        if (!(transform instanceof MapTransform || transform instanceof FlatMapTransform)) {
            break;
        }
        chain.add(transform);
        List<Transform> downstream = adjacencyMap.get(transform);
        if (downstream.size() != 1) {
            break;
        }
        Transform nextTransform = downstream.get(0);
        if (nextTransform.localParallelism() != transform.localParallelism() || nextTransform.shouldRebalanceInput(0)) {
            break;
        }
        transform = nextTransform;
    }
    return chain.size() > 1 ? chain : null;
}
Also used : ArrayList(java.util.ArrayList) MapTransform(com.hazelcast.jet.impl.pipeline.transform.MapTransform) FlatMapTransform(com.hazelcast.jet.impl.pipeline.transform.FlatMapTransform) 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) FlatMapTransform(com.hazelcast.jet.impl.pipeline.transform.FlatMapTransform)

Example 9 with Transform

use of com.hazelcast.jet.impl.pipeline.transform.Transform in project hazelcast by hazelcast.

the class PipelineImpl method toDotString.

@Nonnull
@Override
public String toDotString() {
    makeNamesUnique();
    Map<Transform, List<Transform>> adjMap = this.adjacencyMap();
    Map<Transform, String> transformNames = new HashMap<>();
    final StringBuilder builder = new StringBuilder(256);
    builder.append("digraph Pipeline {\n");
    for (Entry<Transform, List<Transform>> entry : adjMap.entrySet()) {
        Transform src = entry.getKey();
        String srcName = transformNames.computeIfAbsent(src, Transform::name);
        for (Transform dest : entry.getValue()) {
            String destName = transformNames.computeIfAbsent(dest, Transform::name);
            builder.append("\t").append("\"").append(escapeGraphviz(srcName)).append("\"").append(" -> ").append("\"").append(escapeGraphviz(destName)).append("\"").append(";\n");
        }
    }
    builder.append("}");
    return builder.toString();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) SinkTransform(com.hazelcast.jet.impl.pipeline.transform.SinkTransform) BatchSourceTransform(com.hazelcast.jet.impl.pipeline.transform.BatchSourceTransform) AbstractTransform(com.hazelcast.jet.impl.pipeline.transform.AbstractTransform) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) StreamSourceTransform(com.hazelcast.jet.impl.pipeline.transform.StreamSourceTransform) Nonnull(javax.annotation.Nonnull)

Example 10 with Transform

use of com.hazelcast.jet.impl.pipeline.transform.Transform in project hazelcast by hazelcast.

the class PipelineImpl method writeTo.

@Nonnull
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public <T> SinkStage writeTo(@Nonnull Sink<? super T> sink, @Nonnull GeneralStage<? extends T> stage0, @Nonnull GeneralStage<? extends T> stage1, @Nonnull GeneralStage<? extends T>... moreStages) {
    List<GeneralStage> stages = new ArrayList<>(asList(moreStages));
    stages.add(0, stage0);
    stages.add(1, stage1);
    List<Transform> upstream = stages.stream().map(s -> (AbstractStage) s).map(s -> s.transform).collect(toList());
    int[] ordinalsToAdapt = IntStream.range(0, stages.size()).filter(i -> ((ComputeStageImplBase) stages.get(i)).fnAdapter == ADAPT_TO_JET_EVENT).toArray();
    SinkImpl sinkImpl = (SinkImpl) sink;
    SinkTransform sinkTransform = new SinkTransform(sinkImpl, upstream, ordinalsToAdapt);
    SinkStageImpl sinkStage = new SinkStageImpl(sinkTransform, this);
    sinkImpl.onAssignToStage();
    connectGeneralStages(stages, sinkTransform);
    return sinkStage;
}
Also used : IntStream(java.util.stream.IntStream) Util.escapeGraphviz(com.hazelcast.jet.impl.util.Util.escapeGraphviz) HashMap(java.util.HashMap) StreamSource(com.hazelcast.jet.pipeline.StreamSource) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) BatchStage(com.hazelcast.jet.pipeline.BatchStage) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) SinkTransform(com.hazelcast.jet.impl.pipeline.transform.SinkTransform) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) DAG(com.hazelcast.jet.core.DAG) Nonnull(javax.annotation.Nonnull) GeneralStage(com.hazelcast.jet.pipeline.GeneralStage) BatchSource(com.hazelcast.jet.pipeline.BatchSource) BatchSourceTransform(com.hazelcast.jet.impl.pipeline.transform.BatchSourceTransform) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Set(java.util.Set) AbstractTransform(com.hazelcast.jet.impl.pipeline.transform.AbstractTransform) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) File(java.io.File) ADAPT_TO_JET_EVENT(com.hazelcast.jet.impl.pipeline.ComputeStageImplBase.ADAPT_TO_JET_EVENT) SinkStage(com.hazelcast.jet.pipeline.SinkStage) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Entry(java.util.Map.Entry) Util.addOrIncrementIndexInName(com.hazelcast.jet.impl.util.Util.addOrIncrementIndexInName) StreamSourceTransform(com.hazelcast.jet.impl.pipeline.transform.StreamSourceTransform) StreamSourceStage(com.hazelcast.jet.pipeline.StreamSourceStage) Collections(java.util.Collections) Sink(com.hazelcast.jet.pipeline.Sink) GeneralStage(com.hazelcast.jet.pipeline.GeneralStage) SinkTransform(com.hazelcast.jet.impl.pipeline.transform.SinkTransform) ArrayList(java.util.ArrayList) SinkTransform(com.hazelcast.jet.impl.pipeline.transform.SinkTransform) BatchSourceTransform(com.hazelcast.jet.impl.pipeline.transform.BatchSourceTransform) AbstractTransform(com.hazelcast.jet.impl.pipeline.transform.AbstractTransform) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) StreamSourceTransform(com.hazelcast.jet.impl.pipeline.transform.StreamSourceTransform) Nonnull(javax.annotation.Nonnull)

Aggregations

Transform (com.hazelcast.jet.impl.pipeline.transform.Transform)20 Nonnull (javax.annotation.Nonnull)15 SinkTransform (com.hazelcast.jet.impl.pipeline.transform.SinkTransform)12 List (java.util.List)12 StreamSourceTransform (com.hazelcast.jet.impl.pipeline.transform.StreamSourceTransform)9 TimestampTransform (com.hazelcast.jet.impl.pipeline.transform.TimestampTransform)9 ArrayList (java.util.ArrayList)9 Collectors.toList (java.util.stream.Collectors.toList)9 AbstractTransform (com.hazelcast.jet.impl.pipeline.transform.AbstractTransform)8 GeneralStage (com.hazelcast.jet.pipeline.GeneralStage)8 FlatMapTransform (com.hazelcast.jet.impl.pipeline.transform.FlatMapTransform)7 MapTransform (com.hazelcast.jet.impl.pipeline.transform.MapTransform)7 BatchStage (com.hazelcast.jet.pipeline.BatchStage)7 FunctionEx (com.hazelcast.function.FunctionEx)6 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)6 StreamStage (com.hazelcast.jet.pipeline.StreamStage)6 SupplierEx (com.hazelcast.function.SupplierEx)5 Traverser (com.hazelcast.jet.Traverser)5 Traversers (com.hazelcast.jet.Traversers)5 DAG (com.hazelcast.jet.core.DAG)5