Repository navigation
Conversation
I don't understand the question. |
| .inner | ||
| .resolved | ||
| .get_names() | ||
| .iter() |
There was a problem hiding this comment.
Why do we need to iterate + map + collect ?
Can't we just use the result of get_names() ?
There was a problem hiding this comment.
I we need a NamesRef and get_names return Names:
ResolvedOwnedSchema::get_names() returns Names which is the "owned" version pub type Names = HashMap<Name, Schema>;.
SchemaAwareSerializer::new takes a NamesRef which is pub type NamesRef<'a> = HashMap<Name, &'a Schema>;.
I haven't found a way to avoid the nasty map duplication. I decided to keep it in here - it's a onetime thing.
Previously, write_ref() called write_avro_datum_ref() which creates a serializer with an empty names map, causing Schema::Ref types to fail resolution during serialization. Now the serializer receives the resolved schema names from ResolvedOwnedSchema, enabling proper Schema::Ref resolution for recursive schemas. Added test: test_specific_single_object_writer_with_schema_ref and extend the test schema with a recursion.
Thanks having a look. I'm not sure anymore why I wrote that - probably I looked at a wrong fn;. You're right that write_avro_datum_ref now just got proper |
ca60165 to
88a48e1
Compare
Kriskras99
left a comment
There was a problem hiding this comment.
I don't think this is the right way to solve this. To properly fix this, ResolvedOwnedSchema needs to be reworked, I've started work on this in a branch and I'll open a draft PR tomorrow
Thanks for your review @Kriskras99! You're writing in #442: "This is related to #439, but doesn't directly support fixing it". What's the forward path then to fix single object encoding for recursive types? |
Looks like #445 is solving the issue addressed in this PR. @Kriskras99: feel free to close #439 if applicable. |
Summary
Fixes a bug in
SpecificSingleObjectWriter::write_ref()whereSchema::Reftypes failed to resolve during serialization of recursive schemas.Problem
The
write_ref()method was callingwrite_avro_datum_ref()which created a serializer with an empty names map. This causedSchema::Reftypes to fail resolution during serialization, preventing recursive schemas from being properly serialized.Solution
Modified
SpecificSingleObjectWriter::write_ref()to:GenericSingleObjectWriter'sResolvedOwnedSchemaSchema::RefresolutionAlso updated
write_avro_datum_ref()to create aResolvedSchemafrom the input schema and use its names map instead of an empty map.Test Plan
Added
test_specific_single_object_writer_with_schema_ref()which:Nodeschema with a self-referencing fieldOpen questions:
- [x] This change makeswrite_avro_datum_refuseSchemAwareWriteSerializerwhich is probably more expensive than a plainwrite_avro_datum_ref. Shall this be part of the MR?