-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AVRO-3155: [docs] Remove 'default' from map and array examples (and add to enum). #3046
AVRO-3155: [docs] Remove 'default' from map and array examples (and add to enum). #3046
Conversation
Default values are not valid for maps and arrays, and are only valid for record fields (and enums, though that's a different story). Having it in the examples is confusing, as people might have expectations around it behaving in a certain way. In the Java and Rust implementation, a default value listed here will be packed into the custom props and attributes payloads, and do not need to be of the same type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originates from
#662 https://issues.apache.org/jira/browse/AVRO-2574 It doesn't mention any reason though.
cc @Fokko
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks correct to me
BTW, I don't think Rust implementation is stable enough as a reference. Can you link to related Java code? |
This is in Schema.java. @Override
@Deprecated
void toJson(Set<String> knownNames, String currentNamespace, JsonGenerator gen) throws IOException {
gen.writeStartObject();
gen.writeStringField("type", "map");
gen.writeFieldName("values");
valueType.toJson(knownNames, currentNamespace, gen);
writeProps(gen);
gen.writeEndObject();
} Props are written, but there's no default value to be seen. On the parsing side, the code for the parser code also just reads the value field here. |
Is there anything else required to get this merged? Like it's not critical, but it's weird to leave it hanging. |
This pull request seems to fix [AVRO-3155] Schema specification inconsistently describes default value for types. |
AVRO-3155
What is the purpose of the change
Default values have no special purpose for maps and arrays, and are only
valid for record fields and enums.
Having it in the examples is confusing, as people might have expectations
around it behaving in a certain way.
In the Java and Rust implementation, a default value listed here
will be packed into the custom props and attributes payloads, and
do not need to be of the same type; i.e.,
default: "no default"
wouldbe valid.
Other implementations just ignore it and won't round trip it, for example:
Verifying this change
I wrote a small test in rust to validate my understanding; unfortunately
using an assertion on Map would be confusing as the instance
for
Eq
forMapSchema
ignores theattributes
field.Resulting in:
For Java I just read the code.