Top Description Inners Fields Constructors Methods
org.apache.avro.generic

public Class GenericDatumReader<D>

extends Object
implements DatumReader<D>
Class Inheritance
All Implemented Interfaces
org.apache.avro.io.DatumReader
Known Direct Subclasses
org.apache.avro.specific.SpecificDatumReader
Imports
java.io.IOException, java.lang.reflect.Constructor, java.nio.ByteBuffer, java.util.Collection, .HashMap, .Map, java.util.concurrent.ConcurrentHashMap, java.util.function.Function, org.apache.avro.AvroRuntimeException, .Conversion, .Conversions, .LogicalType, .Schema, .Schema.Field, org.apache.avro.io.DatumReader, .Decoder, .DecoderFactory, .ResolvingDecoder, org.apache.avro.util.Utf8, .WeakIdentityHashMap, org.apache.avro.util.internal.ThreadLocalWithInitial

DatumReader for generic Java objects.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
GenericDatumReader.IdentitySchemaKey

This class is used to reproduce part of IdentityHashMap in ConcurrentHashMap code.

pack-priv static class

Field Summary

Modifier and TypeField and Description
private Schema
private final Thread
private ResolvingDecoder
private final GenericData
private Schema
private DatumReader<D>
private final GenericDatumReader.ReaderCache
private static final ThreadLocal<Map<Schema, Map<Schema, ResolvingDecoder>>>

Constructor Summary

AccessConstructor and Description
public
public
GenericDatumReader(Schema schema)

Construct where the writer's and reader's schemas are the same.

public
GenericDatumReader(Schema writer, Schema reader)

Construct given writer's and reader's schema.

public
protected

Method Summary

Modifier and TypeMethod and Description
protected void
addToArray(Object array, long pos, Object e)

Called by the default implementation of readArray to add a value.

protected void
addToMap(Object map, Object key, Object value)

Called by the default implementation of readMap to add a key/value pair.

protected Object
convert(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 Object
createBytes(byte[] value)

Called to create byte arrays from default values.

protected Object
createEnum(String symbol, Schema schema)

Called to create an enum value.

protected Object
createFixed(Object old, Schema schema)

Deprecated As of Avro 1.6.0 this method has been moved to GenericData#createFixed(Object, Schema)
Called to create an fixed value.
protected Object
createFixed(Object old, byte[] bytes, Schema schema)

Deprecated As of Avro 1.6.0 this method has been moved to GenericData#createFixed(Object, byte[], Schema)
Called to create an fixed value.
protected Object
createString(String value)

Called to create a string from a default value.

protected Class<T>
findStringClass(Schema schema)

Determines the class to used to represent a string Schema.

public GenericData
getData()

Return the GenericData implementation.

public Schema
getExpected()

Get the reader's schema.

pack-priv GenericDatumReader.ReaderCache
protected final ResolvingDecoder
getResolver(Schema actual, Schema expected)

Gets a resolving decoder for use by this GenericDatumReader.

public Schema
getSchema()

Return the writer's schema.

protected Object
newArray(Object old, int size, Schema schema)

Called to create new array instances.

protected Object
protected Object
newMap(Object old, int size)

Called to create new array instances.

protected Object
newRecord(Object old, Schema schema)

Deprecated As of Avro 1.6.0 this method has been moved to GenericData#newRecord(Object, Schema)
Called to create new record instances.
protected Object
peekArray(Object array)

Called by the default implementation of readArray to retrieve a value from a reused instance.

private Object
public D
read(D reuse, Decoder in)

Implements org.apache.avro.io.DatumReader.read.

Read a datum.
protected Object
read(Object old, Schema expected, ResolvingDecoder in)

Called to read data.

protected Object
readArray(Object old, Schema expected, ResolvingDecoder in)

Called to read an array instance.

protected Object
readBytes(Object old, Schema s, Decoder in)

Called to read byte arrays.

protected Object
readBytes(Object old, Decoder in)

Called to read byte arrays.

protected Object
readEnum(Schema expected, Decoder in)

Called to read an enum value.

protected void
readField(Object record, Schema.Field field, Object oldDatum, ResolvingDecoder in, Object state)

Called to read a single field of a record.

protected Object
readFixed(Object old, Schema expected, Decoder in)

Called to read a fixed value.

protected Object
readInt(Object old, Schema expected, Decoder in)

Called to read integers.

protected Object
readMap(Object old, Schema expected, ResolvingDecoder in)

Called to read a map instance.

protected Object
readMapKey(Object old, Schema expected, Decoder in)

Called by the default implementation of readMap to read a key value.

protected Object
readRecord(Object old, Schema expected, ResolvingDecoder in)

Called to read a record instance.

protected Object
readString(Object old, Schema expected, Decoder in)

Called to read strings.

protected Object
readString(Object old, Decoder in)

Called to read strings.

protected Object
readWithConversion(Object old, Schema expected, LogicalType logicalType, Conversion<?> conversion, ResolvingDecoder in)

protected Object
public void
setExpected(Schema reader)

Set the reader's schema.

public void
setSchema(Schema writer)

Implements org.apache.avro.io.DatumReader.setSchema.

Set the writer's schema.
public static void
skip(Schema schema, Decoder in)

Skip an instance of a schema.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actualback to summary
private Schema actual
creatorback to summary
private final Thread creator
creatorResolverback to summary
private ResolvingDecoder creatorResolver
databack to summary
private final GenericData data
expectedback to summary
private Schema expected
fastDatumReaderback to summary
private DatumReader<D> fastDatumReader
readerCacheback to summary
private final GenericDatumReader.ReaderCache readerCache
RESOLVER_CACHEback to summary
private static final ThreadLocal<Map<Schema, Map<Schema, ResolvingDecoder>>> RESOLVER_CACHE

Constructor Detail

GenericDatumReaderback to summary
public GenericDatumReader()
GenericDatumReaderback to summary
public GenericDatumReader(Schema schema)

Construct where the writer's and reader's schemas are the same.

GenericDatumReaderback to summary
public GenericDatumReader(Schema writer, Schema reader)

Construct given writer's and reader's schema.

GenericDatumReaderback to summary
public GenericDatumReader(Schema writer, Schema reader, GenericData data)
GenericDatumReaderback to summary
protected GenericDatumReader(GenericData data)

Method Detail

addToArrayback to summary
protected void addToArray(Object array, long pos, Object e)

Called by the default implementation of readArray to add a value. The default implementation is for Collection.

Annotations
@SuppressWarnings:unchecked
addToMapback to summary
protected void addToMap(Object map, Object key, Object value)

Called by the default implementation of readMap to add a key/value pair. The default implementation is for Map.

Annotations
@SuppressWarnings:unchecked
convertback to summary
protected Object convert(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).

Exceptions
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.
createBytesback to summary
protected Object createBytes(byte[] value)

Called to create byte arrays from default values. Subclasses may override to use a different byte array representation. By default, this calls ByteBuffer#wrap(byte[]).

createEnumback to summary
protected Object createEnum(String symbol, Schema schema)

Called to create an enum value. May be overridden for alternate enum representations. By default, returns a GenericEnumSymbol.

createFixedback to summary
protected Object createFixed(Object old, Schema schema)

Deprecated

As of Avro 1.6.0 this method has been moved to GenericData#createFixed(Object, Schema)

Called to create an fixed value. May be overridden for alternate fixed representations. By default, returns GenericFixed.

Annotations
@Deprecated
createFixedback to summary
protected Object createFixed(Object old, byte[] bytes, Schema schema)

Deprecated

As of Avro 1.6.0 this method has been moved to GenericData#createFixed(Object, byte[], Schema)

Called to create an fixed value. May be overridden for alternate fixed representations. By default, returns GenericFixed.

Annotations
@Deprecated
createStringback to summary
protected Object createString(String value)

Called to create a string from a default value. Subclasses may override to use a different string representation. By default, this calls Utf8#Utf8(String).

findStringClassback to summary
protected Class<T> findStringClass(Schema schema)

Determines the class to used to represent a string Schema. By default uses GenericData#STRING_PROP to determine whether Utf8 or String is used. Subclasses may override for alternate representations.

getDataback to summary
public GenericData getData()

Return the GenericData implementation.

getExpectedback to summary
public Schema getExpected()

Get the reader's schema.

getReaderCacheback to summary
pack-priv GenericDatumReader.ReaderCache getReaderCache()
getResolverback to summary
protected final ResolvingDecoder getResolver(Schema actual, Schema expected) throws IOException

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.

getSchemaback to summary
public Schema getSchema()

Return the writer's schema.

newArrayback to summary
protected Object newArray(Object old, int size, Schema schema)

Called to create new array instances. Subclasses may override to use a different array implementation. By default, this returns a GenericData.Array.

Annotations
@SuppressWarnings:unchecked
newInstanceFromStringback to summary
protected Object newInstanceFromString(Class<T> c, String s)
Annotations
@SuppressWarnings:unchecked
newMapback to summary
protected Object newMap(Object old, int size)

Called to create new array instances. Subclasses may override to use a different map implementation. By default, this returns a HashMap.

Annotations
@SuppressWarnings:unchecked
newRecordback to summary
protected Object newRecord(Object old, Schema schema)

Deprecated

As of Avro 1.6.0 this method has been moved to GenericData#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 a GenericData.Record.

Annotations
@Deprecated
peekArrayback to summary
protected Object peekArray(Object array)

Called by the default implementation of readArray to retrieve a value from a reused instance. The default implementation is for GenericArray.

Annotations
@SuppressWarnings:unchecked
pruneArrayback to summary
private Object pruneArray(Object object)
readback to summary
public D read(D reuse, Decoder in) throws IOException

Implements org.apache.avro.io.DatumReader.read.

Doc from org.apache.avro.io.DatumReader.read.

Read 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.

Annotations
@Override
@SuppressWarnings:unchecked
readback to summary
protected Object read(Object old, Schema expected, ResolvingDecoder in) throws IOException

Called to read data.

readArrayback to summary
protected Object readArray(Object old, Schema expected, ResolvingDecoder in) throws IOException

Called to read an array instance. May be overridden for alternate array representations.

readBytesback to summary
protected Object readBytes(Object old, Schema s, Decoder in) throws IOException

Called to read byte arrays. Subclasses may override to use a different byte array representation. By default, this calls Decoder#readBytes(ByteBuffer).

readBytesback to summary
protected Object readBytes(Object old, Decoder in) throws IOException

Called to read byte arrays. Subclasses may override to use a different byte array representation. By default, this calls Decoder#readBytes(ByteBuffer).

readEnumback to summary
protected Object readEnum(Schema expected, Decoder in) throws IOException

Called to read an enum value. May be overridden for alternate enum representations. By default, returns a GenericEnumSymbol.

readFieldback to summary
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.

readFixedback to summary
protected Object readFixed(Object old, Schema expected, Decoder in) throws IOException

Called to read a fixed value. May be overridden for alternate fixed representations. By default, returns GenericFixed.

readIntback to summary
protected Object readInt(Object old, Schema expected, Decoder in) throws IOException

Called to read integers. Subclasses may override to use a different integer representation. By default, this calls Decoder#readInt().

readMapback to summary
protected Object readMap(Object old, Schema expected, ResolvingDecoder in) throws IOException

Called to read a map instance. May be overridden for alternate map representations.

readMapKeyback to summary
protected Object readMapKey(Object old, Schema expected, Decoder in) throws IOException

Called by the default implementation of readMap to read a key value. The default implementation returns delegates to readString(Object, org.apache.avro.io.Decoder).

readRecordback to summary
protected Object readRecord(Object old, Schema expected, ResolvingDecoder in) throws IOException

Called to read a record instance. May be overridden for alternate record representations.

readStringback to summary
protected Object readString(Object old, Schema expected, Decoder in) throws IOException

Called to read strings. Subclasses may override to use a different string representation. By default, this calls readString(Object, Decoder).

readStringback to summary
protected Object readString(Object old, Decoder in) throws IOException

Called to read strings. Subclasses may override to use a different string representation. By default, this calls Decoder#readString(Utf8).

readWithConversionback to summary
protected Object readWithConversion(Object old, Schema expected, LogicalType logicalType, Conversion<?> conversion, ResolvingDecoder in) throws IOException
readWithoutConversionback to summary
protected Object readWithoutConversion(Object old, Schema expected, ResolvingDecoder in) throws IOException
setExpectedback to summary
public void setExpected(Schema reader)

Set the reader's schema.

setSchemaback to summary
public void setSchema(Schema writer)

Implements org.apache.avro.io.DatumReader.setSchema.

Doc from org.apache.avro.io.DatumReader.setSchema.

Set the writer's schema.

Annotations
@Override
skipback to summary
public static void skip(Schema schema, Decoder in) throws IOException

Skip an instance of a schema.

org.apache.avro.generic back to summary

private final Class GenericDatumReader.IdentitySchemaKey

extends Object
Class Inheritance

This class is used to reproduce part of IdentityHashMap in ConcurrentHashMap code.

Field Summary

Modifier and TypeField and Description
private final int
private final Schema

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

hashcodeback to summary
private final int hashcode
schemaback to summary
private final Schema schema

Constructor Detail

IdentitySchemaKeyback to summary
public IdentitySchemaKey(Schema schema)

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
org.apache.avro.generic back to summary

pack-priv Class GenericDatumReader.ReaderCache

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Function<Schema, Class<T>>
private final Map<GenericDatumReader.IdentitySchemaKey, Class<T>>
private final Map<Class<T>, Function<String, Object>>

Constructor Summary

AccessConstructor and Description
public
ReaderCache(Function<Schema, Class<T>> findStringClass)

Method Summary

Modifier and TypeMethod and Description
private Function<String, Object>
public Class<T>
public Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

findStringClassback to summary
private final Function<Schema, Class<T>> findStringClass
stringClassCacheback to summary
private final Map<GenericDatumReader.IdentitySchemaKey, Class<T>> stringClassCache
stringCtorCacheback to summary
private final Map<Class<T>, Function<String, Object>> stringCtorCache

Constructor Detail

ReaderCacheback to summary
public ReaderCache(Function<Schema, Class<T>> findStringClass)

Method Detail

buildFunctionback to summary
private Function<String, Object> buildFunction(Class<T> c)
getStringClassback to summary
public Class<T> getStringClass(final Schema s)
newInstanceFromStringback to summary
public Object newInstanceFromString(Class<T> c, String s)