[
https://issues.apache.org/jira/browse/AVRO-1274?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13609230#comment-13609230
]
Tom White commented on AVRO-1274:
---------------------------------
> nullable with null default, nullable with no default, nullable with a value
> default, non-nullable with a default, and non-null without a default
This could be confusing! I think we need to make the common cases accessible
and easy to understand. Required, optional, and optional with a default are all
common cases. The other two (nullable with no default, and to a lesser extent
non-nullable with a default) are not, so we need to work out a way of exposing
them (if we expose them at all at the moment) that makes sense in the context
of IDE autocomplete, which is how I think this API will be experienced.
One renaming might be the following, but I'm not sure what I think about it.
{noformat}
intType(name)
intType(name, default)
nullableIntType(name)
nullableIntType(name, default)
nullableIntTypeNoDefault(name)
{noformat}
Another way would be to leave the naming we have, and offer an escape hatch for
advanced users, {{SchemaBuilder.recordType("r").field("f0")...}} with the
advanced methods.
One thing I do want to avoid is excessive chaining, since if you have something
like {{name("foo").nullable().int()}} then it's not clear to users what parts
of the field definition are optional (e.g. nullable is but the type isn't).
This is why I prefer the overloaded variants of requiredX/optionalX.
Regarding enforcing the default in union types, the following change to the API
should do it:
{noformat}
Schema schema = SchemaBuilder.recordType("r")
.unionLong("myunion").withType(SchemaBuilder.NULL).build();
{noformat}
or
{noformat}
Schema schema = SchemaBuilder.recordType("r")
.unionLong("myunion", 7L).withType(SchemaBuilder.INT).build();
{noformat}
I'll create a patch for that while we decide what to do about the
optional/nullable API.
> 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
> Attachments: 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