T
- the type to be serializedpublic class AvroSerializationSchema<T> extends Object implements SerializationSchema<T>
SerializationSchema.InitializationContext
Modifier | Constructor and Description |
---|---|
protected |
AvroSerializationSchema(Class<T> recordClazz,
org.apache.avro.Schema schema)
Creates an Avro deserialization schema.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkAvroInitialized() |
boolean |
equals(Object o) |
static AvroSerializationSchema<org.apache.avro.generic.GenericRecord> |
forGeneric(org.apache.avro.Schema schema)
Creates
AvroSerializationSchema that serializes GenericRecord using provided
schema. |
static <T extends org.apache.avro.specific.SpecificRecord> |
forSpecific(Class<T> tClass)
Creates
AvroSerializationSchema that serializes SpecificRecord using provided
schema. |
protected org.apache.avro.generic.GenericDatumWriter<T> |
getDatumWriter() |
protected org.apache.avro.io.BinaryEncoder |
getEncoder() |
protected ByteArrayOutputStream |
getOutputStream() |
org.apache.avro.Schema |
getSchema() |
int |
hashCode() |
void |
open(SerializationSchema.InitializationContext context)
Initialization method for the schema.
|
byte[] |
serialize(T object)
Serializes the incoming element to a specified type.
|
protected AvroSerializationSchema(Class<T> recordClazz, @Nullable org.apache.avro.Schema schema)
recordClazz
- class to serialize. Should be one of: SpecificRecord
, GenericRecord
.schema
- writer Avro schema. Should be provided if recordClazz is GenericRecord
public static <T extends org.apache.avro.specific.SpecificRecord> AvroSerializationSchema<T> forSpecific(Class<T> tClass)
AvroSerializationSchema
that serializes SpecificRecord
using provided
schema.tClass
- the type to be serializedpublic static AvroSerializationSchema<org.apache.avro.generic.GenericRecord> forGeneric(org.apache.avro.Schema schema)
AvroSerializationSchema
that serializes GenericRecord
using provided
schema.schema
- the schema that will be used for serializationpublic org.apache.avro.Schema getSchema()
protected org.apache.avro.io.BinaryEncoder getEncoder()
protected org.apache.avro.generic.GenericDatumWriter<T> getDatumWriter()
protected ByteArrayOutputStream getOutputStream()
public void open(SerializationSchema.InitializationContext context) throws Exception
SerializationSchema
SerializationSchema.serialize(Object)
and thus suitable for one time setup work.
The provided SerializationSchema.InitializationContext
can be used to access additional features such
as e.g. registering user metrics.
open
in interface SerializationSchema<T>
context
- Contextual information that can be used during initialization.Exception
public byte[] serialize(T object)
SerializationSchema
serialize
in interface SerializationSchema<T>
object
- The incoming element to be serializedprotected void checkAvroInitialized()
Copyright © 2014–2023 The Apache Software Foundation. All rights reserved.