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












0














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



























    0














    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

























      0












      0








      0







      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 Nov 20 at 22:18









      breezymri

      82521530




      82521530
























          1 Answer
          1






          active

          oldest

          votes


















          0














          There will be a potential issue with writers in the first case--apparently writers do not use default values. So a writer writing "old data" (missing the new field--so writer is publishing a record with the "keywords" field only) will blow up against the first schema. Same writer using second schema will be successful, and the "caseSensitive" field will be set to null in the resulting message.






          share|improve this answer





















          • hmm, so if that is true, then as long as I can ensure that all my writers will be on new schema with the migration, then I'm good, correct?
            – breezymri
            Nov 29 at 0:10










          • I think so, but I'm not an expert :). I just happened to be looking at the writer issue recently, so am aware of that aspect. As far as I know, readers do use default values, so you should be good.
            – chacmool
            Nov 29 at 1:38











          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',
          autoActivateHeartbeat: false,
          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

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          There will be a potential issue with writers in the first case--apparently writers do not use default values. So a writer writing "old data" (missing the new field--so writer is publishing a record with the "keywords" field only) will blow up against the first schema. Same writer using second schema will be successful, and the "caseSensitive" field will be set to null in the resulting message.






          share|improve this answer





















          • hmm, so if that is true, then as long as I can ensure that all my writers will be on new schema with the migration, then I'm good, correct?
            – breezymri
            Nov 29 at 0:10










          • I think so, but I'm not an expert :). I just happened to be looking at the writer issue recently, so am aware of that aspect. As far as I know, readers do use default values, so you should be good.
            – chacmool
            Nov 29 at 1:38
















          0














          There will be a potential issue with writers in the first case--apparently writers do not use default values. So a writer writing "old data" (missing the new field--so writer is publishing a record with the "keywords" field only) will blow up against the first schema. Same writer using second schema will be successful, and the "caseSensitive" field will be set to null in the resulting message.






          share|improve this answer





















          • hmm, so if that is true, then as long as I can ensure that all my writers will be on new schema with the migration, then I'm good, correct?
            – breezymri
            Nov 29 at 0:10










          • I think so, but I'm not an expert :). I just happened to be looking at the writer issue recently, so am aware of that aspect. As far as I know, readers do use default values, so you should be good.
            – chacmool
            Nov 29 at 1:38














          0












          0








          0






          There will be a potential issue with writers in the first case--apparently writers do not use default values. So a writer writing "old data" (missing the new field--so writer is publishing a record with the "keywords" field only) will blow up against the first schema. Same writer using second schema will be successful, and the "caseSensitive" field will be set to null in the resulting message.






          share|improve this answer












          There will be a potential issue with writers in the first case--apparently writers do not use default values. So a writer writing "old data" (missing the new field--so writer is publishing a record with the "keywords" field only) will blow up against the first schema. Same writer using second schema will be successful, and the "caseSensitive" field will be set to null in the resulting message.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 28 at 23:15









          chacmool

          5661917




          5661917












          • hmm, so if that is true, then as long as I can ensure that all my writers will be on new schema with the migration, then I'm good, correct?
            – breezymri
            Nov 29 at 0:10










          • I think so, but I'm not an expert :). I just happened to be looking at the writer issue recently, so am aware of that aspect. As far as I know, readers do use default values, so you should be good.
            – chacmool
            Nov 29 at 1:38


















          • hmm, so if that is true, then as long as I can ensure that all my writers will be on new schema with the migration, then I'm good, correct?
            – breezymri
            Nov 29 at 0:10










          • I think so, but I'm not an expert :). I just happened to be looking at the writer issue recently, so am aware of that aspect. As far as I know, readers do use default values, so you should be good.
            – chacmool
            Nov 29 at 1:38
















          hmm, so if that is true, then as long as I can ensure that all my writers will be on new schema with the migration, then I'm good, correct?
          – breezymri
          Nov 29 at 0:10




          hmm, so if that is true, then as long as I can ensure that all my writers will be on new schema with the migration, then I'm good, correct?
          – breezymri
          Nov 29 at 0:10












          I think so, but I'm not an expert :). I just happened to be looking at the writer issue recently, so am aware of that aspect. As far as I know, readers do use default values, so you should be good.
          – chacmool
          Nov 29 at 1:38




          I think so, but I'm not an expert :). I just happened to be looking at the writer issue recently, so am aware of that aspect. As far as I know, readers do use default values, so you should be good.
          – chacmool
          Nov 29 at 1:38


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          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

          Wiesbaden

          Marschland

          Dieringhausen