private PairStream<K, V> toPairStream(Stream<Pair<K, V>> stream) { return new PairStream<>(stream.streamBuilder, stream.node); }
private <R> StreamState<K, R> updateStateByKeyPartition(StateUpdater<? super V, ? extends R> stateUpdater) { return new StreamState<>( new PairStream<>(streamBuilder, addProcessorNode(new UpdateStateByKeyProcessor<>(stateUpdater), KEY_VALUE, true))); }
/** * Returns a new stream by applying a {@link Function} to the value of each key-value pairs in this stream. * * @param function the mapping function * @param <R> the result type * @return the new stream */ public <R> PairStream<K, R> mapValues(Function<? super V, ? extends R> function) { return new PairStream<>(streamBuilder, addProcessorNode(new MapValuesProcessor<>(function), KEY_VALUE, true)); }
/** * Return a new stream by applying a {@link FlatMapFunction} function to the value of each key-value pairs in this stream. * * @param function the flatmap function * @param <R> the result type * @return the new stream */ public <R> PairStream<K, R> flatMapValues(FlatMapFunction<? super V, ? extends R> function) { return new PairStream<>(streamBuilder, addProcessorNode(new FlatMapValuesProcessor<>(function), KEY_VALUE, true)); }
private PairStream<K, V> reducePartition(Reducer<V> reducer) { return new PairStream<>(streamBuilder, addProcessorNode(new ReduceByKeyProcessor<>(reducer), KEY_VALUE, true)); }
private <A> PairStream<K, A> combinePartition(CombinerAggregator<? super V, A, ?> aggregator) { return new PairStream<>(streamBuilder, addProcessorNode(new AggregateByKeyProcessor<>(aggregator, true), KEY_VALUE, true)); }
private <R> PairStream<K, R> merge(CombinerAggregator<?, V, ? extends R> aggregator) { return new PairStream<>(streamBuilder, addProcessorNode(new MergeAggregateByKeyProcessor<>(aggregator), KEY_VALUE, true)); }
/** * Returns a stream of key-value pairs by applying a {@link PairFunction} on each value of this stream. * * @param function the mapping function to be applied to each value in this stream * @param <K> the key type * @param <V> the value type * @return the new stream of key-value pairs */ public <K, V> PairStream<K, V> mapToPair(PairFunction<? super T, ? extends K, ? extends V> function) { return new PairStream<>(streamBuilder, addProcessorNode(new MapProcessor<>(function), KEY_VALUE)); }
private <A, R> PairStream<K, R> aggregatePartition(CombinerAggregator<? super V, A, ? extends R> aggregator) { return new PairStream<>(streamBuilder, addProcessorNode(new AggregateByKeyProcessor<>(aggregator), KEY_VALUE, true)); }
/** * Returns a stream consisting of the results of replacing each value of this stream with the key-value pairs produced by applying the * provided mapping function to each value. * * @param function the mapping function to be applied to each value in this stream which produces new key-value pairs. * @param <K> the key type * @param <V> the value type * @return the new stream of key-value pairs * * @see #flatMap(FlatMapFunction) * @see #mapToPair(PairFunction) */ public <K, V> PairStream<K, V> flatMapToPair(PairFlatMapFunction<? super T, ? extends K, ? extends V> function) { return new PairStream<>(streamBuilder, addProcessorNode(new FlatMapProcessor<>(function), KEY_VALUE)); }
/** * Queries the given stream state with the values in this stream as the keys. * * @param streamState the stream state * @param <V> the value type * @return the result stream */ public <V> PairStream<T, V> stateQuery(StreamState<T, V> streamState) { // need field grouping for state query so that the query is routed to the correct task Node newNode = partitionBy(VALUE, node.getParallelism()).addProcessorNode(new StateQueryProcessor<>(streamState), KEY_VALUE); return new PairStream<>(streamBuilder, newNode); }
private <R, V1> PairStream<K, R> coGroupByKeyPartition(PairStream<K, V1> otherStream) { String firstStream = stream; String secondStream = otherStream.stream; Node coGroupNode = addProcessorNode( new CoGroupByKeyProcessor<>(firstStream, secondStream), KEY_VALUE, true); addNode(otherStream.getNode(), coGroupNode, coGroupNode.getParallelism()); return new PairStream<>(streamBuilder, coGroupNode); }
private <R, V1> PairStream<K, R> joinPartition(PairStream<K, V1> otherStream, ValueJoiner<? super V, ? super V1, ? extends R> valueJoiner, JoinProcessor.JoinType leftType, JoinProcessor.JoinType rightType) { String leftStream = stream; String rightStream = otherStream.stream; Node joinNode = addProcessorNode( new JoinProcessor<>(leftStream, rightStream, valueJoiner, leftType, rightType), KEY_VALUE, true); addNode(otherStream.getNode(), joinNode, joinNode.getParallelism()); return new PairStream<>(streamBuilder, joinNode); }