Database Reference
In-Depth Information
NOTE
Avro string can be represented by either Java String or the Avro Utf8 Java type. The reason to use
Utf8 is efficiency: because it is mutable, a single Utf8 instance may be reused for reading or writing a
series of values. Also, Java String decodes UTF-8 at object construction time, whereas Avro Utf8
does it lazily, which can increase performance in some cases.
Utf8 implements Java's java.lang.CharSequence interface, which allows some interoperability
with Java libraries. In other cases, it may be necessary to convert Utf8 instances to String objects by
calling its toString() method.
Utf8 is the default for Generic and Specific, but it's possible to use String for a particular mapping.
There are a couple of ways to achieve this. The first is to set the avro.java.string property in the
schema to String :
{ "type" : "string" , "avro.java.string" : "String" }
Alternatively, for the Specific mapping, you can generate classes that have String -based getters and
setters. When using the Avro Maven plug-in, this is done by setting the configuration property
stringType to String ( The Specific API has a demonstration of this).
Finally, note that the Java Reflect mapping always uses String objects, since it is designed for Java
compatibility, not performance.
Search WWH ::




Custom Search