T
- The type created by the deserialization schema.@PublicEvolving public abstract class AbstractDeserializationSchema<T> extends Object implements DeserializationSchema<T>
This base variant of the deserialization schema produces the type information automatically by extracting it from the generic class arguments.
To write a deserialization schema for a specific type, simply extend this class and declare the type in the class signature. Flink will reflectively determine the type and create the proper TypeInformation:
public class MyDeserializationSchema extends AbstractDeserializationSchema<MyType> {
public MyType deserialize(byte[] message) throws IOException {
...
}
}
If you want to write a more generic DeserializationSchema that works for different types, you need to pass the TypeInformation (or an equivalent hint) to the constructor:
public class MyGenericSchema<T> extends AbstractDeserializationSchema<T> {
public MyGenericSchema(Class<T> type) {
super(type);
}
public T deserialize(byte[] message) throws IOException {
...
}
}
DeserializationSchema.InitializationContext
Modifier | Constructor and Description |
---|---|
protected |
AbstractDeserializationSchema()
Creates a new AbstractDeserializationSchema and tries to infer the type returned by this
DeserializationSchema.
|
protected |
AbstractDeserializationSchema(Class<T> type)
Creates an AbstractDeserializationSchema that returns the TypeInformation indicated by the
given class.
|
protected |
AbstractDeserializationSchema(TypeHint<T> typeHint)
Creates an AbstractDeserializationSchema that returns the TypeInformation indicated by the
given type hint.
|
protected |
AbstractDeserializationSchema(TypeInformation<T> typeInfo)
Creates an AbstractDeserializationSchema that returns the given TypeInformation for the
produced type.
|
Modifier and Type | Method and Description |
---|---|
abstract T |
deserialize(byte[] message)
De-serializes the byte message.
|
TypeInformation<T> |
getProducedType()
Gets the type produced by this deserializer.
|
boolean |
isEndOfStream(T nextElement)
Method to decide whether the element signals the end of the stream.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
deserialize, open
protected AbstractDeserializationSchema()
This constructor is usable whenever the DeserializationSchema concretely defines its type, without generic variables:
public class MyDeserializationSchema extends AbstractDeserializationSchema<MyType> {
public MyType deserialize(byte[] message) throws IOException {
...
}
}
protected AbstractDeserializationSchema(Class<T> type)
Generic Use
.
This constructor may fail if the class is generic. In that case, please use the
constructor that accepts a TypeHint
, or a
TypeInformation
.
type
- The class of the produced type.protected AbstractDeserializationSchema(TypeHint<T> typeHint)
Generic Use
.typeHint
- The TypeHint for the produced type.protected AbstractDeserializationSchema(TypeInformation<T> typeInfo)
Generic Use
.typeInfo
- The TypeInformation for the produced type.public abstract T deserialize(byte[] message) throws IOException
deserialize
in interface DeserializationSchema<T>
message
- The message, as a byte array.IOException
public boolean isEndOfStream(T nextElement)
This default implementation returns always false, meaning the stream is interpreted to be unbounded.
isEndOfStream
in interface DeserializationSchema<T>
nextElement
- The element to test for the end-of-stream signal.public TypeInformation<T> getProducedType()
getProducedType
in interface ResultTypeQueryable<T>
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.