com.ibm.streams.operator.window.sort

Class SortedTupleWindow

  • All Implemented Interfaces:
    StateHandler, StreamWindowListener<Tuple>, java.io.Closeable, java.lang.AutoCloseable, java.util.EventListener
    Direct Known Subclasses:
    TumblingWindowSort


    public abstract class SortedTupleWindow
    extends StatefulWindowListener<java.util.List<Tuple>,Tuple>
    Abstract window handler that sorts incoming generic tuples according to a comparator for the window's tuples. Each partition's state contains the full set as a List<Tuple> of tuples in the window for that partition in order of the comparator.
    Tuples that are duplicates according to the comparator are kept in the state, though the order within duplicates is not defined.
    • Constructor Detail

      • SortedTupleWindow

        protected SortedTupleWindow(StreamWindow<Tuple> window,
                         boolean ascending,
                         java.lang.String... attributeNames)
        Sort tuples according to a set of attributes using comparators that match the natural ordering of the Java object mapping for the attributes SPL type.
        Parameters:
        window - Window being sorted.
        ascending - True if the comparator is to order from low to high, false for high to low.
        attributeNames - Names of attributes to be included in the ordering. If no names are supplied then the ordering will be across all attributes that are comparable.
        See Also:
        StreamSchema.getAttributesComparator(boolean, String...)
      • SortedTupleWindow

        protected SortedTupleWindow(StreamWindow<Tuple> window,
                         boolean ascending,
                         java.util.List<java.lang.String> attributeNames)
        Sort tuples according to a set of attributes using comparators that match the natural ordering of the Java object mapping for the attributes SPL type.
        Parameters:
        window - Window being sorted.
        ascending - True if the comparator is to order from low to high, false for high to low.
        attributeNames - Names of attributes to be included in the ordering. If no names are supplied then the ordering will be across all attributes that are comparable.
      • SortedTupleWindow

        protected SortedTupleWindow(StreamWindow<Tuple> window,
                         java.util.Comparator<Tuple> comparator)
        Sort the tuples according to a specific comparator.
        Parameters:
        window - Window being sorted.
        comparator - Comparator used to sort.
    • Method Detail

      • getInitializedState

        protected java.util.List<Tuple> getInitializedState(java.lang.Object partition,
                                                java.util.List<Tuple> state)
        Return a new linked list each time.
        Specified by:
        getInitializedState in class StatefulWindowListener<java.util.List<Tuple>,Tuple>
        Parameters:
        partition - Partition for the state.
        state - The previous state or null if this is the first call.
        Returns:
        An initialized state object.
      • handleEvent

        public void handleEvent(StreamWindowEvent<Tuple> event)
                         throws java.lang.Exception
        Handle INSERTION and EVICTION events to maintain a sorted List of tuples in the window.
        Parameters:
        event - Windowing event.
        Throws:
        java.lang.Exception - Exception processing an event.