T - the type of elements handled by this coder.public class WritableCoder<T extends org.apache.hadoop.io.Writable> extends CustomCoder<T>
WritableCoder is a Coder for a Java class that implements Writable.
To use, specify the coder type on a PCollection:
PCollection<MyRecord> records =
foo.apply(...).setCoder(WritableCoder.of(MyRecord.class));
| Modifier and Type | Class and Description |
|---|---|
static class |
WritableCoder.WritableCoderProviderRegistrar
|
Coder.Context, Coder.NonDeterministicException| Constructor and Description |
|---|
WritableCoder(java.lang.Class<T> type) |
| Modifier and Type | Method and Description |
|---|---|
T |
decode(java.io.InputStream inStream)
Decodes a value of type
T from the given input stream in the given context. |
void |
encode(T value,
java.io.OutputStream outStream)
Encodes the given value of type
T onto the given output stream. |
boolean |
equals(java.lang.Object other) |
java.util.List<Coder<?>> |
getCoderArguments()
|
static CoderProvider |
getCoderProvider()
|
int |
hashCode() |
static <T extends org.apache.hadoop.io.Writable> |
of(java.lang.Class<T> clazz)
Returns a
WritableCoder instance for the provided element class. |
void |
verifyDeterministic()
Throw
Coder.NonDeterministicException if the coding is not deterministic. |
consistentWithEquals, decode, encode, getEncodedElementByteSize, getEncodedTypeDescriptor, isRegisterByteSizeObserverCheap, registerByteSizeObserver, structuralValue, verifyDeterministic, verifyDeterministicpublic WritableCoder(java.lang.Class<T> type)
public static <T extends org.apache.hadoop.io.Writable> WritableCoder<T> of(java.lang.Class<T> clazz)
WritableCoder instance for the provided element class.T - the element typepublic void encode(T value, java.io.OutputStream outStream) throws java.io.IOException
CoderT onto the given output stream.encode in class Coder<T extends org.apache.hadoop.io.Writable>java.io.IOException - if writing to the OutputStream fails for some reasonCoderException - if the value could not be encoded for some reasonpublic T decode(java.io.InputStream inStream) throws java.io.IOException
CoderT from the given input stream in the given context. Returns the
decoded value.decode in class Coder<T extends org.apache.hadoop.io.Writable>java.io.IOException - if reading from the InputStream fails for some reasonCoderException - if the value could not be decoded for some reasonpublic java.util.List<Coder<?>> getCoderArguments()
CustomCoderCoder for a parameterized type, returns the list of Coders being
used for each of the parameters in the same order they appear within the parameterized type's
type signature. If this cannot be done, or this Coder does not encode/decode a
parameterized type, returns the empty list..
Returns an empty list. A CustomCoder has no default argument coders.
getCoderArguments in class CustomCoder<T extends org.apache.hadoop.io.Writable>public void verifyDeterministic()
throws Coder.NonDeterministicException
CustomCoderCoder.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.
verifyDeterministic in class CustomCoder<T extends org.apache.hadoop.io.Writable>Coder.NonDeterministicException - if this coder is not deterministic.public boolean equals(java.lang.Object other)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic static CoderProvider getCoderProvider()
CoderProvider which uses the WritableCoder for Hadoop writable types.
This method is invoked reflectively from DefaultCoder.