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 StandardCoder<KV<K,V>>
KvCoder encodes KVs.Coder.Context, Coder.NonDeterministicException| Modifier and Type | Method and Description |
|---|---|
org.apache.beam.sdk.util.CloudObject |
asCloudObject()
Returns the
CloudObject that represents this Coder. |
boolean |
consistentWithEquals()
|
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,
org.apache.beam.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. |
equals, getAllowedEncodings, getComponents, getEncodedElementByteSize, getEncodingId, 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()
StandardCodertrue if this Coder is injective with respect to Object.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 for null.
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.
consistentWithEquals in interface Coder<KV<K,V>>consistentWithEquals in class StandardCoder<KV<K,V>>false for StandardCoder unless overridden.public Object structuralValue(KV<K,V> kv) throws Exception
CoderObject.equals() method that represents structural equality
on the argument.
For any two values x and y of type T, if their encoded bytes are the
same, then it must be the case that structuralValue(x).equals(@code structuralValue(y).
Most notably:
null should be a proper object with
an equals() method, even if the input value is null.
See also Coder.consistentWithEquals().
structuralValue in interface Coder<KV<K,V>>structuralValue in class StandardCoder<KV<K,V>>Exceptionpublic org.apache.beam.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>>false unless it is overridden. StandardCoder.registerByteSizeObserver(T, org.apache.beam.sdk.util.common.ElementByteSizeObserver, org.apache.beam.sdk.coders.Coder.Context)
invokes StandardCoder.getEncodedElementByteSize(T, org.apache.beam.sdk.coders.Coder.Context) which requires re-encoding an element
unless it is overridden. This is considered expensive.public void registerByteSizeObserver(KV<K,V> kv, org.apache.beam.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