flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fhueske <...@git.apache.org>
Subject [GitHub] flink pull request #2368: [FLINK-3899] Document window processing with Reduc...
Date Tue, 23 Aug 2016 22:01:18 GMT
Github user fhueske commented on a diff in the pull request:

    --- Diff: docs/apis/streaming/windows.md ---
    @@ -459,42 +459,106 @@ ready for processing. This allows to get the benefit of incremental
window compu
     the additional meta information that writing a `WindowFunction` provides.
     This is an example that shows how incremental aggregation functions can be combined with
    -a `WindowFunction`.
    +a `WindowFunction`.  The `FoldFunction`/`WindowFunction` example shows how to extract
    +ending event-time of a window of sensor readings that contain a timestamp, 
    +and the `ReduceFunction`/`WindowFunctions` example shows how to do eager window
    +aggregation (only a single element is kept in the window).
     <div class="codetabs" markdown="1">
     <div data-lang="java" markdown="1">
     {% highlight java %}
    -DataStream<Tuple2<String, Long>> input = ...;
    +DataStream<SensorReading> input = ...;
     // for folding incremental computation
         .keyBy(<key selector>)
         .window(<window assigner>)
    -    .apply(<initial value>, new MyFoldFunction(), new MyWindowFunction());
    +    .apply(Long.MIN_VALUE, new MyFoldFunction(), new MyWindowFunction());
    +/* ... */
    +private static  class myFoldFunction implements FoldFunction<SensorReading, Long>
    +    public Long fold(Long acc, SensorReading s) {
    +        return Math.max(acc, s.timestamp());
    +    }
    +private static class MyWindowFunction implements WindowFunction<Long, Long, String,
TimeWindow> {
    +    public void apply(String key, TimeWindow window, Iterable<Long> timestamps,
Collector<Long> out) {
    +            out.collect(timestamps.iterator().next());
    --- End diff --
    `Math.max(acc.getField(1), s.timestamp())` will give you the timestamp of the last element
that was added to the window (assuming they arrive in event-time). With end time of the window
I meant the time stamp after which an element would be placed in the next window (for an hourly
tumbling window this would be `00:59:59.999` for the window from `00:00:00:000` to  `00:59:59.999`).
This information is only available in a `WindowFunction` through the `TimeWindow` object.

If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.

View raw message