Skip to content
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

Support for Union-Types (Serde, Schemas, Avro-Values) #76

Closed

Conversation

RGafiyatullin
Copy link

@RGafiyatullin RGafiyatullin commented Mar 14, 2019

Difference between the Value::Union representation this PR and @kphelps 's one: Value::Union(variant_index: usize, variant_value: Box<Value>) instead of Value::Union(union_ref: UnionRef, variant_value: Box<Value>).

This option does not allow for creation of union-type instance from the inner variant-value "implicitly" (i.e. without knowing the variant-index able to carry that exact variant-data).
This should help a lot with Serde because this restriction allows "lossless" translations between Structs<->Avro-Values<->Avro-Binary in both directions.

Example of usage: https://gist.github.com/RGafiyatullin/4fec518e3cd8e3c6fe718ca976a4cdc5
Output: https://gist.github.com/RGafiyatullin/8aaf4c427bec5456edde2e0913dde472

@RGafiyatullin RGafiyatullin changed the title Support union-types Support union-types (multiple named record variants) Mar 14, 2019
@RGafiyatullin RGafiyatullin changed the title Support union-types (multiple named record variants) Support for Union-Types (Serde, Schemas, Avro-Values — the lot) Mar 15, 2019
@RGafiyatullin RGafiyatullin changed the title Support for Union-Types (Serde, Schemas, Avro-Values — the lot) Support for Union-Types (Serde, Schemas, Avro-Values) Mar 15, 2019
Copy link
Owner

@flavray flavray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good overall, just a comment :)

src/types.rs Outdated
.find_schema(&v)
.ok_or_else(|| SchemaResolutionError::new("Could not find matching type in union"))?;
v.resolve(inner)
match self {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this code is missing the resolution when the writer value is not a union but reader is a union.

e.g: writer writes a Long, reader is Union(Null, Long), then resolve_union should output a Union(1, Value::Long)

See the "if reader's is a union, but writer's is not" section in https://avro.apache.org/docs/1.8.2/spec.html#Schema+Resolution

Copy link
Author

@RGafiyatullin RGafiyatullin Mar 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Standard relies on availability of both writer- and reader-schema for resolution.
So I believe the signature of the method should go as pub(crate) fn resolve(reader_schema, writer_schema) -> Result<Value, Error>.
The only usage of the method is pub fn from_avro_datum<R: Read>. I think it only would be right to remove the method value.resolve from the public API.

…o create a union-schema other than parsing a string
@nlopes
Copy link
Contributor

nlopes commented Sep 2, 2019

Any movement on this? I have an incoming PR for Schema Compatibility that would gain a bit by having this PR in.

@CtrlC-Root
Copy link

I would also benefit from having this work merged. Is there anything I can do to help?

@poros
Copy link
Collaborator

poros commented Jan 14, 2020

There is also #60 implementing bits and pieces of the same feature in a slightly different way and both PRs are pretty old... (definitely because of the fault of us maintainers).

I'll need to budget some time to properly understand how serde handles enums (tonight I only managed to read the serialization half of the data format) and at the same time follow up with the authors to understand who is still interested in contributing.

@RGafiyatullin are you still interested in contributing? Shall we try to revitalize this PR? I asked the same thing to @jdeschenes on #60.

@poros poros self-requested a review January 14, 2020 22:40
@poros
Copy link
Collaborator

poros commented Jun 7, 2020

I believe that #110 landed the same feature of this PR only in a slightly different form. Closing for now, but please feel free to open a new one based on current master in case there is still something missing that you'd like to see added.

@poros poros closed this Jun 7, 2020
martin-g added a commit to martin-g/avro that referenced this pull request Sep 22, 2021
Documenting avro-rs v0.14.0 (/home/martin/git/apache/avro/lang/rust)
warning: this URL is not a hyperlink
   --> src/lib.rs:696:5
    |
696 | //! flavray/avro-rs#76).
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://github.com/flavray/avro-rs/pull/76>`
    |
    = note: `#[warn(rustdoc::bare_urls)]` on by default
    = note: bare URLs are not automatically turned into clickable links
martin-g added a commit to apache/avro that referenced this pull request Jan 5, 2022
* AVRO-3205 Update Cargo.toml [package] information

* AVRO-3205 Fix 'cargo doc` warning

Documenting avro-rs v0.14.0 (/home/martin/git/apache/avro/lang/rust)
warning: this URL is not a hyperlink
   --> src/lib.rs:696:5
    |
696 | //! flavray/avro-rs#76).
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://github.com/flavray/avro-rs/pull/76>`
    |
    = note: `#[warn(rustdoc::bare_urls)]` on by default
    = note: bare URLs are not automatically turned into clickable links

* AVRO-3205 Add keywords and documentation to [package]

* AVRO-3205 Add categories = ["encoding"]

* AVRO-3205 Update markdown files

Replace flavray/avro-rs with apache/avro.
Replace MIT license with Apache License 2
martin-g added a commit to apache/avro that referenced this pull request Feb 1, 2022
* AVRO-3205 Update Cargo.toml [package] information

* AVRO-3205 Fix 'cargo doc` warning

Documenting avro-rs v0.14.0 (/home/martin/git/apache/avro/lang/rust)
warning: this URL is not a hyperlink
   --> src/lib.rs:696:5
    |
696 | //! flavray/avro-rs#76).
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://github.com/flavray/avro-rs/pull/76>`
    |
    = note: `#[warn(rustdoc::bare_urls)]` on by default
    = note: bare URLs are not automatically turned into clickable links

* AVRO-3205 Add keywords and documentation to [package]

* AVRO-3205 Add categories = ["encoding"]

* AVRO-3205 Update markdown files

Replace flavray/avro-rs with apache/avro.
Replace MIT license with Apache License 2

(cherry picked from commit ea07ac0)
martin-g added a commit to apache/avro that referenced this pull request Feb 3, 2022
Remove a link to an issue/PR at flavray/avro-rs/pull/76 because it is
already resolved. Enable (uncomment) the tests related to this issue.

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
martin-g added a commit to apache/avro that referenced this pull request Feb 3, 2022
Remove a link to an issue/PR at flavray/avro-rs/pull/76 because it is
already resolved. Enable (uncomment) the tests related to this issue.

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
(cherry picked from commit 69fda12)
martin-g added a commit to apache/avro-rs that referenced this pull request Sep 23, 2024
* AVRO-3205 Update Cargo.toml [package] information

* AVRO-3205 Fix 'cargo doc` warning

Documenting avro-rs v0.14.0 (/home/martin/git/apache/avro/lang/rust)
warning: this URL is not a hyperlink
   --> src/lib.rs:696:5
    |
696 | //! flavray/avro-rs#76).
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://github.com/flavray/avro-rs/pull/76>`
    |
    = note: `#[warn(rustdoc::bare_urls)]` on by default
    = note: bare URLs are not automatically turned into clickable links

* AVRO-3205 Add keywords and documentation to [package]

* AVRO-3205 Add categories = ["encoding"]

* AVRO-3205 Update markdown files

Replace flavray/avro-rs with apache/avro.
Replace MIT license with Apache License 2
martin-g added a commit to apache/avro-rs that referenced this pull request Sep 23, 2024
Remove a link to an issue/PR at flavray/avro-rs/pull/76 because it is
already resolved. Enable (uncomment) the tests related to this issue.

Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants