@TypeInfo(value=MapViewTypeInfoFactory.class) @PublicEvolving public class MapView<K,V> extends Object implements DataView
MapView
provides Map functionality for accumulators used by user-defined aggregate
functions [[AggregateFunction]].
A MapView
can be backed by a Java HashMap or a state backend, depending on the
context in which the aggregation function is used.
At runtime MapView
will be replaced by a state MapView which is backed by a
MapState
instead of HashMap
if it works
in streaming.
Example of an accumulator type with a MapView
and an aggregate function that uses it:
public class MyAccum { public MapViewmap; public long count; } public class MyAgg extends AggregateFunction {
Modifier and Type | Field and Description |
---|---|
org.apache.flink.api.common.typeinfo.TypeInformation<?> |
keyType |
Map<K,V> |
map |
org.apache.flink.api.common.typeinfo.TypeInformation<?> |
valueType |
Constructor and Description |
---|
MapView()
Creates a MapView.
|
MapView(org.apache.flink.api.common.typeinfo.TypeInformation<?> keyType,
org.apache.flink.api.common.typeinfo.TypeInformation<?> valueType)
Creates a MapView with the specified key and value types.
|
MapView(org.apache.flink.api.common.typeinfo.TypeInformation<?> keyType,
org.apache.flink.api.common.typeinfo.TypeInformation<?> valueType,
Map<K,V> map) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all entries of this map.
|
boolean |
contains(K key)
Checks if the map view contains a value for a given key.
|
Iterable<Map.Entry<K,V>> |
entries()
Returns all entries of the map view.
|
boolean |
equals(Object other) |
V |
get(K key)
Return the value for the specified key or
null if the key is not in the map view. |
int |
hashCode() |
Iterator<Map.Entry<K,V>> |
iterator()
Returns an iterator over all entries of the map view.
|
Iterable<K> |
keys()
Returns all the keys in the map view.
|
void |
put(K key,
V value)
Inserts a value for the given key into the map view.
|
void |
putAll(Map<K,V> map)
Inserts all mappings from the specified map to this map view.
|
void |
remove(K key)
Deletes the value for the given key.
|
Iterable<V> |
values()
Returns all the values in the map view.
|
public transient org.apache.flink.api.common.typeinfo.TypeInformation<?> keyType
public transient org.apache.flink.api.common.typeinfo.TypeInformation<?> valueType
public MapView(org.apache.flink.api.common.typeinfo.TypeInformation<?> keyType, org.apache.flink.api.common.typeinfo.TypeInformation<?> valueType, Map<K,V> map)
public MapView(org.apache.flink.api.common.typeinfo.TypeInformation<?> keyType, org.apache.flink.api.common.typeinfo.TypeInformation<?> valueType)
keyType
- The type of keys of the MapView.valueType
- The type of the values of the MapView.public MapView()
public V get(K key) throws Exception
null
if the key is not in the map view.key
- The look up key.Exception
- Thrown if the system cannot get data.public void put(K key, V value) throws Exception
key
- The key for which the value is inserted.value
- The value that is inserted for the key.Exception
- Thrown if the system cannot put data.public void putAll(Map<K,V> map) throws Exception
map
- The map whose entries are inserted into this map view.Exception
- Thrown if the system cannot access the map.public void remove(K key) throws Exception
key
- The key for which the value is deleted.Exception
- Thrown if the system cannot access the map.public boolean contains(K key) throws Exception
key
- The key to check.Exception
- Thrown if the system cannot access the map.public Iterable<Map.Entry<K,V>> entries() throws Exception
Exception
- Thrown if the system cannot access the map.public Iterable<K> keys() throws Exception
Exception
- Thrown if the system cannot access the map.public Iterable<V> values() throws Exception
Exception
- Thrown if the system cannot access the map.public Iterator<Map.Entry<K,V>> iterator() throws Exception
Exception
- Thrown if the system cannot access the map.public void clear()
Copyright © 2014–2019 The Apache Software Foundation. All rights reserved.