[
https://issues.apache.org/jira/browse/AVRO-2380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17239572#comment-17239572
]
Leigh Hopcroft commented on AVRO-2380:
--------------------------------------
Hi [~wmaiouiru], thanks for the response. {code:json}"long"{code} and
{code:json}{"type":"long", "logicalType": "timestamp-micros"}{code} are
conflicting in this implementation it seems, according to the error message. As
for whether this behaviour conforms to the spec you quoted I suppose depends on
your interpretation of the phrase "same type". I expected the implementation of
this spec to treat a primitive type and a logical type based on that primitive
type to not be classed as the "same type", and therefore be allowed to coexist
in a union type.
Regarding your suggestion of defining the records in advance before using it in
a union, could you give an example? My current (not working) schema is similar
to the below for reference.
{code:json}
{"name": "val", "type": ["boolean", "int", "long", "float", "double", "string",
"bytes", {"type" : "long", "logicalType" : "timestamp-micros"}]}
{code}
> Logical types are not supported when the actual datatype is also present in
> Union
> ---------------------------------------------------------------------------------
>
> Key: AVRO-2380
> URL: https://issues.apache.org/jira/browse/AVRO-2380
> Project: Apache Avro
> Issue Type: Bug
> Affects Versions: 1.8.2
> Reporter: Harshvardhan Agrawal
> Priority: Major
>
> {code:java}
> {
> "name" : "data",
> "type" : {
> "type" : "map",
> "values" : {
> "type" : "array",
> "items" : {
> "type" : "map",
> "values" : [ "string", "long", "null", "double", "float", "int", "boolean"
> ]
> }
> }
> }{code}
> The above schema represents a Map<String, List<Map<String, Object>>> where
> the values of the inner map could be any of the basic datatypes supported by
> Avro.
> If we want the Map to support logical types such as timestamp for e.g.
> {code:java}
> {
> "name" : "data",
> "type" : {
> "type" : "map",
> "values" : {
> "type" : "array",
> "items" : {
> "type" : "map",
> "values" : [ "string", "long", "null", "double", "float", "int", "boolean",
> { "type" : "long", "logicalType" : "timestamp-micros" }]
> }
> }
> }{code}
> The schema parser fails with the following error:
>
> {code:java}
> Exception in thread "main" org.apache.avro.AvroRuntimeException: Duplicate in
> union:long at org.apache.avro.Schema$UnionSchema.<init>(Schema.java:854)
> at org.apache.avro.Schema.parse(Schema.java:1341)
> at org.apache.avro.Schema.parse(Schema.java:1311)
> at org.apache.avro.Schema.parse(Schema.java:1306)
> at org.apache.avro.Schema.parse(Schema.java:1311)
> at org.apache.avro.Schema.parse(Schema.java:1269)
> at org.apache.avro.Schema$Parser.parse(Schema.java:1032)
> at org.apache.avro.Schema$Parser.parse(Schema.java:1020)
> {code}
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)