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

cmd/go2avro: Struct default values differ from their type.fields defaults #70

Closed
spaceweasel opened this issue Apr 6, 2020 · 1 comment

Comments

@spaceweasel
Copy link

When a go struct has a slice or time field, the Avro defaults defined within each of the fields are [] and 0 respectively. However, the top-level struct default values are null and "0001-01-01T00:00:00Z"

A test to illustrate:

go2avro X
cmp stdout expect-stdout

go2avro example.com/foo/bar.X
cmp stdout expect-stdout

-- expect-stdout --
{
    "default": {
        "S": [],
        "T": 0
    },
    "fields": [
        {
            "default": [],
            "name": "S",
            "type": {
                "items": "string",
                "type": "array"
            }
        },
        {
            "default": 0,
            "name": "T",
            "type": {
                "logicalType": "timestamp-micros",
                "type": "long"
            }
        }
    ],
    "name": "X",
    "type": "record"
}
-- bar.go --
package bar

import "time"

type X struct {
  S []string
  T time.Time
}

-- go.mod --
module example.com/foo/bar

go 1.14

require github.com/heetch/avro v0.0.0-20200318154341-de261c0e4b7f // indirect
}
  > cmp stdout expect-stdout
  [diff -stdout +expect-stdout]
    {
        "fields": [
            {
                "default": {
  -                "S": null,
  -                "T": "0001-01-01T00:00:00Z"
  +                "S": [],
  +                "T": 0
                },
                "name": "C",
                "type": {
                    "fields": [
                        {
                            "default": [],
                            "name": "S",
                            "type": {
                                "items": "string",
                                "type": "array"
                            }
                        },
                        {
                            "default": 0,
                            "name": "T",
                            "type": {
                                "logicalType": "timestamp-micros",
                                "type": "long"
                            }
                        }
                    ],
                    "name": "C",
                    "type": "record"
                }
            }
        ],
        "name": "P",
        "type": "record"
    }

Not sure if this is related to #37

@spaceweasel
Copy link
Author

Underlying issue same as #37

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

No branches or pull requests

1 participant