/** * Returns a new stream where the values are grouped by the keys. * * @return the new stream */ public PairStream<K, Iterable<V>> groupByKey() { return partitionByKey().aggregatePartition(new MergeValues<>()); }
/** * Returns a new stream where the values are grouped by keys and the given window. The values that arrive within a window having the * same key will be merged together and returned as an Iterable of values mapped to the key. * * @param window the window configuration * @return the new stream */ public PairStream<K, Iterable<V>> groupByKeyAndWindow(Window<?, ?> window) { return partitionByKey().window(window).aggregatePartition(new MergeValues<>()); }
private <A, R> PairStream<K, R> combineByKey(CombinerAggregator<? super V, A, ? extends R> aggregator) { if (shouldPartitionByKey()) { if (node instanceof ProcessorNode) { if (node.isWindowed()) { return combinePartition(aggregator).partitionBy(KEY).merge(aggregator); } } else if (node instanceof WindowNode) { Set<Node> parents = node.getParents(); Optional<Node> nonWindowed = parents.stream().filter(p -> !p.isWindowed()).findAny(); if (!nonWindowed.isPresent()) { parents.forEach(p -> { Node localAggregateNode = makeProcessorNode( new AggregateByKeyProcessor<>(aggregator, true), KEY_VALUE, true); streamBuilder.insert(p, localAggregateNode); }); return ((PairStream<K, A>) partitionBy(KEY)).merge(aggregator); } } return partitionBy(KEY).aggregatePartition(aggregator); } else { return aggregatePartition(aggregator); } }