[ 
https://issues.apache.org/jira/browse/AVRO-3257?focusedWorklogId=693503&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-693503
 ]

ASF GitHub Bot logged work on AVRO-3257:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 09/Dec/21 19:20
            Start Date: 09/Dec/21 19:20
    Worklog Time Spent: 10m 
      Work Description: martin-g commented on a change in pull request #1411:
URL: https://github.com/apache/avro/pull/1411#discussion_r766084596



##########
File path: doc/src/content/xdocs/idl.xml
##########
@@ -301,17 +301,36 @@ record Card {
         <section id="unions">
           <title>Unions</title>
           <p>Union types are denoted as <code>union { typeA, typeB, typeC, ... 
}</code>. For example,
-          this record contains a string field that is optional (unioned with 
<code>null</code>):
+          this record contains a string field that is optional (unioned with 
<code>null</code>), and
+          a field containing either a precise or a imprecise number:
           </p>
           <source>
 record RecordWithUnion {
   union { null, string } optionalString;
+  union { decimal(12, 6), float } number;
 }
           </source>
           <p>
             Note that the same restrictions apply to Avro IDL unions as apply 
to unions defined in the
-            JSON format; namely, a record may not contain multiple elements of 
the same type.
+            JSON format; namely, a record may not contain multiple elements of 
the same type. Also,
+            fields/parameters that use the union type and have a default 
parameter must specify a
+            default value of the same type as the <em>first</em>em> union type.
           </p>
+          <p>Because it occurs so often, there is a special shorthand to 
denote a union of
+            <code>null</code> with another type. In the following snippet, the 
first three fields have
+            identical types:
+          </p>
+          <source>
+record RecordWithUnion {
+  union { null, string } optionalString1 = null;
+  string? optionalString2 = null;
+  string? optionalString3; // No default value
+  string? optionalString4 = "something";
+}
+          </source>
+          <p>Note that unlike explicit unions, the position of the 
<code>null</code> type is fluid; it will be
+            the first or last type depending on the default value (if any). So 
in the example above, all fields
+            are valid.</p>

Review comment:
       We should not forget to update the new website once it starts being used 
(https://lists.apache.org/thread/ktjh7kyd92hf0jsmpp16c3k121dc8grg)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 693503)
    Time Spent: 1h 40m  (was: 1.5h)

> IDL: add syntax to create optional fields
> -----------------------------------------
>
>                 Key: AVRO-3257
>                 URL: https://issues.apache.org/jira/browse/AVRO-3257
>             Project: Apache Avro
>          Issue Type: Improvement
>          Components: java, spec
>            Reporter: Oscar Westra van Holthe - Kind
>            Assignee: Oscar Westra van Holthe - Kind
>            Priority: Minor
>              Labels: javacc, pull-request-available
>             Fix For: 1.11.1
>
>          Time Spent: 1h 40m
>  Remaining Estimate: 0h
>
> To define optional values, Avro has the "union with the null type" 
> construction.
> In IDL, this is a rather verbose construct:
> {code}
> union {null, string} optionalName = null;
> {code}
> Wish: add Kotlin style optional types like this:
> {code}
> string? optionalName = null;
> {code}
> The resulting schema should be identical; it's only a syntax change.
> Note: it would be nice (but not required) if the syntax would also work if 
> the default value is not null:
> {code}
> string? optionalName = "Jane Doe";
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to