Search in sources :

Example 1 with ADAPT_TO_JET_EVENT

use of com.hazelcast.jet.impl.pipeline.ComputeStageImplBase.ADAPT_TO_JET_EVENT in project hazelcast-jet by hazelcast.

the class GrAggBuilder method buildStream.

@SuppressWarnings("unchecked")
public <A, R, OUT> StreamStage<OUT> buildStream(@Nonnull AggregateOperation<A, ? extends R> aggrOp, @Nonnull KeyedWindowResultFunction<? super K, ? super R, OUT> mapToOutputFn) {
    List<Transform> upstreamTransforms = upstreamStages.stream().map(s -> s.transform).collect(toList());
    JetEventFunctionAdapter fnAdapter = ADAPT_TO_JET_EVENT;
    // Avoided Stream API here due to static typing issues
    List<DistributedFunction<?, ? extends K>> adaptedKeyFns = new ArrayList<>();
    for (DistributedFunction keyFn : keyFns) {
        adaptedKeyFns.add(adaptKeyFn(keyFn));
    }
    Transform transform = new WindowGroupTransform<K, A, R, JetEvent<OUT>>(upstreamTransforms, wDef, adaptedKeyFns, adaptAggregateOperation(aggrOp), fnAdapter.adaptKeyedWindowResultFn(mapToOutputFn));
    pipelineImpl.connect(upstreamTransforms, transform);
    return new StreamStageImpl<>(transform, fnAdapter, pipelineImpl);
}
Also used : WindowGroupTransform(com.hazelcast.jet.impl.pipeline.transform.WindowGroupTransform) DistributedBiFunction(com.hazelcast.jet.function.DistributedBiFunction) ArrayList(java.util.ArrayList) BatchStage(com.hazelcast.jet.pipeline.BatchStage) Tag.tag(com.hazelcast.jet.datamodel.Tag.tag) KeyedWindowResultFunction(com.hazelcast.jet.function.KeyedWindowResultFunction) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) WindowGroupAggregateBuilder(com.hazelcast.jet.pipeline.WindowGroupAggregateBuilder) StageWithGroupingAndWindow(com.hazelcast.jet.pipeline.StageWithGroupingAndWindow) DistributedFunction(com.hazelcast.jet.function.DistributedFunction) GroupTransform(com.hazelcast.jet.impl.pipeline.transform.GroupTransform) Nonnull(javax.annotation.Nonnull) StreamStage(com.hazelcast.jet.pipeline.StreamStage) WindowDefinition(com.hazelcast.jet.pipeline.WindowDefinition) StageWithGrouping(com.hazelcast.jet.pipeline.StageWithGrouping) JetEventFunctionAdapter.adaptAggregateOperation(com.hazelcast.jet.impl.pipeline.JetEventFunctionAdapter.adaptAggregateOperation) Tag(com.hazelcast.jet.datamodel.Tag) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) ADAPT_TO_JET_EVENT(com.hazelcast.jet.impl.pipeline.ComputeStageImplBase.ADAPT_TO_JET_EVENT) List(java.util.List) ComputeStageImplBase.ensureJetEvents(com.hazelcast.jet.impl.pipeline.ComputeStageImplBase.ensureJetEvents) Collectors.toList(java.util.stream.Collectors.toList) JetEventFunctionAdapter.adaptKeyFn(com.hazelcast.jet.impl.pipeline.JetEventFunctionAdapter.adaptKeyFn) StreamStageWithGrouping(com.hazelcast.jet.pipeline.StreamStageWithGrouping) GroupAggregateBuilder(com.hazelcast.jet.pipeline.GroupAggregateBuilder) ArrayList(java.util.ArrayList) WindowGroupTransform(com.hazelcast.jet.impl.pipeline.transform.WindowGroupTransform) GroupTransform(com.hazelcast.jet.impl.pipeline.transform.GroupTransform) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) WindowGroupTransform(com.hazelcast.jet.impl.pipeline.transform.WindowGroupTransform) DistributedFunction(com.hazelcast.jet.function.DistributedFunction)

Example 2 with ADAPT_TO_JET_EVENT

use of com.hazelcast.jet.impl.pipeline.ComputeStageImplBase.ADAPT_TO_JET_EVENT 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 3 with ADAPT_TO_JET_EVENT

use of com.hazelcast.jet.impl.pipeline.ComputeStageImplBase.ADAPT_TO_JET_EVENT 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

ADAPT_TO_JET_EVENT (com.hazelcast.jet.impl.pipeline.ComputeStageImplBase.ADAPT_TO_JET_EVENT)3 Transform (com.hazelcast.jet.impl.pipeline.transform.Transform)3 BatchStage (com.hazelcast.jet.pipeline.BatchStage)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Collectors.toList (java.util.stream.Collectors.toList)3 Nonnull (javax.annotation.Nonnull)3 DAG (com.hazelcast.jet.core.DAG)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 BatchSource (com.hazelcast.jet.pipeline.BatchSource)2 GeneralStage (com.hazelcast.jet.pipeline.GeneralStage)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 StreamStage (com.hazelcast.jet.pipeline.StreamStage)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2