Class KvCoder<K extends @Nullable Object,V extends @Nullable Object>
- 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
KvCoder
encodes KV
s.- 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 TypeMethodDescriptionboolean
decode
(InputStream inStream) Decodes a value of typeT
from the given input stream in the given context.decode
(InputStream inStream, Coder.Context context) Decodes a value of typeT
from the given input stream in the given context.void
encode
(KV<K, V> kv, OutputStream outStream) Encodes the given value of typeT
onto the given output stream.void
encode
(KV<K, V> kv, OutputStream outStream, Coder.Context context) Encodes the given value of typeT
onto the given output stream in the given context.TypeDescriptor
<KV<K, V>> Returns theTypeDescriptor
for the type encoded.boolean
Returns whether both keyCoder and valueCoder are considered not expensive.static <K,
V> KvCoder <K, V> void
registerByteSizeObserver
(KV<K, V> kv, org.apache.beam.sdk.util.common.ElementByteSizeObserver observer) Notifies ElementByteSizeObserver about the byte size of the encoded value using this coder.structuralValue
(KV<K, V> kv) Returns an object with anObject.equals()
method that represents structural equality on the argument.void
ThrowCoder.NonDeterministicException
if the coding is not deterministic.Methods inherited from class org.apache.beam.sdk.coders.StructuredCoder
equals, getComponents, hashCode, toString
Methods inherited from class org.apache.beam.sdk.coders.Coder
getEncodedElementByteSize, getEncodedElementByteSizeUsingCoder, verifyDeterministic, verifyDeterministic
-
Method Details
-
of
-
getKeyCoder
-
getValueCoder
-
encode
Description copied from class:Coder
Encodes the given value of typeT
onto 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. -
encode
public void encode(KV<K, V> kv, OutputStream outStream, Coder.Context context) throws IOException, CoderExceptionDescription copied from class:Coder
Encodes the given value of typeT
onto the given output stream in the given context. -
decode
Description copied from class:Coder
Decodes a value of typeT
from 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. -
decode
public KV<K,V> decode(InputStream inStream, Coder.Context context) throws IOException, CoderException Description copied from class:Coder
Decodes a value of typeT
from the given input stream in the given context. Returns the decoded value. -
getCoderArguments
Description copied from class:Coder
-
verifyDeterministic
Description copied from class:Coder
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.
- Specified by:
verifyDeterministic
in classCoder<KV<K extends @Nullable Object,
V extends @Nullable Object>> - Throws:
Coder.NonDeterministicException
- if this coder is not deterministic.
- two values that compare as equal (via
-
consistentWithEquals
public boolean consistentWithEquals()Description copied from class:Coder
Returnstrue
if thisCoder
is 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.
-
structuralValue
Description copied from class:Coder
Returns an object with anObject.equals()
method that represents structural equality on the argument.For any two values
x
andy
of 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
null
should 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. -
isRegisterByteSizeObserverCheap
Returns whether both keyCoder and valueCoder are considered not expensive. -
registerByteSizeObserver
public void registerByteSizeObserver(KV<K, V> kv, org.apache.beam.sdk.util.common.ElementByteSizeObserver observer) throws ExceptionNotifies ElementByteSizeObserver about the byte size of the encoded value using this coder. -
getEncodedTypeDescriptor
Description copied from class:Coder
Returns theTypeDescriptor
for the type encoded.
-