T - the type of the elements of the Iterables being transcodedIterableT - the type of the Iterables being transcodedpublic abstract class IterableLikeCoder<T,IterableT extends Iterable<T>> extends StandardCoder<IterableT>
Coder for a class that implements Iterable.
To complete a subclass, implement the decodeToIterable(java.util.List<T>) method. This superclass
will decode the elements in the input stream into a List and then pass them to that
method to be converted into the appropriate iterable type. Note that this means the input
iterables must fit into memory.
The format of this coder is as follows:
Iterable has a known and finite size, then the size is written to the
output stream in big endian format, followed by all of the encoded elements.Iterable is not known to have a finite size, then each element
of the input is preceded by true encoded as a byte (indicating "more data")
followed by the encoded element, and terminated by false encoded as a byte.Coder.Context, Coder.NonDeterministicException| Modifier | Constructor and Description |
|---|---|
protected |
IterableLikeCoder(Coder<T> elementCoder,
String iterableName) |
| Modifier and Type | Method and Description |
|---|---|
IterableT |
decode(InputStream inStream,
Coder.Context context)
Decodes a value of type
T from the given input stream in
the given context. |
protected abstract IterableT |
decodeToIterable(List<T> decodedElements)
Builds an instance of
IterableT, this coder's associated Iterable-like
subtype, from a list of decoded elements. |
void |
encode(IterableT iterable,
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. |
Coder<T> |
getElemCoder() |
protected static <T,IterableT extends Iterable<T>> |
getInstanceComponentsHelper(IterableT exampleValue)
Returns the first element in the iterable-like
exampleValue if it is non-empty,
otherwise returns null. |
boolean |
isRegisterByteSizeObserverCheap(IterableT iterable,
Coder.Context context)
Returns whether
Coder.registerByteSizeObserver(T, org.apache.beam.sdk.util.common.ElementByteSizeObserver, org.apache.beam.sdk.coders.Coder.Context) cheap enough to
call for every element, that is, if this Coder can
calculate the byte size of the element to be coded in roughly
constant time (or lazily). |
void |
registerByteSizeObserver(IterableT iterable,
org.apache.beam.sdk.util.common.ElementByteSizeObserver observer,
Coder.Context context)
Notifies the
ElementByteSizeObserver about the byte size
of the encoded value using this Coder. |
void |
verifyDeterministic()
Throw
Coder.NonDeterministicException if the coding is not deterministic. |
asCloudObject, consistentWithEquals, equals, getAllowedEncodings, getComponents, getEncodedElementByteSize, getEncodingId, hashCode, structuralValue, toString, verifyDeterministic, verifyDeterministicprotected abstract IterableT decodeToIterable(List<T> decodedElements)
IterableT, this coder's associated Iterable-like
subtype, from a list of decoded elements.protected static <T,IterableT extends Iterable<T>> List<Object> getInstanceComponentsHelper(IterableT exampleValue)
exampleValue if it is non-empty,
otherwise returns null.public void encode(IterableT iterable, 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 IterableT 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
Coder.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.
NonDeterministicException - always.
Encoding is not deterministic for the general Iterable case, as it depends
upon the type of iterable. This may allow two objects to compare as equal
while the encoding differs.Coder.NonDeterministicException - if this coder is not deterministic.public boolean isRegisterByteSizeObserverCheap(IterableT iterable, Coder.Context context)
Coder.registerByteSizeObserver(T, org.apache.beam.sdk.util.common.ElementByteSizeObserver, org.apache.beam.sdk.coders.Coder.Context) cheap enough to
call for every element, that is, if this Coder can
calculate the byte size of the element to be coded in roughly
constant time (or lazily).
Not intended to be called by user code, but instead by
PipelineRunner
implementations.
isRegisterByteSizeObserverCheap in interface Coder<IterableT extends Iterable<T>>isRegisterByteSizeObserverCheap in class StandardCoder<IterableT extends Iterable<T>>true if the iterable is of a known class that supports lazy counting
of byte size, since that requires minimal extra computation.public void registerByteSizeObserver(IterableT iterable, org.apache.beam.sdk.util.common.ElementByteSizeObserver observer, Coder.Context context) throws Exception
StandardCoderElementByteSizeObserver about the byte size
of the encoded value using this Coder.
Not intended to be called by user code, but instead by
PipelineRunner
implementations.
For StandardCoder subclasses, this notifies observer about the byte size
of the encoded value using this coder as returned by StandardCoder.getEncodedElementByteSize(T, org.apache.beam.sdk.coders.Coder.Context).
registerByteSizeObserver in interface Coder<IterableT extends Iterable<T>>registerByteSizeObserver in class StandardCoder<IterableT extends Iterable<T>>Exception