use of com.hazelcast.function.FunctionEx in project hazelcast by hazelcast.
the class ComputeStageImplBase method attachFilterUsingPartitionedService.
@Nonnull
@SuppressWarnings({ "unchecked", "rawtypes" })
<S, K, RET> RET attachFilterUsingPartitionedService(@Nonnull ServiceFactory<?, S> serviceFactory, @Nonnull FunctionEx<? super T, ? extends K> partitionKeyFn, @Nonnull BiPredicateEx<? super S, ? super T> filterFn) {
checkSerializable(filterFn, "filterFn");
checkSerializable(partitionKeyFn, "partitionKeyFn");
serviceFactory = moveAttachedFilesToPipeline(serviceFactory);
BiPredicateEx adaptedFilterFn = fnAdapter.adaptFilterUsingServiceFn(filterFn);
FunctionEx adaptedPartitionKeyFn = fnAdapter.adaptKeyFn(partitionKeyFn);
return (RET) attach(filterUsingServicePartitionedTransform(transform, serviceFactory, adaptedFilterFn, adaptedPartitionKeyFn), fnAdapter);
}
use of com.hazelcast.function.FunctionEx in project hazelcast by hazelcast.
the class ComputeStageImplBase method attachMapUsingPartitionedServiceAsyncBatched.
@Nonnull
@SuppressWarnings({ "unchecked", "rawtypes" })
<S, K, R, RET> RET attachMapUsingPartitionedServiceAsyncBatched(@Nonnull ServiceFactory<?, S> serviceFactory, int maxBatchSize, @Nonnull FunctionEx<? super T, ? extends K> partitionKeyFn, @Nonnull BiFunctionEx<? super S, ? super List<T>, ? extends CompletableFuture<List<R>>> mapAsyncFn) {
checkSerializable(mapAsyncFn, "mapAsyncFn");
checkSerializable(partitionKeyFn, "partitionKeyFn");
serviceFactory = moveAttachedFilesToPipeline(serviceFactory);
BiFunctionEx<? super S, ? super List<T>, ? extends CompletableFuture<List<Traverser<R>>>> flatMapAsyncFn = (s, items) -> mapAsyncFn.apply(s, items).thenApply(list -> toList(list, Traversers::singleton));
BiFunctionEx adaptedFlatMapFn = fnAdapter.adaptFlatMapUsingServiceAsyncBatchedFn(flatMapAsyncFn);
FunctionEx adaptedPartitionKeyFn = fnAdapter.adaptKeyFn(partitionKeyFn);
// Here we flatten the result from List<Traverser<R>> to Traverser<R>.
// The former is used in pipeline API, the latter in core API.
BiFunctionEx<? super S, ? super List<T>, ? extends CompletableFuture<Traverser<R>>> flattenedFn = (svc, items) -> {
// R might actually be JetEvent<R> -- we can't represent this with static types
CompletableFuture<List<Traverser<R>>> f = (CompletableFuture<List<Traverser<R>>>) adaptedFlatMapFn.apply(svc, items);
return f.thenApply(res -> traverseIterable(res).flatMap(Function.identity()));
};
PartitionedProcessorTransform processorTransform = flatMapUsingServiceAsyncBatchedPartitionedTransform(transform, "map", serviceFactory, MAX_CONCURRENT_ASYNC_BATCHES, maxBatchSize, flattenedFn, adaptedPartitionKeyFn);
return attach(processorTransform, fnAdapter);
}
use of com.hazelcast.function.FunctionEx 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.function.FunctionEx in project hazelcast by hazelcast.
the class GroupTransform method addToDagTwoStage.
// --------- ---------
// | source0 | ... | sourceN |
// --------- ---------
// | |
// local local
// partitioned partitioned
// v v
// --------------------
// | accumulateByKeyP |
// --------------------
// |
// distributed
// partitioned
// v
// ---------------
// | combineByKeyP |
// ---------------
private void addToDagTwoStage(Planner p) {
List<FunctionEx<?, ? extends K>> groupKeyFns = this.groupKeyFns;
Vertex v1 = p.dag.newVertex(name() + FIRST_STAGE_VERTEX_NAME_SUFFIX, accumulateByKeyP(groupKeyFns, aggrOp)).localParallelism(determinedLocalParallelism());
PlannerVertex pv2 = p.addVertex(this, name(), determinedLocalParallelism(), combineByKeyP(aggrOp, mapToOutputFn));
p.addEdges(this, v1, (e, ord) -> e.partitioned(groupKeyFns.get(ord), HASH_CODE));
p.dag.edge(between(v1, pv2.v).distributed().partitioned(entryKey()));
}
use of com.hazelcast.function.FunctionEx in project hazelcast by hazelcast.
the class SinkTransform method addToDag.
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void addToDag(Planner p, Context context) {
determineLocalParallelism(sink.metaSupplier().preferredLocalParallelism(), context, false);
PlannerVertex pv = p.addVertex(this, name(), determinedLocalParallelism(), adaptingMetaSupplier(sink.metaSupplier(), ordinalsToAdapt));
p.addEdges(this, pv.v, (e, ord) -> {
// all the items will be routed to the member with the partition key
if (sink.getType() == TOTAL_PARALLELISM_ONE) {
e.allToOne(sink.name()).distributed();
} else {
if (sink.getType().isPartitioned()) {
FunctionEx keyFn = sink.partitionKeyFunction();
if (arrayIndexOf(ord, ordinalsToAdapt) >= 0) {
keyFn = ADAPT_TO_JET_EVENT.adaptKeyFn(keyFn);
}
e.partitioned(keyFn, Partitioner.defaultPartitioner());
}
if (sink.getType().isDistributed()) {
e.distributed();
}
}
});
}
Aggregations