79089980

Date: 2024-10-15 12:45:51
Score: 1
Natty:
Report link

I had a slightly similar question which I tested out.

My conclusion: nullable and optional fileds are the same.

I thought if a schema have an optional avro field (a field defining a default value) than it can accept records which are not defining that field. And I thought if a schema have a nullable avro field (a field which type is something or null) than it can accept records which have a null value for that field.

My tests resulted the following: if your record not provide a nullable, non-optional field with a null or other type of value, it will cause an exception, which is what I was expecting. If you provide a null value to an optional non-nullable field, it will not cause an exception thus, optionality make the field nullable, but nullability doesnt cause optionality as a default value is not defined.

In your use-case if the specific field is not present in the record, than the default null value will be used as its value.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: LACCI