[
https://issues.apache.org/jira/browse/AVRO-1274?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13647196#comment-13647196
]
Scott Carey commented on AVRO-1274:
-----------------------------------
We may have more work to do here.
How would you use the builder to do the equivalent of:
{code}
public static final org.apache.avro.Schema SCHEMA$ = new
org.apache.avro.Schema.Parser().parse(
"{\"type\":\"record\",\"name\":\"HandshakeRequest\",\"namespace\":\"org.apache.avro.ipc\",\"fields\":[
{\"name\":\"clientHash\",\"type\":{\"type\":\"fixed\",\"name\":\"MD5\",\"size\":16}},
{\"name\":\"clientProtocol\",\"type\":[\"null\",{\"type\":\"string\",\"avro.java.string\":\"String\"}]},
{\"name\":\"serverHash\",\"type\":\"MD5\"},
{\"name\":\"meta\",\"type\":[\"null\",{\"type\":\"map\",\"values\":\"bytes\",\"avro.java.string\":\"String\"}]}
]}");
{code}
?
I am trying to suggest that we replace literal strings with the builder in
AVRO-1316 but cannot seem to repliate the above with the builder.
The "clientProtocol" and "meta" fields are the problem. It does not seem
possible to create a union of null and 'more' without a default.
Additionally, "unionType" is confusing. Is this how it would be done? If so,
I do not see how to add types to the union if I start with:
{code}
unionType("clientProtocol", SchemaBuilder.NULL)
{code}
Then how do I add extra types? Or is the type passed in expected to _be_ a
union? if so the field should be named unionSchema and the javadoc needs to be
clear.
This builder API makes it hard to create union fields without defaults.
Perhaps it is simply a documentation issue and the doc for unionType() needs an
example.
Should we open a new ticket for these concerns or re-open this one? I suspect
it is largely documentation but am not sure.
> Add a schema builder API
> ------------------------
>
> Key: AVRO-1274
> URL: https://issues.apache.org/jira/browse/AVRO-1274
> Project: Avro
> Issue Type: New Feature
> Components: java
> Reporter: Tom White
> Assignee: Tom White
> Fix For: 1.7.5
>
> Attachments: AVRO-1274.patch, AVRO-1274.patch, AVRO-1274.patch,
> AVRO-1274.patch, AVRO-1274.patch, AVRO-1274.patch, AVRO-1274.patch,
> TestDefaults.patch
>
>
> It would be nice to have a fluent API that made it easier to construct record
> schemas.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira