question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error on optional array of records

See original GitHub issue

Code 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:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
yan-hiccommented, May 7, 2019

@scottbelden thank you very much for the quick turnaround, for this and the ISO date enh !

1reaction
scottbeldencommented, May 6, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found