Hi,
Hi,
Please go through the union type default behaviour. It says you can define
default for union type with first type of union value. Hence you defined map as
first union type you must define default value with map type. Otherwise you can
change the schema like below for your requirements.
Schema :
> {
> "type": "record",
> "name": “my_record",
> "fields": [
> {
> "name": "work_sample",
> "type": [
“null”,
> {
> "type": "map",
> "values": "long"
> }
> ],
> "default": null
> }
> ]
> }
Hope this will help you.
For more details:
https://avro.apache.org/docs/1.8.1/spec.html#Unions
Sent from my iPhone
> On 17-Dec-2018, at 1:25 PM, Oded Zahavi <[email protected]> wrote:
>
> Hi,
>
> I’m working with Avro Turf which in turn works with Avro. Currently using
> version 1.8.2. I have the following schema:
> {
> "type": "record",
> "name": “my_record",
> "fields": [
> {
> "name": "work_sample",
> "type": [
> {
> "type": "map",
> "values": "long"
> },
> "null"
> ],
> "default": null
> }
> ]
> }
>
> and I am trying to read the following data with this schema:
> {
> "id": 457604,
> "updated_at": 1531640762,
> "is_allowed": true
> }
>
> Since I have default null, I expected to get
> {"work_sample":null}
>
> However, what I get is an error. This seems to work as expected for the array
> case. It looks like since in the array case a type check is done before,
> allowing it to receive null values and apply the default. I fixed this
> locally and it looks okay. I have opened a pull request I’d love you guys to
> have a look:
> https://github.com/apache/avro/pull/403/files
> <https://github.com/apache/avro/pull/403/files>
>
> Thanks,
> Oded Zahavi