Class ListView<T>

  • Type Parameters:
    T - element type
    All Implemented Interfaces:
    DataView

    @PublicEvolving
    public class ListView<T>
    extends Object
    implements DataView
    A DataView that provides List-like functionality in state entries.

    A ListView can be backed by a Java ArrayList or can leverage Flink's state backends depending on the context. In many unbounded data scenarios, the ListView delegates all calls to a ListState instead of the ArrayList.

    For aggregating functions, the view can be used as a field in the accumulator of an AggregateFunction or TableAggregateFunction when large amounts of data are expected. Aggregate functions might be used at various locations (pre-aggregation, combiners, merging of window slides, etc.) for some of these locations the data view is not backed by state but ArrayList.

    For process table functions, the view can be used as a top-level state entry. Data views in PTFs are always backed by state.

    Note: Elements of a ListView must not be null. For heap-based state backends, hashCode/equals of the original (i.e. external) class are used. However, the serialization format will use internal data structures.

    The DataType of the view's elements is reflectively extracted from the accumulator definition. This includes the generic argument T of this class. If reflective extraction is not successful, it is possible to use a DataTypeHint on top the accumulator field. It will be mapped to the underlying collection.

    The following examples show how to specify an AggregateFunction with a ListView:

    {@code
      public class MyAccumulator {
    
        public ListView list = new ListView<>();
    
        // or explicit:
        // @DataTypeHint("ARRAY < STRING >")
        // public ListView list = new ListView<>();
    
        public long count = 0L;
      }
    
      public class MyAggregateFunction extends AggregateFunction {
    • Constructor Detail

      • ListView

        public ListView()
        Creates a list view.

        The DataType of the contained elements is reflectively extracted.

    • Method Detail

      • getList

        public List<T> getList()
        Returns the entire view's content as an instance of List.
      • setList

        public void setList​(List<T> list)
        Replaces the entire view's content with the content of the given List.
      • get

        public Iterable<T> get()
                        throws Exception
        Returns an iterable of the list view.
        Returns:
        The iterable of the list.
        Throws:
        Exception - Thrown if the system cannot get data.
      • add

        public void add​(T value)
                 throws Exception
        Adds the given value to the list.
        Parameters:
        value - The element to be appended to this list view.
        Throws:
        Exception - Thrown if the system cannot add data.
      • addAll

        public void addAll​(List<T> list)
                    throws Exception
        Adds all of the elements of the specified list to this list view.
        Parameters:
        list - The list with the elements that will be stored in this list view.
        Throws:
        Exception - Thrown if the system cannot add all data.
      • remove

        public boolean remove​(T value)
                       throws Exception
        Removes the given value from the list.
        Parameters:
        value - The element to be removed from this list view.
        Throws:
        Exception
      • clear

        public void clear()
        Removes all elements from this list view.
        Specified by:
        clear in interface DataView
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object