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);
}
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);
}
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;
}
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();
}
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;
}
Aggregations