Class ListView<T>
- java.lang.Object
-
- org.apache.flink.table.api.dataview.ListView<T>
-
- Type Parameters:
T- element type
- All Implemented Interfaces:
DataView
@TypeInfo(ListViewTypeInfoFactory.class) @PublicEvolving public class ListView<T> extends Object implements DataView
ADataViewthat providesList-like functionality in the accumulator of anAggregateFunctionorTableAggregateFunctionwhen large amounts of data are expected.A
ListViewcan be backed by a JavaArrayListor can leverage Flink's state backends depending on the context in which the aggregate function is used. In many unbounded data scenarios, theListViewdelegates all calls to aListStateinstead of theArrayList.Note: Elements of a
ListViewmust not be null. For heap-based state backends,hashCode/equalsof the original (i.e. external) class are used. However, the serialization format will use internal data structures.The
DataTypeof the view's elements is reflectively extracted from the accumulator definition. This includes the generic argumentTof this class. If reflective extraction is not successful, it is possible to use aDataTypeHinton top the accumulator field. It will be mapped to the underlying collection.The following examples show how to specify an
AggregateFunctionwith aListView:public class MyAccumulator { public ListView<String> list = new ListView<>(); // or explicit: // {@literal @}DataTypeHint("ARRAY<STRING>") // public ListView<String> list = new ListView<>(); public long count = 0L; } public class MyAggregateFunction extends AggregateFunction<String, MyAccumulator> { {@literal @}Override public MyAccumulator createAccumulator() { return new MyAccumulator(); } public void accumulate(MyAccumulator accumulator, String id) { accumulator.list.add(id); accumulator.count++; } {@literal @}Override public String getValue(MyAccumulator accumulator) { // return the count and the joined elements return count + ": " + String.join("|", acc.list.get()); } }
-
-
Field Summary
Fields Modifier and Type Field Description org.apache.flink.api.common.typeinfo.TypeInformation<?>elementTypeDeprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(T value)Adds the given value to the list.voidaddAll(List<T> list)Adds all of the elements of the specified list to this list view.voidclear()Removes all of the elements from this list view.booleanequals(Object o)Iterable<T>get()Returns an iterable of the list view.List<T>getList()Returns the entire view's content as an instance ofList.inthashCode()static DataTypenewListViewDataType(DataType elementDataType)booleanremove(T value)Removes the given value from the list.voidsetList(List<T> list)Replaces the entire view's content with the content of the givenList.
-
-
-
Field Detail
-
elementType
@Deprecated public transient org.apache.flink.api.common.typeinfo.TypeInformation<?> elementType
Deprecated.
-
-
Constructor Detail
-
ListView
public ListView()
Creates a list view.The
DataTypeof the contained elements is reflectively extracted.
-
ListView
@Deprecated public ListView(org.apache.flink.api.common.typeinfo.TypeInformation<?> elementType)
Deprecated.This method uses the old type system. Please use aDataTypeHintinstead if the reflective type extraction is not successful.Creates aListViewfor elements of the specified type.- Parameters:
elementType- The type of the list view elements.
-
-
Method Detail
-
setList
public void setList(List<T> list)
Replaces the entire view's content with the content of the givenList.
-
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 of the elements from this list view.
-
-