Class EventTimeSessionWindows

  • All Implemented Interfaces:
    Serializable

    @PublicEvolving
    public class EventTimeSessionWindows
    extends org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner<Object,​org.apache.flink.streaming.api.windowing.windows.TimeWindow>
    A WindowAssigner that windows elements into sessions based on the timestamp of the elements. Windows cannot overlap.

    For example, in order to window into windows of 1 minute, every 10 seconds:

    
     DataStream<Tuple2<String, Integer>> in = ...;
     KeyedStream<String, Tuple2<String, Integer>> keyed = in.keyBy(...);
     WindowedStream<Tuple2<String, Integer>, String, TimeWindows> windowed =
       keyed.window(EventTimeSessionWindows.withGap(Duration.ofMinutes(1)));
     
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner

        org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner.MergeCallback<W extends Object>
      • Nested classes/interfaces inherited from class org.apache.flink.streaming.api.windowing.assigners.WindowAssigner

        org.apache.flink.streaming.api.windowing.assigners.WindowAssigner.WindowAssignerContext
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected long sessionTimeout  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected EventTimeSessionWindows​(long sessionTimeout)  
    • Field Detail

      • sessionTimeout

        protected long sessionTimeout
    • Constructor Detail

      • EventTimeSessionWindows

        protected EventTimeSessionWindows​(long sessionTimeout)
    • Method Detail

      • assignWindows

        public Collection<org.apache.flink.streaming.api.windowing.windows.TimeWindow> assignWindows​(Object element,
                                                                                                     long timestamp,
                                                                                                     org.apache.flink.streaming.api.windowing.assigners.WindowAssigner.WindowAssignerContext context)
        Specified by:
        assignWindows in class org.apache.flink.streaming.api.windowing.assigners.WindowAssigner<Object,​org.apache.flink.streaming.api.windowing.windows.TimeWindow>
      • getDefaultTrigger

        public org.apache.flink.streaming.api.windowing.triggers.Trigger<Object,​org.apache.flink.streaming.api.windowing.windows.TimeWindow> getDefaultTrigger()
        Specified by:
        getDefaultTrigger in class org.apache.flink.streaming.api.windowing.assigners.WindowAssigner<Object,​org.apache.flink.streaming.api.windowing.windows.TimeWindow>
      • withGap

        public static EventTimeSessionWindows withGap​(Duration size)
        Creates a new SessionWindows WindowAssigner that assigns elements to sessions based on the element timestamp.
        Parameters:
        size - The session timeout, i.e. the time gap between sessions
        Returns:
        The policy.
      • withDynamicGap

        @PublicEvolving
        public static <T> DynamicEventTimeSessionWindows<T> withDynamicGap​(SessionWindowTimeGapExtractor<T> sessionWindowTimeGapExtractor)
        Creates a new SessionWindows WindowAssigner that assigns elements to sessions based on the element timestamp.
        Parameters:
        sessionWindowTimeGapExtractor - The extractor to use to extract the time gap from the input elements
        Returns:
        The policy.
      • getWindowSerializer

        public org.apache.flink.api.common.typeutils.TypeSerializer<org.apache.flink.streaming.api.windowing.windows.TimeWindow> getWindowSerializer​(org.apache.flink.api.common.ExecutionConfig executionConfig)
        Specified by:
        getWindowSerializer in class org.apache.flink.streaming.api.windowing.assigners.WindowAssigner<Object,​org.apache.flink.streaming.api.windowing.windows.TimeWindow>
      • isEventTime

        public boolean isEventTime()
        Specified by:
        isEventTime in class org.apache.flink.streaming.api.windowing.assigners.WindowAssigner<Object,​org.apache.flink.streaming.api.windowing.windows.TimeWindow>
      • mergeWindows

        public void mergeWindows​(Collection<org.apache.flink.streaming.api.windowing.windows.TimeWindow> windows,
                                 org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner.MergeCallback<org.apache.flink.streaming.api.windowing.windows.TimeWindow> c)
        Merge overlapping TimeWindows.
        Specified by:
        mergeWindows in class org.apache.flink.streaming.api.windowing.assigners.MergingWindowAssigner<Object,​org.apache.flink.streaming.api.windowing.windows.TimeWindow>