K - the type of the keys of the KVs being transcodedV - the type of the values of the KVs being transcodedpublic class MapCoder<K,V> extends StandardCoder<Map<K,V>>
Coder.Context, Coder.NonDeterministicException| Modifier and Type | Method and Description |
|---|---|
Map<K,V> |
decode(InputStream inStream,
Coder.Context context)
Decodes a value of type
T 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 type
T onto the given output stream
in the given context. |
List<? extends Coder<?>> |
getCoderArguments()
If this is a
Coder for a parameterized type, returns the
list of Coders being used for each of the parameters, or
returns null 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 returns
null. |
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,
org.apache.beam.sdk.util.common.ElementByteSizeObserver observer,
Coder.Context context)
Notifies the
ElementByteSizeObserver about the byte size
of the encoded value using this Coder. |
void |
verifyDeterministic()
Throw
Coder.NonDeterministicException if the coding is not deterministic. |
asCloudObject, consistentWithEquals, equals, getAllowedEncodings, getComponents, getEncodedElementByteSize, getEncodingId, hashCode, isRegisterByteSizeObserverCheap, structuralValue, toString, verifyDeterministic, verifyDeterministicpublic static <K,V> MapCoder<K,V> of(Coder<K> keyCoder, Coder<V> valueCoder)
public static <K,V> List<Object> getInstanceComponents(Map<K,V> exampleValue)
null.public void encode(Map<K,V> map, OutputStream outStream, Coder.Context context) throws IOException, CoderException
CoderT onto the given output stream
in the given context.IOException - if writing to the OutputStream fails
for some reasonCoderException - if the value could not be encoded for some reasonpublic Map<K,V> decode(InputStream inStream, Coder.Context context) throws IOException, CoderException
CoderT from the given input stream in
the given context. Returns the decoded value.IOException - if reading from the InputStream fails
for some reasonCoderException - if the value could not be decoded for some reasonpublic List<? extends Coder<?>> getCoderArguments()
Coder for a parameterized type, returns the
list of Coders being used for each of the parameters, or
returns null if this cannot be done or this is not a
parameterized type.List containing the key coder at index 0 at the and value coder at index 1.public void verifyDeterministic()
throws Coder.NonDeterministicException
Coder.NonDeterministicException if the coding is not deterministic.
In order for a Coder to be considered deterministic,
the following must be true:
Object.equals()
or Comparable.compareTo(), if supported) have the same
encoding.
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.
NonDeterministicException - always. Not all maps have a deterministic encoding.
For example, HashMap comparison does not depend on element order, so
two HashMap instances may be equal but produce different encodings.Coder.NonDeterministicException - if this coder is not deterministic.public void registerByteSizeObserver(Map<K,V> map, org.apache.beam.sdk.util.common.ElementByteSizeObserver observer, Coder.Context context) throws Exception
StandardCoderElementByteSizeObserver about the byte size
of the encoded value using this Coder.
Not intended to be called by user code, but instead by
PipelineRunner
implementations.
For StandardCoder subclasses, this notifies observer about the byte size
of the encoded value using this coder as returned by StandardCoder.getEncodedElementByteSize(T, org.apache.beam.sdk.coders.Coder.Context).
registerByteSizeObserver in interface Coder<Map<K,V>>registerByteSizeObserver in class StandardCoder<Map<K,V>>Exception