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 with NULL #112

Closed
gpthome opened this issue Mar 22, 2024 · 3 comments · Fixed by #120
Closed

Union with NULL #112

gpthome opened this issue Mar 22, 2024 · 3 comments · Fixed by #120
Assignees

Comments

@gpthome
Copy link

gpthome commented Mar 22, 2024

I'm experimenting with the datacontract CLI. I'm on version 0.9.7. I started by executing the import command on an existing Avro schema.

datacontract import --format avro --source sample.avsc

The import fails on the following definition. At this point, we've decided to support "null" as an option in our data contracts on most data elements. The practice we've seen cited most often is to start a union with "null" as in the example.

        {
            "name": "material",
            "type": [
                "null",
                {
                    "type": "string",
                    "avro.java.string": "String"
                }
            ]
        },

This yields the below error.
image

Again, if I remove the NULL from the union, the parsing moves on successfully.

Is this an issue or are we using it incorrectly?

Thanks.

@simonharrer
Copy link
Contributor

Thanks for reporting this. From a short google search I think your avro format is fine. We should add the functionality to parse optional fields as well. Perhaps @ismailova-n can help as she did the avro import.

@jeeger
Copy link
Collaborator

jeeger commented Mar 25, 2024

Maybe handling "union with null" could even be special cased to translate into an optional field.

@jeeger
Copy link
Collaborator

jeeger commented Mar 26, 2024

At the moment, a data contract has no concept of union types. For now, we would special-case the import of Avro unions with "null" to result in an optional field of the contained type. I believe this is the most common usecase for union types. To support arbitrary unions, we'd have to discuss how to extend the data contract specification.

@ismailova-n ismailova-n self-assigned this Mar 26, 2024
@ismailova-n ismailova-n linked a pull request Mar 28, 2024 that will close this issue
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.

4 participants