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

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

                Author: ASF GitHub Bot
            Created on: 23/Nov/21 15:54
            Start Date: 23/Nov/21 15:54
    Worklog Time Spent: 10m 
      Work Description: opwvhk commented on a change in pull request #1411:
URL: https://github.com/apache/avro/pull/1411#discussion_r755269337



##########
File path: doc/src/content/xdocs/idl.xml
##########
@@ -301,17 +301,32 @@ 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. The following two fields have 
identical types:
+          </p>
+          <source>
+record RecordWithUnion {
+  union { null, string } optionalString1;
+  string? optionalString2;
+}
+          </source>
+          <p>Note that the union contains the <code>null</code> type first, so 
the only allowed default
+            value is <code>null</code>.</p>

Review comment:
       This documents the addition




-- 
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: 685365)
    Time Spent: 20m  (was: 10m)

> 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
>          Time Spent: 20m
>  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