@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 | Constructor and Description |
---|---|
protected |
SchemaCoder(Schema schema,
TypeDescriptor<T> typeDescriptor,
SerializableFunction<T,Row> toRowFunction,
SerializableFunction<Row,T> fromRowFunction) |
Modifier and Type | Method and Description |
---|---|
static <T> Coder<T> |
coderForFieldType(Schema.FieldType fieldType) |
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. |
boolean |
equals(@Nullable java.lang.Object o) |
TypeDescriptor<T> |
getEncodedTypeDescriptor()
Returns the
TypeDescriptor for the type encoded. |
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.
|
int |
hashCode() |
static SchemaCoder<Row> |
of(Schema schema)
|
static <T> SchemaCoder<T> |
of(Schema schema,
TypeDescriptor<T> typeDescriptor,
SerializableFunction<T,Row> toRowFunction,
SerializableFunction<Row,T> fromRowFunction)
Returns a
SchemaCoder for the specified class. |
static void |
overrideEncodingPositions(java.util.UUID uuid,
java.util.Map<java.lang.String,java.lang.Integer> encodingPositions)
Override encoding positions for the given schema.
|
java.lang.String |
toString() |
void |
verifyDeterministic()
Throw
Coder.NonDeterministicException if the coding is not deterministic. |
getCoderArguments
decode, encode, getEncodedElementByteSize, isRegisterByteSizeObserverCheap, registerByteSizeObserver, structuralValue, verifyDeterministic, verifyDeterministic
protected final Schema schema
protected SchemaCoder(Schema schema, TypeDescriptor<T> typeDescriptor, SerializableFunction<T,Row> toRowFunction, SerializableFunction<Row,T> fromRowFunction)
public static <T> SchemaCoder<T> of(Schema schema, TypeDescriptor<T> typeDescriptor, SerializableFunction<T,Row> toRowFunction, SerializableFunction<Row,T> fromRowFunction)
SchemaCoder
for the specified class. If no schema is registered for this
class, then throws NoSuchSchemaException
. The parameter functions to convert from and
to Rows must implement the equals contract.public static SchemaCoder<Row> of(Schema schema)
public static void overrideEncodingPositions(java.util.UUID uuid, java.util.Map<java.lang.String,java.lang.Integer> encodingPositions)
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
Coder
T
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
Coder
T
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
CustomCoder
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.
verifyDeterministic
in class CustomCoder<T>
Coder.NonDeterministicException
- if this coder is not deterministic.public boolean consistentWithEquals()
Coder
true
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 static <T> Coder<T> coderForFieldType(Schema.FieldType fieldType)
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(@Nullable java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public TypeDescriptor<T> getEncodedTypeDescriptor()
Coder
TypeDescriptor
for the type encoded.getEncodedTypeDescriptor
in class Coder<T>