Database Reference
In-Depth Information
Type
Description
Schema example
fixed A fixed number of 8-bit unsigned bytes.
{
"type" :
"fixed" ,
"name" :
"Md5Hash" ,
"size" : 16
}
union A union of schemas. A union is represented by a JSON array, where each
element in the array is a schema. Data represented by a union must match
one of the schemas in the union.
[
"null" ,
"string" ,
{ "type" :
"map" ,
"values" :
"string" }
]
Each Avro language API has a representation for each Avro type that is specific to the lan-
guage. For example, Avro's double type is represented in C, C++, and Java by a
double , in Python by a float , and in Ruby by a Float .
What's more, there may be more than one representation, or mapping, for a language. All
languages support a dynamic mapping, which can be used even when the schema is not
known ahead of runtime. Java calls this the Generic mapping.
In addition, the Java and C++ implementations can generate code to represent the data for
an Avro schema. Code generation, which is called the Specific mapping in Java, is an op-
timization that is useful when you have a copy of the schema before you read or write
data. Generated classes also provide a more domain-oriented API for user code than Gen-
eric ones.
Java has a third mapping, the Reflect mapping, which maps Avro types onto preexisting
Java types using reflection. It is slower than the Generic and Specific mappings but can be
a convenient way of defining a type, since Avro can infer a schema automatically.
Java's type mappings are shown in Table 12-3 . As the table shows, the Specific mapping
is the same as the Generic one unless otherwise noted (and the Reflect one is the same as
the Specific one unless noted). The Specific mapping differs from the Generic one only
for record , enum , and fixed , all of which have generated classes (the names of which
are controlled by the name and optional namespace attributes).
Search WWH ::




Custom Search