Avro schema: adding a new field with default value - straight default value or a union with null?











up vote
0
down vote

favorite












So I have an avro record like so (call it v1):



record MyRecord {
array<string> keywords;
}


I'd like to add a field caseSensitive with a default value of false (call it v2). The first approach I have is:



record MyRecord {
array<string> keywords;
boolean caseSensitive = false;
}


According to schema evolution, this is both backward and forward compatible because a reader with the new schema v2 reading a record that was encoded with old writer schema v1 will be able to fill this field with the default value and a reader with older schema v1 will be able to read a record encoded with the new writer schema v2 because it will just ignore the newly added field.



Another way to add this field is by adding a union type of null and boolean with a default value of null, like so:



record MyRecord {
array<string> keywords;
union{null, boolean} caseSensitive = null;
}


This is also backward and forward compatible. I can see that sometimes one would want to use the 2nd approach if there is no clear default value for a field (such as name, address, etc.). But given my use case with a clear default value, I'm thinking of going with the first solution. My question is: is there any other concerns that I'm missing here?










share|improve this question


























    up vote
    0
    down vote

    favorite












    So I have an avro record like so (call it v1):



    record MyRecord {
    array<string> keywords;
    }


    I'd like to add a field caseSensitive with a default value of false (call it v2). The first approach I have is:



    record MyRecord {
    array<string> keywords;
    boolean caseSensitive = false;
    }


    According to schema evolution, this is both backward and forward compatible because a reader with the new schema v2 reading a record that was encoded with old writer schema v1 will be able to fill this field with the default value and a reader with older schema v1 will be able to read a record encoded with the new writer schema v2 because it will just ignore the newly added field.



    Another way to add this field is by adding a union type of null and boolean with a default value of null, like so:



    record MyRecord {
    array<string> keywords;
    union{null, boolean} caseSensitive = null;
    }


    This is also backward and forward compatible. I can see that sometimes one would want to use the 2nd approach if there is no clear default value for a field (such as name, address, etc.). But given my use case with a clear default value, I'm thinking of going with the first solution. My question is: is there any other concerns that I'm missing here?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      So I have an avro record like so (call it v1):



      record MyRecord {
      array<string> keywords;
      }


      I'd like to add a field caseSensitive with a default value of false (call it v2). The first approach I have is:



      record MyRecord {
      array<string> keywords;
      boolean caseSensitive = false;
      }


      According to schema evolution, this is both backward and forward compatible because a reader with the new schema v2 reading a record that was encoded with old writer schema v1 will be able to fill this field with the default value and a reader with older schema v1 will be able to read a record encoded with the new writer schema v2 because it will just ignore the newly added field.



      Another way to add this field is by adding a union type of null and boolean with a default value of null, like so:



      record MyRecord {
      array<string> keywords;
      union{null, boolean} caseSensitive = null;
      }


      This is also backward and forward compatible. I can see that sometimes one would want to use the 2nd approach if there is no clear default value for a field (such as name, address, etc.). But given my use case with a clear default value, I'm thinking of going with the first solution. My question is: is there any other concerns that I'm missing here?










      share|improve this question













      So I have an avro record like so (call it v1):



      record MyRecord {
      array<string> keywords;
      }


      I'd like to add a field caseSensitive with a default value of false (call it v2). The first approach I have is:



      record MyRecord {
      array<string> keywords;
      boolean caseSensitive = false;
      }


      According to schema evolution, this is both backward and forward compatible because a reader with the new schema v2 reading a record that was encoded with old writer schema v1 will be able to fill this field with the default value and a reader with older schema v1 will be able to read a record encoded with the new writer schema v2 because it will just ignore the newly added field.



      Another way to add this field is by adding a union type of null and boolean with a default value of null, like so:



      record MyRecord {
      array<string> keywords;
      union{null, boolean} caseSensitive = null;
      }


      This is also backward and forward compatible. I can see that sometimes one would want to use the 2nd approach if there is no clear default value for a field (such as name, address, etc.). But given my use case with a clear default value, I'm thinking of going with the first solution. My question is: is there any other concerns that I'm missing here?







      avro backwards-compatibility






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      breezymri

      81521530




      81521530





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402440%2favro-schema-adding-a-new-field-with-default-value-straight-default-value-or-a%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402440%2favro-schema-adding-a-new-field-with-default-value-straight-default-value-or-a%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Berounka

          Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

          Sphinx de Gizeh