Google Cloud Dataflow SDK for Java, version 1.9.1
Class KvCoder<K,V>
- java.lang.Object
-
- com.google.cloud.dataflow.sdk.coders.StandardCoder<T>
-
- com.google.cloud.dataflow.sdk.coders.KvCoderBase<KV<K,V>>
-
- com.google.cloud.dataflow.sdk.coders.KvCoder<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<KV<K,V>>, Serializable
public class KvCoder<K,V> extends KvCoderBase<KV<K,V>>
AKvCoder
encodesKV
s.- 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 com.google.cloud.dataflow.sdk.util.CloudObject
asCloudObject()
Returns theCloudObject
that represents thisCoder
.boolean
consistentWithEquals()
KV<K,V>
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, 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(KV<K,V> exampleValue)
Coder<K>
getKeyCoder()
Coder<V>
getValueCoder()
boolean
isRegisterByteSizeObserverCheap(KV<K,V> kv, Coder.Context context)
Returns whether both keyCoder and valueCoder are considered not expensive.static <K,V> KvCoder<K,V>
of(Coder<K> keyCoder, Coder<V> valueCoder)
static KvCoder<?,?>
of(List<Coder<?>> components)
void
registerByteSizeObserver(KV<K,V> kv, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver observer, Coder.Context context)
Notifies ElementByteSizeObserver about the byte size of the encoded value using this coder.Object
structuralValue(KV<K,V> kv)
Returns an object with anObject.equals()
method that represents structural equality on the argument.void
verifyDeterministic()
ThrowCoder.NonDeterministicException
if the coding is not deterministic.-
Methods inherited from class com.google.cloud.dataflow.sdk.coders.KvCoderBase
of
-
Methods inherited from class com.google.cloud.dataflow.sdk.coders.StandardCoder
equals, getAllowedEncodings, getComponents, getEncodedElementByteSize, getEncodingId, hashCode, toString, verifyDeterministic, verifyDeterministic
-
-
-
-
Method Detail
-
encode
public void encode(KV<K,V> kv, 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 KV<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()
Description copied from interface:Coder
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.
-
verifyDeterministic
public void verifyDeterministic() throws Coder.NonDeterministicException
Description copied from interface: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.
- Throws:
Coder.NonDeterministicException
- if this coder is not deterministic.
- two values that compare as equal (via
-
consistentWithEquals
public boolean consistentWithEquals()
Description copied from class:StandardCoder
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.- Specified by:
consistentWithEquals
in interfaceCoder<KV<K,V>>
- Overrides:
consistentWithEquals
in classStandardCoder<KV<K,V>>
- Returns:
false
forStandardCoder
unless overridden.
-
structuralValue
public Object structuralValue(KV<K,V> kv) throws Exception
Description copied from interface: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(@code 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()
.- Specified by:
structuralValue
in interfaceCoder<KV<K,V>>
- Overrides:
structuralValue
in classStandardCoder<KV<K,V>>
- Throws:
Exception
-
asCloudObject
public com.google.cloud.dataflow.sdk.util.CloudObject asCloudObject()
Description copied from interface:Coder
Returns theCloudObject
that represents thisCoder
.- Specified by:
asCloudObject
in interfaceCoder<KV<K,V>>
- Overrides:
asCloudObject
in classStandardCoder<KV<K,V>>
-
isRegisterByteSizeObserverCheap
public boolean isRegisterByteSizeObserverCheap(KV<K,V> kv, Coder.Context context)
Returns whether both keyCoder and valueCoder are considered not expensive.- Specified by:
isRegisterByteSizeObserverCheap
in interfaceCoder<KV<K,V>>
- Overrides:
isRegisterByteSizeObserverCheap
in classStandardCoder<KV<K,V>>
- Returns:
false
unless it is overridden.StandardCoder.registerByteSizeObserver(T, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver, com.google.cloud.dataflow.sdk.coders.Coder.Context)
invokesStandardCoder.getEncodedElementByteSize(T, com.google.cloud.dataflow.sdk.coders.Coder.Context)
which requires re-encoding an element unless it is overridden. This is considered expensive.
-
registerByteSizeObserver
public void registerByteSizeObserver(KV<K,V> kv, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver observer, Coder.Context context) throws Exception
Notifies ElementByteSizeObserver about the byte size of the encoded value using this coder.- Specified by:
registerByteSizeObserver
in interfaceCoder<KV<K,V>>
- Overrides:
registerByteSizeObserver
in classStandardCoder<KV<K,V>>
- Throws:
Exception
-
-