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

Incorrect default value for a field with ["string","null"] union type and "null" default value #133

Open
vkorenev opened this issue Mar 24, 2020 · 3 comments

Comments

@vkorenev
Copy link

For the following Avro schema

{
  "type": "record",
  "name": "Item",
  "fields": [
    { "name": "foo", "type": [ "null", "string" ], "default": null },
    { "name": "bar", "type": [ "string", "null" ], "default": "null" },
    { "name": "baz", "type": [ "string", "null" ], "default": "abcd" }
  ]
}

avrohugger generates the following case class:

final case class Item(
  var foo: Option[String] = None,
  var bar: Option[String] = None,
  var baz: Option[String] = Some("abcd")
) extends org.apache.avro.specific.SpecificRecordBase ...

The default values for foo and baz are correct.
However, the default value for bar should be Some("null"), not None.

@nicodv
Copy link

nicodv commented Jun 23, 2020

Expected, as the default value of a union corresponds to its first element, see this answer: https://stackoverflow.com/a/23387590/1571826

@vkorenev
Copy link
Author

@nicodv, no, this is not expected. The first type of the union for "bar" is string, so the default value should be string as well.

@nicodv
Copy link

nicodv commented Jun 24, 2020

My bad, was looking at “foo”.

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

2 participants