Package org.apache.spark.sql.streaming
Interface MapState<K,V>
- All Superinterfaces:
Serializable
Interface used for arbitrary stateful operations with the v2 API to capture map value state.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Function to remove the state for the current grouping key.boolean
containsKey
(K key) Function to check if the user map key is contained in the map for the current grouping key.boolean
exists()
Function to check whether any user map entry exists for current grouping key or not.Function to get the state value for current grouping key and user map key.iterator()
Function to return the iterator of user map key-value pairs present in the map for the current grouping key.scala.collection.Iterator<K>
keys()
Function to return the user map keys present in the map for the current grouping key.void
Function to remove the user map key from the map for the current grouping key.void
updateValue
(K key, V value) Function to add or update the map entry for the current grouping key.scala.collection.Iterator<V>
values()
Function to return the user map values present in the map for the current grouping key.
-
Method Details
-
clear
void clear()Function to remove the state for the current grouping key. Note that this removes the entire map state associated with the current grouping key. -
containsKey
Function to check if the user map key is contained in the map for the current grouping key.- Parameters:
key
- - user map key- Returns:
- - true if the user key is present in the map, false otherwise.
-
exists
boolean exists()Function to check whether any user map entry exists for current grouping key or not.- Returns:
- - true if state exists, false otherwise.
-
getValue
Function to get the state value for current grouping key and user map key. If the state exists, the value is returned. If the state does not exist, the default value for the type is returned for AnyVal types and null for AnyRef types.Note that it's always recommended to check whether the state exists or not by calling exists() before calling get().
- Parameters:
key
- (undocumented)- Returns:
- - the value of the state if it exists. If the state does not exist, the default value for the type is returned for AnyVal types and null for AnyRef types.
-
iterator
Function to return the iterator of user map key-value pairs present in the map for the current grouping key.- Returns:
- - iterator of user map key-value pairs if the map is not empty and empty iterator otherwise.
-
keys
scala.collection.Iterator<K> keys()Function to return the user map keys present in the map for the current grouping key.- Returns:
- - iterator of user map keys if the map is not empty, empty iterator otherwise.
-
removeKey
Function to remove the user map key from the map for the current grouping key.Note that this function will remove the user map key and its associated value from the map associated with the current grouping key. If the user map key is not present in the map, this function will not do anything.
- Parameters:
key
- - user map key
-
updateValue
Function to add or update the map entry for the current grouping key.Note that this function will add the user map key and value if the user map key is not present in the map associated with the current grouping key. If the user map key is already present in the associated map, the value for the user key will be updated to the new user map value.
- Parameters:
key
- - user map keyvalue
- - user map value
-
values
scala.collection.Iterator<V> values()Function to return the user map values present in the map for the current grouping key.- Returns:
- - iterator of user map values if the map is not empty, empty iterator otherwise.
-