Repository navigation
Conversation
|
@LucasJavaudin Could you please review the new unit tests ? Thanks! |
8bcf5c4 to
9299438
Compare
|
Converted to Draft because as the JIRA ticket explains the produced |
Yes, this is good! |
|
Can I push to this Draft a test that do not pass but that I think should pass? |
Is it ?
|
Only Avro project committers can push to this repository. You will have to open a PR against the branch for this PR. |
Sorry, I meant that the test are useful and they currently pass but I agree that they should not pass.
For unit variant, shouldn't it be |
|
There might be more than one unit variants in the enum. I think it should be |
|
Consider the following enum: What should be its schema? I can think of two options. A record with two fields
The union cannot be Can it be just An unionWith the enum |
4d2f191 to
806b355
Compare
|
@LucasJavaudin I think the PR is ready for final review! |
|
The avro_derive tests fail ... |
|
@martin-g Thank you for your work! This solves the issue I raised in AVRO-3646. I pushed two new integration tests in #1949 that try to deserialize and serialize more complex enums. The tests do not pass for multiple reasons. I think that would improve greatly the library if we could (de)serialize arbitrary enums (and even derive a schema for them) but maybe this needs to much work? Unfortunately, I don't have enough time myself to do more than adding tests and reviewing your changes. |
The problem here is that another user (@jklamer, the contributor of the avro_derive crate) expects that #[derive(Debug, Deserialize, Serialize, AvroSchema, Clone, PartialEq, Eq)]
enum MyEnum {
Foo,
Bar,
Baz,
}should map to this Avro schema: Which is really nice! But unfortunately does not work anymore with the new way of supporting complex Rust enums (ones with non-null tuple/newtype/struct variants). The only way to still support the above I see is to introduce a second Also CC @spiegela |
|
Yeah, this conversation is split over a couple different PR's, threads, and e-mails. But I'll respond here. With My bias would be to create a Macro that creates an intermediate form that is unambiguously convertible between Rust Enum and an Avro compatible entity and do the conversion before serialization and after deserialization (don't try to make serde process work outside the avro spec) (and could point to macro in the AvroSchema derive error), but I personally haven't been able to think of a solution that works for every case. Rust's type system is just most expansive that Avro's, so the ambiguity is inevitable at some level. That being said, I LOVE Rust enums, with a passion, and when I realized I couldn't automatically serde them... I started something that could. <-- me shaving the yak. TLDR: I think it's impossible to do automatically without creating ambiguity that I would like to shield most users from. I think doing it as an opt in with clearly defined restrictions (and good error messages) would be a good to go for advanced users. CC @spiegela |
|
I wonder whether we can use https://serde.rs/enum-representations.html#untagged to give a hint to apache_avro (de)serialization process to keep the old behavior. |
|
Actually it doesn't need to be |
|
@martin-g hahaha agreed. And now with Java Sealed classes, a pretty clear Rust Enum 1-1 could be made too! |
|
Another user asked for the same functionality at serde-rs/serde#2309 |
|
To make sure I understand the status of change, is the remaining question here how the AvroSchema derive should ”choose” which enum format to use when constructing the schema? If so, I was thinking that the AvroSchema derive could infer the correct behavior based on the variant characteristics:
That leaves the case of non-unit, multi-field, unnamed fields 😅. For those, we should return a compile error, I think, and let the dev implement |
|
The actual problem in ser.rs and de.rs. The new serde logic is powerful enough to handle complex kinds of Rust enums (by using Schema::Record([Schema::Enum, Schema::Union])). But it does not support the old representation (Schema::Enum) because all variants are mapped to Value::Null and there could be at most one The logic what schema to derive looks like a simpler task (although I haven't tried it yet, so I might be wrong). |
These improvements were identified while working on AVRO-3646 but they are not related to the changes related to this ticket. This commit was part of #1921 Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
These improvements were identified while working on AVRO-3646 but they are not related to the changes related to this ticket. This commit was part of #1921 Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
These improvements were identified while working on AVRO-3646 but they are not related to the changes related to this ticket. This commit was part of #1921 Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> (cherry picked from commit 0ea0dcc)
…f variants Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
…ent variants Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Also do schema validation on the produced avro values Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
…ith nullable struct_variant Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
…ariants (#1949) * AVRO-3646: Add a test that (de)serialize a enum with mixed variants * AVRO-3646: Add a test that (de)serialize a enum w/ duplicates variants * Enable PR checks for all PRs, not just the ones against master Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> * AVRO-3646: Fix a clippy error about enum variant being postfixed with 'Variant' Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> * AVRO-3646: Fix the serialization (X -> types::Value) for enum tuple variants Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> * AVRO-3646: Fix the name of the enum variants in the Avro schema Rename the test method to be different than the one in serde_enum.rs IT tests. Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> * AVRO-3646: Remove the duplicates to conform to Avro specification A Union could have at most one item for a primitive type Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> * AVRO-3646: Remove dbg!() statement. Fix clippy errors Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> Co-authored-by: LucasJavaudin <[email protected]> Co-authored-by: Martin Tzvetanov Grigorov <[email protected]>
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
d61f529 to
c17bddb
Compare
These improvements were identified while working on AVRO-3646 but they are not related to the changes related to this ticket. This commit was part of apache/avro#1921 Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
|
Seems like AVRO-3695 should be addressed in this issue. (see #2035) However I just tested it against Master + AVRO-3631 and it does not address the problem. This is my last blocking issue for using Rust for our industry protocol, so hoping it can be looked at. @martin-g ? I've created what is probably a 'Hack' fix that addresses the issue for me. But honestly I'm not sure what i'm doing here, so it likley breaks other stuff. (So I havn't made a PR, just added here for your info) ser.rs. line # 260 or so |
These improvements were identified while working on AVRO-3646 but they are not related to the changes related to this ticket. This commit was part of apache/avro#1921 Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
|
Hi @martin-g |
|
@mati865, the Rust code has been moved from https://github.com/apache/avro to https://github.com/apache/avro-rs so I guess a new pull request with these changes should be opened there. |
|
@KalleOlaviNiemitalo I'm aware of that, but it would be impolite to copy changes from someone's branch without asking first. |
|
Any help is welcome! |
|
I've played with this code for a few hours now, and I think I finally understand at least some problems. When it comes to simple vs complex enums handling, Serde is too generic and doesn't allow distinguishing between Enum variants with or without values. But for Avro the difference is quite significant. If we take this code: enum One {
A,
B
}
enum Two {
A,
B(String)
}
enum Three {
A(i32),
B(String)
}
// And all other gazillion variationsSerde will straight call An obvious way to solve it, although not very convenient, would be to create an attribute or derive proc-macro that generates serializer and deserializer for enums since proc-macros can get all the required information. Maybe Serde feature that would help here could be requested from, but I don't know if it's even possible to introduce such a significant change at this point. I think the other issues like the ones mentioned in #1921 (comment) are at least in some part caused by this "simple vs complex enums handling". |
I am pretty sure that such additions to serde(**) would be rejected! |
Feel free to experiment and send a PR for discussion! |
|
Sorry for the late reply. All my attempts eventually more or less resulted in rewriting serde, or parts of it. The most reasonable solution seems to be what Borsh did by creating their own serialization framework: https://github.com/near/borsh-rs/tree/master/borsh-derive They both require enormous implementation effort, though. I won't be able to dedicate so much time to it. |
These improvements were identified while working on AVRO-3646 but they are not related to the changes related to this ticket. This commit was part of apache#1921 Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
What is the purpose of the change
Verifying this change
This change just adds unit tests
Documentation