Class SortedMapCoder<K extends Comparable<? super 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(SortedMap<K, V> map, OutputStream outStream) Encodes the given value of typeTonto the given output stream.voidencode(SortedMap<K, V> map, OutputStream outStream, Coder.Context context) Encodes the given value of typeTonto the given output stream in the given context.Returns theTypeDescriptorfor the type encoded.static <K extends Comparable<? super K>,V>
SortedMapCoder<K, V> Produces a MapCoder with the given keyCoder and valueCoder.voidregisterByteSizeObserver(SortedMap<K, V> map, org.apache.beam.sdk.util.common.ElementByteSizeObserver observer) Notifies theElementByteSizeObserverabout the byte size of the encoded value using thisCoder.structuralValue(SortedMap<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
public static <K extends Comparable<? super K>,V> SortedMapCoder<K,V> of(Coder<K> keyCoder, Coder<V> valueCoder) 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<SortedMap<K extends Comparable<? super 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(SortedMap<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<SortedMap<K extends Comparable<? super 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<SortedMap<K extends Comparable<? super K>,V>> - Throws:
IOException- if reading from theInputStreamfails for some reasonCoderException- if the value could not be decoded for some reason
-
decode
public SortedMap<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<SortedMap<K extends Comparable<? super K>,V>> - Throws:
IOException- if reading from theInputStreamfails for some reasonCoderException- if the value could not be decoded for some reason
-
getCoderArguments
If this is aCoderfor a parameterized type, returns the list ofCoders being used for each of the parameters in the same order they appear within the parameterized type's type signature. If this cannot be done, or thisCoderdoes not encode/decode a parameterized type, returns the empty list.- Specified by:
getCoderArgumentsin classCoder<SortedMap<K extends Comparable<? super K>,V>> - Returns:
- a
Listcontaining the key coder at index 0 at the and value coder at index 1.
-
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<SortedMap<K extends Comparable<? super 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<SortedMap<K extends Comparable<? super 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<SortedMap<K extends Comparable<? super K>,V>>
-
registerByteSizeObserver
public void registerByteSizeObserver(SortedMap<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).- Overrides:
registerByteSizeObserverin classCoder<SortedMap<K extends Comparable<? super K>,V>> - Throws:
Exception
-
getEncodedTypeDescriptor
Description copied from class:CoderReturns theTypeDescriptorfor the type encoded.- Overrides:
getEncodedTypeDescriptorin classCoder<SortedMap<K extends Comparable<? super K>,V>>
-