Package org.apache.nifi.avro
Class NonCachingDatumReader<T>
java.lang.Object
org.apache.avro.generic.GenericDatumReader<T>
org.apache.nifi.avro.NonCachingDatumReader<T>
- All Implemented Interfaces:
org.apache.avro.io.DatumReader<T>
public class NonCachingDatumReader<T>
extends org.apache.avro.generic.GenericDatumReader<T>
Override the GenericDatumReader to provide a much more efficient implementation of #readString. The one that is provided by
GenericDatumReader performs very poorly in some cases because it uses an IdentityHashMap with the key being the Schema so that
it can stash away the "stringClass" but that performs far worse than just calling JsonNode#getProp. I.e.,
readString(Object, Schema, Decoder)
in GenericDatumReader calls #getStringClass, which uses an IdentityHashMap to cache results in order to avoid calling findStringClass(Schema)
.
However, findStringClass(Schema)
is much more efficient than using an IdentityHashMap anyway. Additionally, the performance of findStringClass(Schema)
}
can be improved slightly and made more readable.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Class
findStringClass
(org.apache.avro.Schema schema) protected Object
readString
(Object old, org.apache.avro.Schema expected, org.apache.avro.io.Decoder in) Methods inherited from class org.apache.avro.generic.GenericDatumReader
addToArray, addToMap, convert, createBytes, createEnum, createFixed, createFixed, createString, getData, getExpected, getResolver, getSchema, newArray, newInstanceFromString, newMap, newRecord, peekArray, read, read, readArray, readBytes, readBytes, readEnum, readField, readFixed, readInt, readMap, readMapKey, readRecord, readString, readWithConversion, readWithoutConversion, setExpected, setSchema, skip
-
Constructor Details
-
NonCachingDatumReader
public NonCachingDatumReader() -
NonCachingDatumReader
public NonCachingDatumReader(org.apache.avro.Schema schema)
-
-
Method Details
-
readString
protected Object readString(Object old, org.apache.avro.Schema expected, org.apache.avro.io.Decoder in) throws IOException - Overrides:
readString
in classorg.apache.avro.generic.GenericDatumReader<T>
- Throws:
IOException
-
findStringClass
- Overrides:
findStringClass
in classorg.apache.avro.generic.GenericDatumReader<T>
-