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

Union types should allow "null" in any position #39

Closed
chupaty opened this issue Sep 7, 2022 · 3 comments
Closed

Union types should allow "null" in any position #39

chupaty opened this issue Sep 7, 2022 · 3 comments

Comments

@chupaty
Copy link

chupaty commented Sep 7, 2022

Using the following schema:

{
    "type": "record",
    "name": "test",
    "fields": [
        {"name": "a", "type": ["long","null"] }
    ]
}

rsgen-avro errors with:

Templating error: Invalid Schema::Null not in first position on an UnionSchema variants

I don't see a requirement in the avro spec about this (we do have additional requirements when we have a default value, but this doesn't apply here).

@martin-g
Copy link
Contributor

martin-g commented Sep 7, 2022

I think the reason for the current implementation is the following text from the spec: Thus, for unions containing “null”, the “null” is usually listed first, since the default value of such unions is typically null.

But I agree that it could be improved to support your use case. And the spec says usually, not mandatory.

I will send a PR!

martin-g added a commit to martin-g/rsgen-avro that referenced this issue Sep 7, 2022
Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
martin-g added a commit to martin-g/rsgen-avro that referenced this issue Sep 7, 2022
Signed-off-by: Martin Tzvetanov Grigorov <mgrigorov@apache.org>
@lerouxrgd
Copy link
Owner

This crate will make the conservative approach of using "null" only in first position as otherwise things get really too complicated.

@lerouxrgd
Copy link
Owner

lerouxrgd commented Apr 17, 2023

(Although this can be reconsidered later, when the spec is clearer, and when it's supported in apache-avro etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants