T
- element type@TypeInfo(value=ListViewTypeInfoFactory.class) @PublicEvolving public class ListView<T> extends Object implements DataView
DataView
that provides List
-like functionality in the accumulator of an AggregateFunction
or TableAggregateFunction
when large amounts of data are expected.
A ListView
can be backed by a Java ArrayList
or can leverage Flink's state
backends depending on the context in which the aggregate function is used. In many unbounded data
scenarios, the ListView
delegates all calls to a ListState
instead of the ArrayList
.
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
:
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());
}
}
Modifier and Type | Field and Description |
---|---|
TypeInformation<?> |
elementType
Deprecated.
|
Constructor and Description |
---|
ListView()
Creates a list view.
|
ListView(TypeInformation<?> elementType)
Deprecated.
This method uses the old type system. Please use a
DataTypeHint instead
if the reflective type extraction is not successful. |
Modifier and Type | Method and Description |
---|---|
void |
add(T value)
Adds the given value to the list.
|
void |
addAll(List<T> list)
Adds all of the elements of the specified list to this list view.
|
void |
clear()
Removes all of the elements from this list view.
|
boolean |
equals(Object o) |
Iterable<T> |
get()
Returns an iterable of the list view.
|
List<T> |
getList()
Returns the entire view's content as an instance of
List . |
int |
hashCode() |
static DataType |
newListViewDataType(DataType elementDataType)
|
boolean |
remove(T value)
Removes the given value from the list.
|
void |
setList(List<T> list)
Replaces the entire view's content with the content of the given
List . |
@Deprecated public transient TypeInformation<?> elementType
public ListView()
The DataType
of the contained elements is reflectively extracted.
@Deprecated public ListView(TypeInformation<?> elementType)
DataTypeHint
instead
if the reflective type extraction is not successful.ListView
for elements of the specified type.elementType
- The type of the list view elements.public void setList(List<T> list)
List
.public Iterable<T> get() throws Exception
Exception
- Thrown if the system cannot get data.public void add(T value) throws Exception
value
- The element to be appended to this list view.Exception
- Thrown if the system cannot add data.public void addAll(List<T> list) throws Exception
list
- The list with the elements that will be stored in this list view.Exception
- Thrown if the system cannot add all data.public boolean remove(T value) throws Exception
value
- The element to be removed from this list view.Exception
public void clear()
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.