Search in sources :

Example 1 with GeneralStage

use of com.hazelcast.jet.pipeline.GeneralStage in project hazelcast-jet by hazelcast.

the class PipelineImpl method drainTo.

@Override
public <T> SinkStage drainTo(@Nonnull Sink<T> sink, GeneralStage<?>... stagesToDrain) {
    if (stagesToDrain == null || stagesToDrain.length == 0) {
        throw new IllegalArgumentException("No stages supplied to Pipeline.drainTo()");
    }
    List<Transform> upstream = Arrays.stream(stagesToDrain).map(s -> (AbstractStage) s).map(s -> s.transform).collect(toList());
    int[] ordinalsToAdapt = IntStream.range(0, stagesToDrain.length).filter(i -> ((ComputeStageImplBase) stagesToDrain[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();
    connect(upstream, sinkTransform);
    return sinkStage;
}
Also used : GeneralStage(com.hazelcast.jet.pipeline.GeneralStage) IntStream(java.util.stream.IntStream) DONT_ADAPT(com.hazelcast.jet.impl.pipeline.ComputeStageImplBase.DONT_ADAPT) StreamStage(com.hazelcast.jet.pipeline.StreamStage) Arrays(java.util.Arrays) BatchSource(com.hazelcast.jet.pipeline.BatchSource) BatchSourceTransform(com.hazelcast.jet.impl.pipeline.transform.BatchSourceTransform) Pipeline(com.hazelcast.jet.pipeline.Pipeline) HashMap(java.util.HashMap) StreamSource(com.hazelcast.jet.pipeline.StreamSource) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) ADAPT_TO_JET_EVENT(com.hazelcast.jet.impl.pipeline.ComputeStageImplBase.ADAPT_TO_JET_EVENT) ArrayList(java.util.ArrayList) BatchStage(com.hazelcast.jet.pipeline.BatchStage) SinkTransform(com.hazelcast.jet.impl.pipeline.transform.SinkTransform) SinkStage(com.hazelcast.jet.pipeline.SinkStage) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Map(java.util.Map) StreamSourceTransform(com.hazelcast.jet.impl.pipeline.transform.StreamSourceTransform) DAG(com.hazelcast.jet.core.DAG) Nonnull(javax.annotation.Nonnull) Sink(com.hazelcast.jet.pipeline.Sink) SinkTransform(com.hazelcast.jet.impl.pipeline.transform.SinkTransform) BatchSourceTransform(com.hazelcast.jet.impl.pipeline.transform.BatchSourceTransform) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) SinkTransform(com.hazelcast.jet.impl.pipeline.transform.SinkTransform) StreamSourceTransform(com.hazelcast.jet.impl.pipeline.transform.StreamSourceTransform)

Example 2 with GeneralStage

use of com.hazelcast.jet.pipeline.GeneralStage 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)

Example 3 with GeneralStage

use of com.hazelcast.jet.pipeline.GeneralStage in project hazelcast by hazelcast.

the class StageWithKeyAndWindowImpl method aggregate2.

@Nonnull
@Override
@SuppressWarnings("rawtypes")
public <T1, R> StreamStage<KeyedWindowResult<K, R>> aggregate2(@Nonnull StreamStageWithKey<T1, ? extends K> stage1, @Nonnull AggregateOperation2<? super T, ? super T1, ?, ? extends R> aggrOp) {
    ensureJetEvents(computeStage, "This pipeline stage");
    ComputeStageImplBase computeStage1 = ((StageWithGroupingBase) stage1).computeStage;
    ensureJetEvents(computeStage1, "stage1");
    Transform upstream1 = computeStage1.transform;
    FunctionAdapter fnAdapter = ADAPT_TO_JET_EVENT;
    return this.computeStage.attach(new WindowGroupTransform<K, R>(asList(this.computeStage.transform, upstream1), wDef, asList(fnAdapter.adaptKeyFn(keyFn()), fnAdapter.adaptKeyFn(stage1.keyFn())), adaptAggregateOperation2(aggrOp)), singletonList((GeneralStage<?>) computeStage1), fnAdapter);
}
Also used : GeneralStage(com.hazelcast.jet.pipeline.GeneralStage) WindowGroupTransform(com.hazelcast.jet.impl.pipeline.transform.WindowGroupTransform) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) Nonnull(javax.annotation.Nonnull)

Example 4 with GeneralStage

use of com.hazelcast.jet.pipeline.GeneralStage in project hazelcast by hazelcast.

the class StageWithKeyAndWindowImpl method aggregate3.

@Nonnull
@Override
@SuppressWarnings("rawtypes")
public <T1, T2, R> StreamStage<KeyedWindowResult<K, R>> aggregate3(@Nonnull StreamStageWithKey<T1, ? extends K> stage1, @Nonnull StreamStageWithKey<T2, ? extends K> stage2, @Nonnull AggregateOperation3<? super T, ? super T1, ? super T2, ?, ? extends R> aggrOp) {
    ComputeStageImplBase computeStage1 = ((StageWithGroupingBase) stage1).computeStage;
    ComputeStageImplBase computeStage2 = ((StageWithGroupingBase) stage2).computeStage;
    ensureJetEvents(computeStage, "This pipeline stage");
    ensureJetEvents(computeStage1, "stage1");
    ensureJetEvents(computeStage2, "stage2");
    Transform transform1 = ((StageWithGroupingBase) stage1).computeStage.transform;
    Transform transform2 = ((StageWithGroupingBase) stage2).computeStage.transform;
    FunctionAdapter fnAdapter = ADAPT_TO_JET_EVENT;
    return computeStage.attach(new WindowGroupTransform<K, R>(asList(computeStage.transform, transform1, transform2), wDef, asList(fnAdapter.adaptKeyFn(keyFn()), fnAdapter.adaptKeyFn(stage1.keyFn()), fnAdapter.adaptKeyFn(stage2.keyFn())), adaptAggregateOperation3(aggrOp)), asList((GeneralStage<?>) computeStage1, (GeneralStage<?>) computeStage2), fnAdapter);
}
Also used : GeneralStage(com.hazelcast.jet.pipeline.GeneralStage) WindowGroupTransform(com.hazelcast.jet.impl.pipeline.transform.WindowGroupTransform) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) Nonnull(javax.annotation.Nonnull)

Example 5 with GeneralStage

use of com.hazelcast.jet.pipeline.GeneralStage in project hazelcast-jet by hazelcast.

the class AggBuilder method build.

@Nonnull
@SuppressWarnings("unchecked")
public <A, R, OUT, OUT_STAGE extends GeneralStage<OUT>> OUT_STAGE build(@Nonnull AggregateOperation<A, R> aggrOp, @Nonnull CreateOutStageFn<OUT, OUT_STAGE> createOutStageFn, @Nullable WindowResultFunction<? super R, ? extends OUT> mapToOutputFn) {
    AggregateOperation adaptedAggrOp = wDef != null ? adaptAggregateOperation(aggrOp) : aggrOp;
    List<Transform> upstreamTransforms = upstreamStages.stream().map(s -> ((AbstractStage) s).transform).collect(toList());
    final Transform transform;
    if (wDef != null) {
        requireNonNull(mapToOutputFn, "wDef != null but mapToOutputFn == null");
        transform = new WindowAggregateTransform<>(upstreamTransforms, wDef, adaptedAggrOp, mapToOutputFn);
    } else {
        transform = new AggregateTransform<>(upstreamTransforms, adaptedAggrOp);
    }
    OUT_STAGE attached = createOutStageFn.get(transform, DONT_ADAPT, pipelineImpl);
    pipelineImpl.connect(upstreamTransforms, transform);
    return attached;
}
Also used : GeneralStage(com.hazelcast.jet.pipeline.GeneralStage) DONT_ADAPT(com.hazelcast.jet.impl.pipeline.ComputeStageImplBase.DONT_ADAPT) WindowDefinition(com.hazelcast.jet.pipeline.WindowDefinition) JetEventFunctionAdapter.adaptAggregateOperation(com.hazelcast.jet.impl.pipeline.JetEventFunctionAdapter.adaptAggregateOperation) Tag(com.hazelcast.jet.datamodel.Tag) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) ArrayList(java.util.ArrayList) Tag.tag(com.hazelcast.jet.datamodel.Tag.tag) List(java.util.List) ComputeStageImplBase.ensureJetEvents(com.hazelcast.jet.impl.pipeline.ComputeStageImplBase.ensureJetEvents) Collectors.toList(java.util.stream.Collectors.toList) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) Objects.requireNonNull(java.util.Objects.requireNonNull) WindowResultFunction(com.hazelcast.jet.function.WindowResultFunction) Nonnull(javax.annotation.Nonnull) AggregateTransform(com.hazelcast.jet.impl.pipeline.transform.AggregateTransform) WindowAggregateTransform(com.hazelcast.jet.impl.pipeline.transform.WindowAggregateTransform) Nullable(javax.annotation.Nullable) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) AggregateTransform(com.hazelcast.jet.impl.pipeline.transform.AggregateTransform) WindowAggregateTransform(com.hazelcast.jet.impl.pipeline.transform.WindowAggregateTransform) JetEventFunctionAdapter.adaptAggregateOperation(com.hazelcast.jet.impl.pipeline.JetEventFunctionAdapter.adaptAggregateOperation) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) Nonnull(javax.annotation.Nonnull)

Aggregations

Transform (com.hazelcast.jet.impl.pipeline.transform.Transform)5 GeneralStage (com.hazelcast.jet.pipeline.GeneralStage)5 Nonnull (javax.annotation.Nonnull)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Collectors.toList (java.util.stream.Collectors.toList)3 DAG (com.hazelcast.jet.core.DAG)2 ADAPT_TO_JET_EVENT (com.hazelcast.jet.impl.pipeline.ComputeStageImplBase.ADAPT_TO_JET_EVENT)2 DONT_ADAPT (com.hazelcast.jet.impl.pipeline.ComputeStageImplBase.DONT_ADAPT)2 BatchSourceTransform (com.hazelcast.jet.impl.pipeline.transform.BatchSourceTransform)2 SinkTransform (com.hazelcast.jet.impl.pipeline.transform.SinkTransform)2 StreamSourceTransform (com.hazelcast.jet.impl.pipeline.transform.StreamSourceTransform)2 WindowGroupTransform (com.hazelcast.jet.impl.pipeline.transform.WindowGroupTransform)2 BatchSource (com.hazelcast.jet.pipeline.BatchSource)2 BatchStage (com.hazelcast.jet.pipeline.BatchStage)2 Pipeline (com.hazelcast.jet.pipeline.Pipeline)2 Sink (com.hazelcast.jet.pipeline.Sink)2 SinkStage (com.hazelcast.jet.pipeline.SinkStage)2 StreamSource (com.hazelcast.jet.pipeline.StreamSource)2 HashMap (java.util.HashMap)2