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

ISSUE-633 : Fix error when creating a schema with field that is nullable but with default value #636

Merged
merged 2 commits into from
Dec 6, 2019

Conversation

raju-saravanan
Copy link
Collaborator

Fixes #633


for (Schema.Field field : fields) {
Schema fieldSchema = field.schema();
// check for union

boolean currentFieldTypeIsUnion = fieldSchema.getType() == Schema.Type.UNION;
Object defaultValue = field.defaultVal();
if (currentFieldTypeIsUnion) {
// check for the fields with in union
// if it is union and first type is null then set default value as null
if (fieldSchema.getTypes().get(0).getType() == Schema.Type.NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it assumed or guaranteed that null type comes first?

Copy link
Contributor

@guruchai guruchai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extending the example given in the Issue

  1. If geoAddress is null at serializer side, what do you get on deserialization for geoAddress?
  2. If geoAddress is not set at all on serializer side, what do you get on deserialization for geoAddress?

Can you add unit tests around this?

@raju-saravanan
Copy link
Collaborator Author

@guruchai : I have test to check if avro schema resolver is taking defaults for unions

@guruchai
Copy link
Contributor

guruchai commented Dec 6, 2019

LGTM....

@guruchai guruchai merged commit 0c1e536 into master Dec 6, 2019
raju-saravanan added a commit that referenced this pull request Dec 6, 2019
…ble but with default value (#636)

*   ISSUE-633 : Fix error when creating a schema with field that is nullable but with default value

*   Add test cases to check schema registry is parsing the unions with defaults correctly
gkomlossi pushed a commit that referenced this pull request Jun 24, 2021
…ble but with default value (#636)

*   ISSUE-633 : Fix error when creating a schema with field that is nullable but with default value

*   Add test cases to check schema registry is parsing the unions with defaults correctly
gkomlossi pushed a commit that referenced this pull request Jun 24, 2021
…hat is nullable but with default value (#636)

*   ISSUE-633 : Fix error when creating a schema with field that is nullable but with default value

*   Add test cases to check schema registry is parsing the unions with defaults correctly
pnagy-cldr pushed a commit that referenced this pull request Sep 30, 2021
…hat is nullable but with default value (#636)

*   ISSUE-633 : Fix error when creating a schema with field that is nullable but with default value

*   Add test cases to check schema registry is parsing the unions with defaults correctly
gkomlossi pushed a commit that referenced this pull request Dec 16, 2021
…hat is nullable but with default value (#636)

*   ISSUE-633 : Fix error when creating a schema with field that is nullable but with default value

*   Add test cases to check schema registry is parsing the unions with defaults correctly
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

Successfully merging this pull request may close these issues.

Error when creating a schema in schema registry with field that is nullable but with default value
2 participants