hwse opened a new pull request, #3088:
URL: https://github.com/apache/avro/pull/3088

   [AVRO-4033](https://issues.apache.org/jira/browse/AVRO-4033)
   
   ## What is the purpose of the change
   
   Currently avrogencpp generates a class for each union type that is 
encountered in the schema. Even if there is a class that represents the exact 
same union, a new type will be generated.
   
   Example Schema:
   
   ```json
   {
       "type": "record",
       "doc": "Top level Doc.",
       "name": "RootRecord",
       "fields": [
           {
               "name": "nullable_string_1",
               "type": [
                   "null",
                   "string"
               ]
           },
           {
               "name": "nullable_string_2",
               "type": [
                   "null",
                   "string"
               ]
           },
           {
               "name": "nullable_string_3",
               "type": [
                   "null",
                   "string"
               ]
           }
       ]
   }
   ```
   
   The generated RootRecord will look like this:
   
   ```c++
   struct RootRecord {
       typedef _union_test_json_Union__0__ nullable_string_1_t;
       typedef _union_test_json_Union__1__ nullable_string_2_t;
       typedef _union_test_json_Union__2__ nullable_string_3_t;
       nullable_string_1_t nullable_string_1;
       nullable_string_2_t nullable_string_2;
       nullable_string_3_t nullable_string_3;
       RootRecord() :
           nullable_string_1(nullable_string_1_t()),
           nullable_string_2(nullable_string_2_t()),
           nullable_string_3(nullable_string_3_t())
           { }
   }
   ```
   
   Each field uses a unique union class, but their code is identical. With the 
suggested changes, only one union class will be generated.
   
   This can help to reduce the header size for schemas that contain many unions.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
   
   - added unit test to check that c++ types are the same for some union types
   - added a unit test with encode/decode for the schema used in test above
   
   
   ## Documentation
   
   - Does this pull request introduce a new feature? only a small improvement 
in the generated code
   - If yes, how is the feature documented? added release note in JIRA ticket
   


-- 
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: dev-unsubscr...@avro.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to