K - the type of the keys of the KVs being transcodedV - the type of the values of the KVs being transcodedpublic class KvCoder<K,V> extends KvCoderBase<KV<K,V>>
KvCoder encodes KVs.Coder.Context, Coder.NonDeterministicException| Modifier and Type | Method and Description |
|---|---|
com.google.cloud.dataflow.sdk.util.CloudObject |
asCloudObject()
Returns the
CloudObject that represents this Coder. |
boolean |
consistentWithEquals()
Returns true if the encoded bytes of two objects are
equal only when they are also equal according to
Object.equals(). |
KV<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(KV<K,V> kv,
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(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 an
Object.equals() method
that represents structural equality on the argument. |
void |
verifyDeterministic()
Throw
Coder.NonDeterministicException if the coding is not deterministic. |
ofequals, getComponents, getEncodedElementByteSize, hashCode, toString, verifyDeterministic, verifyDeterministicpublic void encode(KV<K,V> kv, 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 KV<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()
CoderCoder 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.public void verifyDeterministic()
throws Coder.NonDeterministicException
CoderCoder.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.
Coder.NonDeterministicException - if this coder is not deterministic.public boolean consistentWithEquals()
CoderObject.equals().
(and also implements a compatible Object.hasCode())
This most notably false for arrays. It will generally
be false when Object.equals() compares object identity,
rather than performing a semantic/structural comparison.
consistentWithEquals in interface Coder<KV<K,V>>consistentWithEquals in class StandardCoder<KV<K,V>>public Object structuralValue(KV<K,V> kv) throws Exception
CoderObject.equals() method
that represents structural equality on the argument.
(and also implements a compatible Object.hashCode()).
For any two objects of type T, if their encoded bytes
are the same, then their structural values are equal
according to Object.equals().
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.
See also Coder.consistentWithEquals().
structuralValue in interface Coder<KV<K,V>>structuralValue in class StandardCoder<KV<K,V>>Exceptionpublic com.google.cloud.dataflow.sdk.util.CloudObject asCloudObject()
CoderCloudObject that represents this Coder.asCloudObject in interface Coder<KV<K,V>>asCloudObject in class StandardCoder<KV<K,V>>public boolean isRegisterByteSizeObserverCheap(KV<K,V> kv, Coder.Context context)
isRegisterByteSizeObserverCheap in interface Coder<KV<K,V>>isRegisterByteSizeObserverCheap in class StandardCoder<KV<K,V>>public void registerByteSizeObserver(KV<K,V> kv, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver observer, Coder.Context context) throws Exception
registerByteSizeObserver in interface Coder<KV<K,V>>registerByteSizeObserver in class StandardCoder<KV<K,V>>Exception