avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tony Imbault <timba...@talend.com>
Subject RE: Impossible to start an union with a named type
Date Thu, 06 Jul 2017 08:52:50 GMT
Thank you Nandor,

I had already done this test, but in my context it is very important to respect the specified
order.

In my opinion the class SchemaBuilder.UnionFieldTypeBuilder should provide the methods type(name),
type (name, namespace) and type(schemaType).

I will check if a jira already exists for this issue.

Thank you

Tony


De : Nandor Kollar [mailto:nkollar@cloudera.com]
Envoyé : jeudi 6 juillet 2017 10:43
À : user@avro.apache.org
Objet : Re: Impossible to start an union with a named type

Hi Tony,

If you change the order of elements in the author field, it is fine:

@Test
public void testUnion() {
  Schema schema = SchemaBuilder
    .unionOf()
    .record("Author")
    .fields()
    .name("name").type().stringType().noDefault()
    .name("birthday").type().longType().noDefault()
    .endRecord().and()
    .record("Book")
    .fields()
    .name("title").type().stringType().noDefault()
    .name("author").type().unionOf()
    .stringType().and()
    .type("Author")
    .endUnion()
    .noDefault()
    .endRecord().endUnion();
}

The specification doesn't say anything about the order of types in a union, so I guess it
shouldn't limit it, I think you're right, your code should compile. Maybe this is a bug in
the SchemaBuilder?

Nandor

On Thu, Jul 6, 2017 at 10:14 AM, Tony Imbault <timbault@talend.com<mailto:timbault@talend.com>>
wrote:
Hi everybody,

i am trying to build the followong JSON schema:

[{
     "type": "record",
     "name": "Author",
     "fields": [{
          "name": "name",
          "type": "string"
     },
     {
          "name": "birthday",
          "type": "long"
     }]
},
{
     "type": "record",
     "name": "Book",
     "fields": [{
          "name": "title",
          "type": "string"
     },
     {
          "name": "author",
          "type": ["Author", "string"]
     }]
}]

In my humble opinion this JSON schema is valid.

But it seems that the SchemaBuilder API does not permit to build this schema.
The corresponding code should be something like that:

Schema schema = SchemaBuilder
                     .unionOf()
                     .record("Author")
                     .fields()
                     .name("name").type().stringType().noDefault()
                     .name("birthday").type().longType().noDefault()
                     .endRecord().and()
                     .record("Book")
                     .fields()
                     .name("title").type().stringType().noDefault()
                     .name("author").type().unionOf()
                     .type("Author").and()
                     .stringType().endUnion()
                     .noDefault()
                     .endRecord().endUnion();

But after a call to unionOf() the type(name) method is not available.

Is there any reason for this limitation?

Thank you very much

Tony Imbault

Mime
View raw message