Package org.apache.avro.generic
Class GenericDatumReader<D>
java.lang.Object
org.apache.avro.generic.GenericDatumReader<D>
- All Implemented Interfaces:
DatumReader<D>
- Direct Known Subclasses:
ProtobufDatumReader,SpecificDatumReader,ThriftDatumReader
DatumReader for generic Java objects.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedGenericDatumReader(Schema schema) Construct where the writer's and reader's schemas are the same.GenericDatumReader(Schema writer, Schema reader) Construct given writer's and reader's schema.GenericDatumReader(Schema writer, Schema reader, GenericData data) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddToArray(Object array, long pos, Object e) Called by the default implementation ofreadArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)to add a value.protected voidCalled by the default implementation ofreadMap(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)to add a key/value pair.protected Objectconvert(Object datum, Schema schema, LogicalType type, Conversion<?> conversion) Convert an underlying representation of a logical type (such as a ByteBuffer) to a higher level object (such as a BigDecimal).protected ObjectcreateBytes(byte[] value) Called to create byte arrays from default values.protected ObjectcreateEnum(String symbol, Schema schema) Called to create an enum value.protected ObjectcreateFixed(Object old, byte[] bytes, Schema schema) Deprecated.protected ObjectcreateFixed(Object old, Schema schema) Deprecated.As of Avro 1.6.0 this method has been moved toGenericData.createFixed(Object, Schema)protected ObjectcreateString(String value) Called to create a string from a default value.protected ClassfindStringClass(Schema schema) Determines the class to used to represent a string Schema.getData()Return theGenericDataimplementation.Get the reader's schema.protected final ResolvingDecodergetResolver(Schema actual, Schema expected) Gets a resolving decoder for use by this GenericDatumReader.Return the writer's schema.protected ObjectCalled to create new array instances.protected ObjectnewInstanceFromString(Class c, String s) protected ObjectCalled to create new array instances.protected ObjectDeprecated.As of Avro 1.6.0 this method has been moved toGenericData.newRecord(Object, Schema)protected ObjectCalled by the default implementation ofreadArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)to retrieve a value from a reused instance.Read a datum.protected Objectread(Object old, Schema expected, ResolvingDecoder in) Called to read data.protected ObjectreadArray(Object old, Schema expected, ResolvingDecoder in) Called to read an array instance.protected ObjectCalled to read byte arrays.protected ObjectCalled to read byte arrays.protected ObjectCalled to read an enum value.protected voidreadField(Object record, Schema.Field field, Object oldDatum, ResolvingDecoder in, Object state) Called to read a single field of a record.protected ObjectCalled to read a fixed value.protected ObjectCalled to read integers.protected ObjectreadMap(Object old, Schema expected, ResolvingDecoder in) Called to read a map instance.protected ObjectreadMapKey(Object old, Schema expected, Decoder in) Called by the default implementation ofreadMap(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)to read a key value.protected ObjectreadRecord(Object old, Schema expected, ResolvingDecoder in) Called to read a record instance.protected ObjectreadString(Object old, Decoder in) Called to read strings.protected ObjectreadString(Object old, Schema expected, Decoder in) Called to read strings.protected ObjectreadWithConversion(Object old, Schema expected, LogicalType logicalType, Conversion<?> conversion, ResolvingDecoder in) protected ObjectreadWithoutConversion(Object old, Schema expected, ResolvingDecoder in) voidsetExpected(Schema reader) Set the reader's schema.voidSet the writer's schema.static voidSkip an instance of a schema.
-
Constructor Details
-
GenericDatumReader
public GenericDatumReader() -
GenericDatumReader
Construct where the writer's and reader's schemas are the same. -
GenericDatumReader
Construct given writer's and reader's schema. -
GenericDatumReader
-
GenericDatumReader
-
-
Method Details
-
getData
Return theGenericDataimplementation. -
getSchema
Return the writer's schema. -
setSchema
Description copied from interface:DatumReaderSet the writer's schema.- Specified by:
setSchemain interfaceDatumReader<D>
-
getExpected
Get the reader's schema. -
setExpected
Set the reader's schema. -
getResolver
Gets a resolving decoder for use by this GenericDatumReader. Unstable API. Currently uses a thread local cache to prevent constructing the resolvers too often, because that is very expensive.- Throws:
IOException
-
read
Description copied from interface:DatumReaderRead a datum. Traverse the schema, depth-first, reading all leaf values in the schema into a datum that is returned. If the provided datum is non-null it may be reused and returned.- Specified by:
readin interfaceDatumReader<D>- Throws:
IOException
-
read
Called to read data.- Throws:
IOException
-
readWithConversion
protected Object readWithConversion(Object old, Schema expected, LogicalType logicalType, Conversion<?> conversion, ResolvingDecoder in) throws IOException - Throws:
IOException
-
readWithoutConversion
protected Object readWithoutConversion(Object old, Schema expected, ResolvingDecoder in) throws IOException - Throws:
IOException
-
convert
Convert an underlying representation of a logical type (such as a ByteBuffer) to a higher level object (such as a BigDecimal).- Throws:
IllegalArgumentException- if a null schema or logicalType is passed in while datum and conversion are not null. Please be noticed that the exception type has changed. With version 1.8.0 and earlier, in above circumstance, the exception thrown out depends on the implementation of conversion (most likely a NullPointerException). Now, an IllegalArgumentException will be thrown out instead.
-
readRecord
Called to read a record instance. May be overridden for alternate record representations.- Throws:
IOException
-
readField
protected void readField(Object record, Schema.Field field, Object oldDatum, ResolvingDecoder in, Object state) throws IOException Called to read a single field of a record. May be overridden for more efficient or alternate implementations.- Throws:
IOException
-
readEnum
Called to read an enum value. May be overridden for alternate enum representations. By default, returns a GenericEnumSymbol.- Throws:
IOException
-
createEnum
Called to create an enum value. May be overridden for alternate enum representations. By default, returns a GenericEnumSymbol. -
readArray
Called to read an array instance. May be overridden for alternate array representations.- Throws:
IOException
-
peekArray
Called by the default implementation ofreadArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)to retrieve a value from a reused instance. The default implementation is forGenericArray. -
addToArray
Called by the default implementation ofreadArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)to add a value. The default implementation is forCollection. -
readMap
Called to read a map instance. May be overridden for alternate map representations.- Throws:
IOException
-
readMapKey
Called by the default implementation ofreadMap(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)to read a key value. The default implementation returns delegates toreadString(Object, org.apache.avro.io.Decoder).- Throws:
IOException
-
addToMap
Called by the default implementation ofreadMap(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)to add a key/value pair. The default implementation is forMap. -
readFixed
Called to read a fixed value. May be overridden for alternate fixed representations. By default, returnsGenericFixed.- Throws:
IOException
-
createFixed
Deprecated.As of Avro 1.6.0 this method has been moved toGenericData.createFixed(Object, Schema)Called to create an fixed value. May be overridden for alternate fixed representations. By default, returnsGenericFixed. -
createFixed
Deprecated.As of Avro 1.6.0 this method has been moved toGenericData.createFixed(Object, byte[], Schema)Called to create an fixed value. May be overridden for alternate fixed representations. By default, returnsGenericFixed. -
newRecord
Deprecated.As of Avro 1.6.0 this method has been moved toGenericData.newRecord(Object, Schema)Called to create new record instances. Subclasses may override to use a different record implementation. The returned instance must conform to the schema provided. If the old object contains fields not present in the schema, they should either be removed from the old object, or it should create a new instance that conforms to the schema. By default, this returns aGenericData.Record. -
newArray
Called to create new array instances. Subclasses may override to use a different array implementation. By default, this returns aGenericData.Array. -
newMap
Called to create new array instances. Subclasses may override to use a different map implementation. By default, this returns aHashMap. -
readString
Called to read strings. Subclasses may override to use a different string representation. By default, this callsreadString(Object,Decoder).- Throws:
IOException
-
readString
Called to read strings. Subclasses may override to use a different string representation. By default, this callsDecoder.readString(Utf8).- Throws:
IOException
-
createString
Called to create a string from a default value. Subclasses may override to use a different string representation. By default, this callsUtf8(String). -
findStringClass
Determines the class to used to represent a string Schema. By default usesGenericData.STRING_PROPto determine whetherUtf8orStringis used. Subclasses may override for alternate representations. -
newInstanceFromString
-
readBytes
Called to read byte arrays. Subclasses may override to use a different byte array representation. By default, this callsDecoder.readBytes(ByteBuffer).- Throws:
IOException
-
readBytes
Called to read byte arrays. Subclasses may override to use a different byte array representation. By default, this callsDecoder.readBytes(ByteBuffer).- Throws:
IOException
-
readInt
Called to read integers. Subclasses may override to use a different integer representation. By default, this callsDecoder.readInt().- Throws:
IOException
-
createBytes
Called to create byte arrays from default values. Subclasses may override to use a different byte array representation. By default, this callsByteBuffer.wrap(byte[]). -
skip
Skip an instance of a schema.- Throws:
IOException
-
GenericData.createFixed(Object, byte[], Schema)