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?
avro backwards-compatibility
add a comment |
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?
avro backwards-compatibility
add a comment |
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?
avro backwards-compatibility
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
avro backwards-compatibility
asked 2 days ago
breezymri
81521530
81521530
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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