Google Cloud Dataflow SDK for Java, version 1.9.1
com.google.cloud.dataflow.sdk.transforms.join
Class UnionCoder
- java.lang.Object
-
- com.google.cloud.dataflow.sdk.coders.StandardCoder<RawUnionValue>
-
- com.google.cloud.dataflow.sdk.transforms.join.UnionCoder
-
- All Implemented Interfaces:
- Coder<RawUnionValue>, Serializable
public class UnionCoder extends StandardCoder<RawUnionValue>
A UnionCoder encodes RawUnionValues.- 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 RawUnionValue
decode(InputStream inStream, Coder.Context context)
Decodes a value of typeT
from the given input stream in the given context.void
encode(RawUnionValue union, 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.List<? extends Coder<?>>
getComponents()
boolean
isRegisterByteSizeObserverCheap(RawUnionValue union, Coder.Context context)
Since this coder uses elementCoders.get(index) and coders that are known to run in constant time, we defer the return value to that coder.static UnionCoder
jsonOf(List<Coder<?>> elements)
static UnionCoder
of(List<Coder<?>> elementCoders)
Builds a union coder with the given list of element coders.void
registerByteSizeObserver(RawUnionValue union, 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.void
verifyDeterministic()
ThrowCoder.NonDeterministicException
if the coding is not deterministic.-
Methods inherited from class com.google.cloud.dataflow.sdk.coders.StandardCoder
asCloudObject, consistentWithEquals, equals, getAllowedEncodings, getEncodedElementByteSize, getEncodingId, hashCode, structuralValue, toString, verifyDeterministic, verifyDeterministic
-
-
-
-
Method Detail
-
of
public static UnionCoder of(List<Coder<?>> elementCoders)
Builds a union coder with the given list of element coders. This list corresponds to a mapping of union tag to Coder. Union tags start at 0.
-
jsonOf
public static UnionCoder jsonOf(List<Coder<?>> elements)
-
encode
public void encode(RawUnionValue union, 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 RawUnionValue 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.
-
getComponents
public List<? extends Coder<?>> getComponents()
Description copied from class:StandardCoder
- Overrides:
getComponents
in classStandardCoder<RawUnionValue>
-
isRegisterByteSizeObserverCheap
public boolean isRegisterByteSizeObserverCheap(RawUnionValue union, Coder.Context context)
Since this coder uses elementCoders.get(index) and coders that are known to run in constant time, we defer the return value to that coder.- Specified by:
isRegisterByteSizeObserverCheap
in interfaceCoder<RawUnionValue>
- Overrides:
isRegisterByteSizeObserverCheap
in classStandardCoder<RawUnionValue>
- 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(RawUnionValue union, 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<RawUnionValue>
- Overrides:
registerByteSizeObserver
in classStandardCoder<RawUnionValue>
- Throws:
Exception
-
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
-
-