Google Cloud Dataflow SDK for Java, version 1.9.1
com.google.cloud.dataflow.sdk.coders
Class MapCoder<K,V>
- java.lang.Object
-
- com.google.cloud.dataflow.sdk.coders.StandardCoder<T>
-
- com.google.cloud.dataflow.sdk.coders.MapCoderBase<Map<K,V>>
-
- com.google.cloud.dataflow.sdk.coders.MapCoder<K,V>
-
- Type Parameters:
K
- the type of the keys of the KVs being transcodedV
- the type of the values of the KVs being transcoded
- All Implemented Interfaces:
- Coder<Map<K,V>>, Serializable
public class MapCoder<K,V> extends MapCoderBase<Map<K,V>>
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.google.cloud.dataflow.sdk.coders.Coder
Coder.Context, Coder.NonDeterministicException
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description Map<K,V>
decode(InputStream inStream, Coder.Context context)
Decodes a value of typeT
from the given input stream in the given context.void
encode(Map<K,V> map, OutputStream outStream, Coder.Context context)
Encodes the given value of typeT
onto the given output stream in the given context.List<? extends Coder<?>>
getCoderArguments()
If this is aCoder
for a parameterized type, returns the list ofCoder
s being used for each of the parameters, or returnsnull
if this cannot be done or this is not a parameterized type.static <K,V> List<Object>
getInstanceComponents(Map<K,V> exampleValue)
Returns the key and value for an arbitrary element of this map, if it is non-empty, otherwise returnsnull
.Coder<K>
getKeyCoder()
Coder<V>
getValueCoder()
static <K,V> MapCoder<K,V>
of(Coder<K> keyCoder, Coder<V> valueCoder)
Produces a MapCoder with the given keyCoder and valueCoder.static MapCoder<?,?>
of(List<Coder<?>> components)
void
registerByteSizeObserver(Map<K,V> map, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver observer, Coder.Context context)
Notifies theElementByteSizeObserver
about the byte size of the encoded value using thisCoder
.void
verifyDeterministic()
ThrowCoder.NonDeterministicException
if the coding is not deterministic.-
Methods inherited from class com.google.cloud.dataflow.sdk.coders.MapCoderBase
of
-
Methods inherited from class com.google.cloud.dataflow.sdk.coders.StandardCoder
asCloudObject, consistentWithEquals, equals, getAllowedEncodings, getComponents, getEncodedElementByteSize, getEncodingId, hashCode, isRegisterByteSizeObserverCheap, structuralValue, toString, verifyDeterministic, verifyDeterministic
-
-
-
-
Method Detail
-
of
public static <K,V> MapCoder<K,V> of(Coder<K> keyCoder, Coder<V> valueCoder)
Produces a MapCoder with the given keyCoder and valueCoder.
-
getInstanceComponents
public static <K,V> List<Object> getInstanceComponents(Map<K,V> exampleValue)
Returns the key and value for an arbitrary element of this map, if it is non-empty, otherwise returnsnull
.
-
encode
public void encode(Map<K,V> map, OutputStream outStream, Coder.Context context) throws IOException, CoderException
Description copied from interface:Coder
Encodes the given value of typeT
onto the given output stream in the given context.- Throws:
IOException
- if writing to theOutputStream
fails for some reasonCoderException
- if the value could not be encoded for some reason
-
decode
public Map<K,V> decode(InputStream inStream, Coder.Context context) throws IOException, CoderException
Description copied from interface:Coder
Decodes a value of typeT
from the given input stream in the given context. Returns the decoded value.- Throws:
IOException
- if reading from theInputStream
fails for some reasonCoderException
- if the value could not be decoded for some reason
-
getCoderArguments
public List<? extends Coder<?>> getCoderArguments()
If this is aCoder
for a parameterized type, returns the list ofCoder
s being used for each of the parameters, or returnsnull
if this cannot be done or this is not a parameterized type.- Returns:
- a
List
containing the key coder at index 0 at the and value coder at index 1.
-
verifyDeterministic
public void verifyDeterministic() throws Coder.NonDeterministicException
ThrowCoder.NonDeterministicException
if the coding is not deterministic.In order for a
Coder
to be considered deterministic, the following must be true:- two values that compare as equal (via
Object.equals()
orComparable.compareTo()
, if supported) have the same encoding. - the
Coder
always produces a canonical encoding, which is the same for an instance of an object even if produced on different computers at different times.
- Throws:
NonDeterministicException
- always. Not all maps have a deterministic encoding. For example,HashMap
comparison does not depend on element order, so twoHashMap
instances may be equal but produce different encodings.Coder.NonDeterministicException
- if this coder is not deterministic.
- two values that compare as equal (via
-
registerByteSizeObserver
public void registerByteSizeObserver(Map<K,V> map, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver observer, Coder.Context context) throws Exception
Description copied from class:StandardCoder
Notifies theElementByteSizeObserver
about the byte size of the encoded value using thisCoder
.Not intended to be called by user code, but instead by
PipelineRunner
implementations.For
StandardCoder
subclasses, this notifiesobserver
about the byte size of the encoded value using this coder as returned byStandardCoder.getEncodedElementByteSize(T, com.google.cloud.dataflow.sdk.coders.Coder.Context)
.- Specified by:
registerByteSizeObserver
in interfaceCoder<Map<K,V>>
- Overrides:
registerByteSizeObserver
in classStandardCoder<Map<K,V>>
- Throws:
Exception
-
-