/** * Attaches a stage that passes through just the items that are distinct * within their window (no two items emitted for a window are equal). There * is no guarantee among the items with the same key which one it will pass * through. To create the item to emit, the stage calls the supplied {@code * mapToOutputFn}. * * @param mapToOutputFn function that returns the items to emit * @return the newly attached stage */ @Nonnull default <R> StreamStage<R> distinct(@Nonnull WindowResultFunction<? super T, ? extends R> mapToOutputFn) { return groupingKey(wholeItem()).distinct(mapToOutputFn); }
/** * Attaches a stage that passes through just the items that are distinct * within their window (no two items emitted for a window are equal). There * is no guarantee which one of the items with the same key will pass * through. The stage emits results in the form of {@link TimestampedItem * TimestampedItem(windowEnd, distinctItem)}. * * @return the newly attached stage */ @Nonnull default StreamStage<TimestampedItem<T>> distinct() { return groupingKey(wholeItem()).distinct(); }
@SuppressWarnings("Convert2MethodRef") // https://bugs.openjdk.java.net/browse/JDK-8154236 private static Pipeline groupAndAggregate() { Pipeline p = Pipeline.create(); p.drawFrom(Sources.<PageVisit, Integer, PageVisit>mapJournal(PAGE_VISIT, mapPutEvents(), mapEventNewValue(), START_FROM_OLDEST)) .addTimestamps(pv -> pv.timestamp(), 100) .window(sliding(10, 1)) .groupingKey(pv -> pv.userId()) .aggregate(toList()) .drainTo(Sinks.logger()); return p; }