use of com.hazelcast.function.BiFunctionEx in project hazelcast by hazelcast.
the class ComputeStageImplBase method attachMapUsingPartitionedServiceAsync.
@Nonnull
@SuppressWarnings({ "unchecked", "rawtypes" })
<S, K, R, RET> RET attachMapUsingPartitionedServiceAsync(@Nonnull ServiceFactory<?, S> serviceFactory, int maxConcurrentOps, boolean preserveOrder, @Nonnull FunctionEx<? super T, ? extends K> partitionKeyFn, @Nonnull BiFunctionEx<? super S, ? super T, ? extends CompletableFuture<R>> mapAsyncFn) {
checkSerializable(mapAsyncFn, "mapAsyncFn");
checkSerializable(partitionKeyFn, "partitionKeyFn");
serviceFactory = moveAttachedFilesToPipeline(serviceFactory);
BiFunctionEx<? super S, ? super T, ? extends CompletableFuture<Traverser<R>>> flatMapAsyncFn = (s, t) -> mapAsyncFn.apply(s, t).thenApply(Traversers::singleton);
BiFunctionEx adaptedFlatMapFn = fnAdapter.adaptFlatMapUsingServiceAsyncFn(flatMapAsyncFn);
FunctionEx adaptedPartitionKeyFn = fnAdapter.adaptKeyFn(partitionKeyFn);
PartitionedProcessorTransform processorTransform = flatMapUsingServiceAsyncPartitionedTransform(transform, "map", serviceFactory, maxConcurrentOps, preserveOrder, adaptedFlatMapFn, adaptedPartitionKeyFn);
return attach(processorTransform, fnAdapter);
}
use of com.hazelcast.function.BiFunctionEx in project hazelcast by hazelcast.
the class ComputeStageImplBase method attachFlatMapUsingPartitionedService.
@Nonnull
@SuppressWarnings({ "unchecked", "rawtypes" })
<S, K, R, RET> RET attachFlatMapUsingPartitionedService(@Nonnull ServiceFactory<?, S> serviceFactory, @Nonnull FunctionEx<? super T, ? extends K> partitionKeyFn, @Nonnull BiFunctionEx<? super S, ? super T, ? extends Traverser<R>> flatMapFn) {
checkSerializable(flatMapFn, "flatMapFn");
checkSerializable(partitionKeyFn, "partitionKeyFn");
serviceFactory = moveAttachedFilesToPipeline(serviceFactory);
BiFunctionEx adaptedFlatMapFn = fnAdapter.adaptFlatMapUsingServiceFn(flatMapFn);
FunctionEx adaptedPartitionKeyFn = fnAdapter.adaptKeyFn(partitionKeyFn);
return (RET) attach(flatMapUsingServicePartitionedTransform(transform, serviceFactory, adaptedFlatMapFn, adaptedPartitionKeyFn), fnAdapter);
}
use of com.hazelcast.function.BiFunctionEx in project hazelcast by hazelcast.
the class HashJoinTransform method addToDag.
// --------- ---------- ----------
// | primary | | joined-1 | | joined-2 |
// --------- ---------- ----------
// | | |
// | distributed distributed
// | broadcast broadcast
// | v v
// | ------------- -------------
// | | collector-1 | | collector-2 |
// | | localPara=1 | | localPara=1 |
// | ------------- -------------
// | | |
// | local local
// local broadcast broadcast
// unicast prioritized prioritized
// ordinal 0 ordinal 1 ordinal 2
// \ | |
// ----------------\ | /----------------/
// v v v
// --------
// | joiner |
// --------
@Override
@SuppressWarnings("unchecked")
public void addToDag(Planner p, Context context) {
determineLocalParallelism(LOCAL_PARALLELISM_USE_DEFAULT, context, p.isPreserveOrder());
PlannerVertex primary = p.xform2vertex.get(this.upstream().get(0));
List keyFns = toList(this.clauses, JoinClause::leftKeyFn);
List<Tag> tags = this.tags;
BiFunctionEx mapToOutputBiFn = this.mapToOutputBiFn;
TriFunction mapToOutputTriFn = this.mapToOutputTriFn;
// must be extracted to variable, probably because of serialization bug
BiFunctionEx<List<Tag>, Object[], ItemsByTag> tupleToItems = tupleToItemsByTag(whereNullsNotAllowed);
Vertex joiner = p.addVertex(this, name() + "-joiner", determinedLocalParallelism(), () -> new HashJoinP<>(keyFns, tags, mapToOutputBiFn, mapToOutputTriFn, tupleToItems)).v;
Edge edgeToJoiner = from(primary.v, primary.nextAvailableOrdinal()).to(joiner, 0);
if (p.isPreserveOrder()) {
edgeToJoiner.isolated();
} else {
applyRebalancing(edgeToJoiner, this);
}
p.dag.edge(edgeToJoiner);
String collectorName = name() + "-collector";
int collectorOrdinal = 1;
for (Transform fromTransform : tailList(this.upstream())) {
PlannerVertex fromPv = p.xform2vertex.get(fromTransform);
JoinClause<?, ?, ?, ?> clause = this.clauses.get(collectorOrdinal - 1);
FunctionEx<Object, Object> getKeyFn = (FunctionEx<Object, Object>) clause.rightKeyFn();
FunctionEx<Object, Object> projectFn = (FunctionEx<Object, Object>) clause.rightProjectFn();
Vertex collector = p.dag.newVertex(collectorName + collectorOrdinal, () -> new HashJoinCollectP(getKeyFn, projectFn));
collector.localParallelism(1);
p.dag.edge(from(fromPv.v, fromPv.nextAvailableOrdinal()).to(collector, 0).distributed().broadcast());
p.dag.edge(from(collector, 0).to(joiner, collectorOrdinal).broadcast().priority(-1));
collectorOrdinal++;
}
}
use of com.hazelcast.function.BiFunctionEx in project hazelcast by hazelcast.
the class CreateDagVisitor method onSlidingWindow.
public Vertex onSlidingWindow(SlidingWindowPhysicalRel rel) {
int orderingFieldIndex = rel.orderingFieldIndex();
FunctionEx<ExpressionEvalContext, SlidingWindowPolicy> windowPolicySupplier = rel.windowPolicyProvider();
// this vertex is used only if there's no aggregation by a window bound
Vertex vertex = dag.newUniqueVertex("Sliding-Window", flatMapUsingServiceP(ServiceFactories.nonSharedService(ctx -> {
ExpressionEvalContext evalContext = ExpressionEvalContext.from(ctx);
SlidingWindowPolicy windowPolicy = windowPolicySupplier.apply(evalContext);
return row -> WindowUtils.addWindowBounds(row, orderingFieldIndex, windowPolicy);
}), (BiFunctionEx<Function<JetSqlRow, Traverser<JetSqlRow>>, JetSqlRow, Traverser<JetSqlRow>>) Function::apply));
connectInput(rel.getInput(), vertex, null);
return vertex;
}
Aggregations