Skip to content

Commit dfee9f6

Browse files
committed
"Mapping to Logical Types" section extended with UUID
1 parent 0384404 commit dfee9f6

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

avro/README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,32 +114,34 @@ and that's about it, for now.
114114

115115
## Avro Logical Types
116116

117-
Following is an extract from [Logical Types](http://avro.apache.org/docs/current/specification/_print/#logical-types) paragraph in
118-
Avro schema specification:
117+
The following is an excerpt from the [Logical Types](https://avro.apache.org/docs/1.11.1/specification/#logical-types) section of
118+
the Avro schema specification:
119+
119120
> A logical type is an Avro primitive or complex type with extra attributes to represent a derived type. The attribute
120-
> `logicalType` is always be present for a logical type, and is a string with the name of one of the logical types
121-
> defined by Avro specification.
121+
> `logicalType` must always be present for a logical type, and is a string with the name of one of the logical types
122+
> listed later in this section. Other attributes may be defined for particular logical types.
123+
124+
Logical types are supported for a limited set of `java.time` classes and for 'java.util.UUID'. See the table below for more details.
122125

123-
Generation of logical types for limited set of `java.time` classes is supported at the moment. See a table bellow.
126+
### Mapping to Logical Types
124127

125-
### Mapping to Logical Type
128+
Mapping to Avro type and logical type involves these steps:
126129

127-
Mapping to Avro type and logical type works in few steps:
128-
1. Serializer for particular Java type (or class) determines a Jackson type where the Java type will be serialized into.
129-
2. `AvroSchemaGenerator` determines corresponding Avro type for that Jackson type.
130-
2. If logical type generation is enabled, then `logicalType` is determined for the above combination of Java type and
131-
Avro type.
130+
1. The serializer for a Java type identifies the Jackson type it will serialize into.
131+
2. The `AvroSchemaGenerator` maps that Jackson type to the corresponding Avro type.
132+
3. `logicalType` value is combination of Java type and Jackson type.
132133

133134
#### Java type to Avro Logical Type mapping
134135

135-
| Java type | Serialization type | Generated Avro schema with Avro type and logical type
136-
| ----------------------------- | ------------------ | -----------------------------------------------------
137-
| `java.time.OffsetDateTime` | NumberType.LONG | `{"type": "long", "logicalType": "timestamp-millis"}`
138-
| `java.time.ZonedDateTime` | NumberType.LONG | `{"type": "long", "logicalType": "timestamp-millis"}`
139-
| `java.time.Instant` | NumberType.LONG | `{"type": "long", "logicalType": "timestamp-millis"}`
140-
| `java.time.LocalDate` | NumberType.INT | `{"type": "int", "logicalType": "date"}`
141-
| `java.time.LocalTime` | NumberType.INT | `{"type": "int", "logicalType": "time-millis"}`
142-
| `java.time.LocalDateTime` | NumberType.LONG | `{"type": "long", "logicalType": "local-timestamp-millis"}`
136+
| Java type | Jackson type | Generated Avro schema with logical type |
137+
|----------------------------|-----------------|---------------------------------------------------------------------------------------------------|
138+
| `java.time.OffsetDateTime` | NumberType.LONG | `{"type": "long", "logicalType": "timestamp-millis"}` |
139+
| `java.time.ZonedDateTime` | NumberType.LONG | `{"type": "long", "logicalType": "timestamp-millis"}` |
140+
| `java.time.Instant` | NumberType.LONG | `{"type": "long", "logicalType": "timestamp-millis"}` |
141+
| `java.time.LocalDate` | NumberType.INT | `{"type": "int", "logicalType": "date"}` |
142+
| `java.time.LocalTime` | NumberType.INT | `{"type": "int", "logicalType": "time-millis"}` |
143+
| `java.time.LocalDateTime` | NumberType.LONG | `{"type": "long", "logicalType": "local-timestamp-millis"}` |
144+
| `java.util.UUID` | | `{"type": "fixed", "name": "UUID", "namespace": "java.util", "size": 16, "logicalType" : "uuid"}` |
143145

144146
_Provided Avro logical type generation is enabled._
145147

0 commit comments

Comments
 (0)