You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: Don't let a record field alias shadow the name of another field - #752
Here lookup is {"x": 1, "y": 1}, so serializing a struct with the fields x and y fails, because x is written with the schema of y. Value::validate and Record::put("x") also end up at y. With the two fields the other way around, the schema doesn't parse at all ("Duplicate field name x"). This is the same on 0.22.0 and 0.23.0.
This PR inserts all names first and adds an alias only if it isn't already the name of a field, so a name always maps to its own field. I also wrote that down in the doc comment of lookup. That's the order encode.rs already uses (name first, then aliases). Aliases that two fields share still point to the last of them, as before.
Strictly speaking, such a schema isn't valid: since AVRO-3833 the spec says aliases are "subject to the same uniqueness constraints as names". The implementations don't agree, though. Java, Python, fastavro and the Go libraries accept both orders and write by field name, while C# and C++ reject both. I went with accepting them, so nothing that parses today stops parsing. If you'd rather reject these schemas like C# and C++, that's a small change and I can switch the PR to it.
RecordSchema::builder(), and as far as I can see the new parser in #672, don't put aliases into lookup at all. Should they be there?
I ran into this while working on a faster record serializer, which relies on every field name mapping to its own field. I'll open that PR right after this one; it builds on this fix.
@martin-g what do you think, error or silently accept?
Error.
Unless the Java SDK does something else. People often come with it is against the spec / common sense but the Java SDK already does it. In this case we should be compatible and a user provided policy would be the best.
@martin-g what do you think, error or silently accept?
Error.
Unless the Java SDK does something else. People often come with it is against the spec / common sense but the Java SDK already does it. In this case we should be compatible and a user provided policy would be the best.
hmm, Thanks. I will continue working on this tomorrow 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a field alias equals the name of another field, the parser overwrites that field's entry in
RecordSchema::lookup:{"type": "record", "name": "R", "fields": [ {"name": "x", "type": "int"}, {"name": "y", "type": "long", "aliases": ["x"]} ]}Here
lookupis{"x": 1, "y": 1}, so serializing a struct with the fieldsxandyfails, becausexis written with the schema ofy.Value::validateandRecord::put("x")also end up aty. With the two fields the other way around, the schema doesn't parse at all ("Duplicate field name x"). This is the same on 0.22.0 and 0.23.0.This PR inserts all names first and adds an alias only if it isn't already the name of a field, so a name always maps to its own field. I also wrote that down in the doc comment of
lookup. That's the orderencode.rsalready uses (name first, then aliases). Aliases that two fields share still point to the last of them, as before.Strictly speaking, such a schema isn't valid: since AVRO-3833 the spec says aliases are "subject to the same uniqueness constraints as names". The implementations don't agree, though. Java, Python, fastavro and the Go libraries accept both orders and write by field name, while C# and C++ reject both. I went with accepting them, so nothing that parses today stops parsing. If you'd rather reject these schemas like C# and C++, that's a small change and I can switch the PR to it.
RecordSchema::builder(), and as far as I can see the new parser in #672, don't put aliases intolookupat all. Should they be there?I ran into this while working on a faster record serializer, which relies on every field name mapping to its own field. I'll open that PR right after this one; it builds on this fix.