com.ibm.streamsx.topology

Interface TWindow<T,K>

  • Type Parameters:
    T - Tuple type, any instance of T at runtime must be serializable.
    K - Key type.
    All Superinterfaces:
    TopologyElement
    All Known Subinterfaces:
    SPLWindow


    public interface TWindow<T,K>
    extends TopologyElement
    Declares a window of tuples for a TStream. Logically a Window represents an continuously updated ordered list of tuples according to the criteria that created it. For example s.last(10) declares a window that at any time contains the last ten tuples seen on stream s, while s.last(5, TimeUnit.SECONDS) is a window that always contains all tuples present on stream s in the last five seconds.

    Typically windows are partitioned by a key which means the window's configuration is independently maintained for each key seen on the stream. For example with a window created using last(3) then each key has its own window partition containing the last three tuples with the same key.
    A partitioned window is created by calling key(Function) or key().
    When a window is not partitioned it acts as though it has a single partition with a constant key with the value Integer.valueOf(0).

    See Also:
    TStream.last(), TStream.last(int), TStream.last(long, java.util.concurrent.TimeUnit), TStream.window(TWindow)
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method and Description
      <A> TStream<A> aggregate(Function<java.util.List<T>,A> aggregator, long period, java.util.concurrent.TimeUnit unit)
      Declares a stream that containing tuples that represent an aggregation of this window.
      <A> TStream<A> aggregate(Function<java.util.List<T>,A> aggregator)
      Declares a stream that containing tuples that represent an aggregation of this window.
      TStream<T> getStream()
      Get this window's stream.
      java.lang.Class<T> getTupleClass()
      Class of the tuples in this window.
      java.lang.reflect.Type getTupleType()
      Type of the tuples in this window.
      boolean isKeyed()
      Is the window keyed.
      TWindow<T,T> key()
      Return a keyed (partitioned) window that has the same configuration as this window with each tuple being the key.
      <U> TWindow<T,U> key(Function<? super T,? extends U> keyFunction)
      Return a keyed (partitioned) window that has the same configuration as this window with the each tuple's key defined by a function.
    • Method Detail

      • aggregate

        <A> TStream<A> aggregate(Function<java.util.List<T>,A> aggregator)
        Declares a stream that containing tuples that represent an aggregation of this window. Each time the contents of the window is updated by a new tuple being added to it, or a tuple being evicted from the window aggregator.call(tuples) is called, where tuples is an List that containing all the tuples in the current window. The List is stable during the method call, and returns the tuples in order of insertion into the window, from oldest to newest.
        Thus the returned stream will contain a sequence of tuples that where the most recent tuple represents the most up to date aggregation of this window or window partition.
        Parameters:
        aggregator - Logic to aggregation the complete window contents.
        Returns:
        A stream that contains the latest aggregations of this window.
      • aggregate

        <A> TStream<A> aggregate(Function<java.util.List<T>,A> aggregator,
                                 long period,
                                 java.util.concurrent.TimeUnit unit)
        Declares a stream that containing tuples that represent an aggregation of this window. Approximately every period (with unit unit) aggregator.call(tuples) is called, where tuples is an List that containing all the tuples in the current window. The List is stable during the method call, and returns the tuples in order of insertion into the window, from oldest to newest.
        Thus the returned stream will contain a new tuple every period seconds (according to unit) aggregation of this window or window partition.
        Parameters:
        aggregator - Logic to aggregation the complete window contents.
        period - Approximately how often to perform the aggregation.
        unit - Time unit for period.
        Returns:
        A stream that contains the latest aggregations of this window.
      • getTupleClass

        java.lang.Class<T> getTupleClass()
        Class of the tuples in this window. WIll be the same as getTupleType() is a Class object.
        Returns:
        Class of the tuple in this window, null if getTupleType() is not a Class object.
      • getTupleType

        java.lang.reflect.Type getTupleType()
        Type of the tuples in this window.
        Returns:
        Type of the tuples in this window.
      • getStream

        TStream<T> getStream()
        Get this window's stream.
        Returns:
        This window's stream.
      • key

        <U> TWindow<T,U> key(Function<? super T,? extends U> keyFunction)
        Return a keyed (partitioned) window that has the same configuration as this window with the each tuple's key defined by a function. A keyed window is a window where each tuple has an inherent key, defined by keyFunction.

        All tuples that have the same key will be processed as an independent window. For example, with a window created using last(3) then each key has its own window containing the last three tuples with the same key.

        Type Parameters:
        U - Type of the key.
        Parameters:
        keyFunction - Function that gets the key from a tuple. The key function must be stateless.
        Returns:
        Keyed window with the same configuration as this window.
      • key

        TWindow<T,T> key()
        Return a keyed (partitioned) window that has the same configuration as this window with each tuple being the key. The key of each tuple is the tuple itself.
        Returns:
        Keyed window with the same configuration as this window.
        See Also:
        key(Function)
      • isKeyed

        boolean isKeyed()
        Is the window keyed.
        Returns:
        true if the window is keyed, false if it is not keyed.
        See Also:
        key(Function), key()
streamsx.topology 2.1 @ IBMStreams GitHub