-
Notifications
You must be signed in to change notification settings - Fork 91
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
How to determine which branch of a union was used #180
Comments
This looks like one of the recurring issues we've had reported, and still have no fix for this (yet!), after a few attempts :( Issues #61 #95 Let me know if you were referring to something else. 🙂 If you want to have a go at this, I'd be happy to review it any time you have something (even if not complete)! If not, I'll give it a go later on. Regarding the implementation, I think adding the index in the
|
How about using a dedicated struct Record;
struct Added {
payload: Record,
}
struct Deleted {
payload: Record,
}
struct Updated {
payload: Record,
}
enum UnionOperation {
Added(Added),
Updated(Updated),
Deleted(Deleted),
} |
No, i think that's the same issue. Sorry about that :) I'd like to take a stab at this but i intend to wait until #99 is merged. If i can do something to help there please let me know. This is indeed how i intend to deserialize this into a rust type but the problem I'm running into now is that the intermediate model (the Value::Union and Value::Record specifically) do not contain the information that would be needed to create to right branch of my enum so that i want to change first. I assume that I'll also need to change the serde deserialization code to use the additional information added to Union or Record to get that working. I think I can either match the avro record name to the rust enum branch name or use something like |
I've a schema that wraps a record type in a union that all have the same layout. They only differ on record name.
For instance:
Added { payload: Record}
Deleted { payload: Record}
Updated { payload: Record}
I can parse these records and that gives me a Union(Record[payload: Record]) but i can't find a way to determine if it's added, delete or updated.
Is this a limitation of the library and, if so, what do you think about adding a reference to the schema or schema name to the Record struct to make this possible? An alternative would be to add the index of the branch to Union so i can resolve it myself using the reader schema (a bit less user friendly but this won't cause any ownership issues so it might be easier to implement)
Both options may break serde deserialization as well i guess. Any ideas about that?
The text was updated successfully, but these errors were encountered: