Class 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:
Serializable
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.beam.sdk.coders.Coder
Coder.Context, Coder.NonDeterministicException -
Method Summary
Modifier and TypeMethodDescriptionbooleandecode(InputStream inStream) Decodes a value of typeTfrom the given input stream in the given context.decode(InputStream inStream, Coder.Context context) Decodes a value of typeTfrom the given input stream in the given context.voidencode(Map<K, V> map, OutputStream outStream) Encodes the given value of typeTonto the given output stream.voidencode(Map<K, V> map, OutputStream outStream, Coder.Context context) Encodes the given value of typeTonto the given output stream in the given context.TypeDescriptor<Map<K, V>> Returns theTypeDescriptorfor the type encoded.static <K,V> MapCoder <K, V> Produces a MapCoder with the given keyCoder and valueCoder.voidregisterByteSizeObserver(Map<K, V> map, org.apache.beam.sdk.util.common.ElementByteSizeObserver observer) Notifies theElementByteSizeObserverabout the byte size of the encoded value using thisCoder.structuralValue(Map<K, V> value) Returns an object with anObject.equals()method that represents structural equality on the argument.voidThrowCoder.NonDeterministicExceptionif the coding is not deterministic.Methods inherited from class org.apache.beam.sdk.coders.StructuredCoder
equals, getComponents, hashCode, toStringMethods inherited from class org.apache.beam.sdk.coders.Coder
getEncodedElementByteSize, getEncodedElementByteSizeUsingCoder, isRegisterByteSizeObserverCheap, verifyDeterministic, verifyDeterministic
-
Method Details
-
of
Produces a MapCoder with the given keyCoder and valueCoder. -
getKeyCoder
-
getValueCoder
-
encode
Description copied from class:CoderEncodes the given value of typeTonto the given output stream. Multiple elements can be encoded next to each other on the output stream, each coder should encode information to know how many bytes to read when decoding. A common approach is to prefix the encoding with the element's encoded length.- Specified by:
encodein classCoder<Map<K,V>> - Throws:
IOException- if writing to theOutputStreamfails for some reasonCoderException- if the value could not be encoded for some reason
-
encode
public void encode(Map<K, V> map, OutputStream outStream, Coder.Context context) throws IOException, CoderExceptionDescription copied from class:CoderEncodes the given value of typeTonto the given output stream in the given context.- Overrides:
encodein classCoder<Map<K,V>> - Throws:
IOException- if writing to theOutputStreamfails for some reasonCoderException- if the value could not be encoded for some reason
-
decode
Description copied from class:CoderDecodes a value of typeTfrom the given input stream in the given context. Returns the decoded value. Multiple elements can be encoded next to each other on the input stream, each coder should encode information to know how many bytes to read when decoding. A common approach is to prefix the encoding with the element's encoded length.- Specified by:
decodein classCoder<Map<K,V>> - Throws:
IOException- if reading from theInputStreamfails for some reasonCoderException- if the value could not be decoded for some reason
-
decode
public Map<K,V> decode(InputStream inStream, Coder.Context context) throws IOException, CoderException Description copied from class:CoderDecodes a value of typeTfrom the given input stream in the given context. Returns the decoded value.- Overrides:
decodein classCoder<Map<K,V>> - Throws:
IOException- if reading from theInputStreamfails for some reasonCoderException- if the value could not be decoded for some reason
-
getCoderArguments
-
verifyDeterministic
ThrowCoder.NonDeterministicExceptionif the coding is not deterministic.In order for a
Coderto 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
Coderalways produces a canonical encoding, which is the same for an instance of an object even if produced on different computers at different times.
- Specified by:
verifyDeterministicin classCoder<Map<K,V>> - Throws:
Coder.NonDeterministicException- always. Not all maps have a deterministic encoding. For example,HashMapcomparison does not depend on element order, so twoHashMapinstances may be equal but produce different encodings.
- two values that compare as equal (via
-
consistentWithEquals
public boolean consistentWithEquals()Description copied from class:CoderReturnstrueif thisCoderis injective with respect toObject.equals(java.lang.Object).Whenever the encoded bytes of two values are equal, then the original values are equal according to
Objects.equals(). Note that this is well-defined fornull.This condition is most notably false for arrays. More generally, this condition is false whenever
equals()compares object identity, rather than performing a semantic/structural comparison.By default, returns false.
- Overrides:
consistentWithEqualsin classCoder<Map<K,V>>
-
structuralValue
Description copied from class:CoderReturns an object with anObject.equals()method that represents structural equality on the argument.For any two values
xandyof typeT, if their encoded bytes are the same, then it must be the case thatstructuralValue(x).equals(structuralValue(y)).Most notably:
- The structural value for an array coder should perform a structural comparison of the contents of the arrays, rather than the default behavior of comparing according to object identity.
- The structural value for a coder accepting
nullshould be a proper object with anequals()method, even if the input value isnull.
See also
Coder.consistentWithEquals().By default, if this coder is
Coder.consistentWithEquals(), and the value is not null, returns the provided object. Otherwise, encodes the value into abyte[], and returns an object that performs array equality on the encoded bytes.- Overrides:
structuralValuein classCoder<Map<K,V>>
-
registerByteSizeObserver
public void registerByteSizeObserver(Map<K, V> map, org.apache.beam.sdk.util.common.ElementByteSizeObserver observer) throws ExceptionDescription copied from class:CoderNotifies theElementByteSizeObserverabout the byte size of the encoded value using thisCoder.Not intended to be called by user code, but instead by
PipelineRunnerimplementations.By default, this notifies
observerabout the byte size of the encoded value using this coder as returned byCoder.getEncodedElementByteSize(T). -
getEncodedTypeDescriptor
Description copied from class:CoderReturns theTypeDescriptorfor the type encoded.- Overrides:
getEncodedTypeDescriptorin classCoder<Map<K,V>>
-