Error on optional array of records
See original GitHub issueCode to reproduce:
from fastavro import writer, reader
schema = {
"type": "record",
"name": "test",
"fields": [
{"name": "name", "type": "string"},
{"name": "address",
"type": [
"null",
{"type": "array",
"items": {
"type": "record",
"name": "whatever",
"fields": [
{"name": "street", "type": ["null", "string"]},
{"name": "zip", "type": ["null", "string"]}
]
}
}
]
}
]
}
records = [
{'name': 'name1', 'address': [{'street': '22st'}]},
{'name': 'name2'}
]
with open('test.avro', 'wb') as f:
writer(f, schema, records, codec='deflate')
with open('test.avro', 'rb') as f:
print(list(reader(f)))
If I write record name2
only, no error and reader returns [{'name': 'name2', 'address': None}]
However for name1
where address
is passed (correctly, as a list), it errors out:
...(type <class 'list'>) do not match ['null', {'type': 'array', 'items': {'type': 'record'...
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Top Results From Across the Web
optional array in avro schema - Stack Overflow
I'm wondering whether or not it is possible to have an optional array. Let's assume a schema like this ...
Read more >Cannot generate an Optional array · Issue #8 - GitHub
Problem during code generation: Templating error: Didn't find schema Array(Union(UnionSchema ... Fix for multiple optional arrays #8.
Read more >How can we give Avro array field as optional
You can try this schema, I have attached an image which highlights the fields which are made optional, you can do the changes...
Read more >accept null for record and array in Avro Schema - 네이버 블로그
In the previous post, I've briefly covered how to write a schema using Apache Avro. In this post, I'll cover how to set...
Read more >scatter over optional array - Terra Support
I have a case where I want to iterate over two arrays, one of which shall be optionally ... In the case of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@scottbelden thank you very much for the quick turnaround, for this and the ISO date enh !
I have a PR that resolves this case (and passes all the other tests). I’m pretty sure there are still some aspects that need to be fleshed out with unions and nulls and default values, but I suppose we’ll get to those when the time comes.