@Experimental(value=SCHEMAS) public class SchemaCoder<T> extends CustomCoder<T>
SchemaCoder is used as the coder for types that have schemas registered.Coder.Context, Coder.NonDeterministicException| Modifier and Type | Method and Description |
|---|---|
boolean |
consistentWithEquals()
|
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. |
SerializableFunction<Row,T> |
getFromRowFunction()
Returns the toRow conversion function.
|
Schema |
getSchema()
Returns the schema associated with this type.
|
SerializableFunction<T,Row> |
getToRowFunction()
Returns the fromRow conversion function.
|
static SchemaCoder<Row> |
of(Schema schema)
Returns a
SchemaCoder for Row classes. |
static <T> SchemaCoder<T> |
of(Schema schema,
SerializableFunction<T,Row> toRowFunction,
SerializableFunction<Row,T> fromRowFunction)
Returns a
SchemaCoder for the specified class. |
java.lang.String |
toString() |
void |
verifyDeterministic()
Throw
Coder.NonDeterministicException if the coding is not deterministic. |
getCoderArgumentsdecode, encode, getEncodedElementByteSize, getEncodedTypeDescriptor, isRegisterByteSizeObserverCheap, registerByteSizeObserver, structuralValue, verifyDeterministic, verifyDeterministicpublic static <T> SchemaCoder<T> of(Schema schema, SerializableFunction<T,Row> toRowFunction, SerializableFunction<Row,T> fromRowFunction)
SchemaCoder for the specified class. If no schema is registered for this
class, then throws NoSuchSchemaException.public static SchemaCoder<Row> of(Schema schema)
SchemaCoder for Row classes.public Schema getSchema()
public SerializableFunction<Row,T> getFromRowFunction()
public SerializableFunction<T,Row> getToRowFunction()
public void encode(T value, java.io.OutputStream outStream) throws java.io.IOException
CoderT onto the given output stream.encode in class Coder<T>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>java.io.IOException - if reading from the InputStream fails for some reasonCoderException - if the value could not be decoded for some reasonpublic 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>Coder.NonDeterministicException - if this coder is not deterministic.public boolean consistentWithEquals()
Codertrue 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.
By default, returns false.
consistentWithEquals in class Coder<T>public java.lang.String toString()
toString in class java.lang.Object