[ 
https://issues.apache.org/jira/browse/AVRO-1274?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13647360#comment-13647360
 ] 

Scott Carey commented on AVRO-1274:
-----------------------------------

I am working on a modification to the builder that would make its use look like 
a json schema.

{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}

becomes similar to:

{code}
  public static final org.apache.avro.Schema SCHEMA$ = SchemaBuilder
    
.typeRecord("HandshakeRequest").namespaceInherited("org.apache.avro.ipc").fields()//
 optional namespace inheritance
      .typeFixed("clientHash", MD5.SCHEMA$).field()   // or 
typeFixed("clientHash", "MD5", 16)
      
.typeUnion("clientProtocol").ofNull().andString().withProp("avro.java.string", 
"String").field()
      .typeFixed("serverHash", "MD5").field() // uses reference to already 
defined MD5
      .typeUnion("meta").ofNull().andMap().withProp("avro.java.string", 
"String").valuesBytes().field()
    .record();
{code}

we can also have shortcuts as before, for example
optionalInt("x", -1) as a shortcut for typeUnion("x").ofInt(-1).andNull()

nullableInt("maybe") as a shortcut for typeUnion("maybe").ofNull(null).andInt()

requiredInt("yes") may not be necessary, its shortcut would be 
typeInt("yes").field();

It should be straightforward to implement the whole Schema.Parser with the 
above (and simplify the parser), which makes it easy to test very thoroughly; 
there is an intentional 1:1 mapping between the parser, spec, and the builder.
                
> 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

Reply via email to