Skip to content

Commit

Permalink
Default for a node can be processed if its type is union and first el…
Browse files Browse the repository at this point in the history
…ement of union is resolved.
  • Loading branch information
li-ukumar committed Feb 2, 2024
1 parent 9487a8b commit 1a273ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ public void resolveReferences() {
fieldsWithUnparsedDefaults.add(field);
continue;
}
AvscParseUtil.lateParseFieldDefault(field, parseResult.getContext());
if (field.hasDefaultValue() && field.getDefaultValue() instanceof AvscUnparsedLiteral) {
AvscParseUtil.lateParseFieldDefault(field, parseResult.getContext());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ private AvroNamedSchema parseNamedSchema(
}
AvroLiteral defaultValue = null;
if (fieldDefaultValueNode != null) {
if (fieldSchema.isFullyDefined()) {
// To parse the default value, the schema should be fully defined
// or if field schema is a union, the first type in the union should be fully defined
if (fieldSchema.isFullyDefined() || (fieldSchema.getRef() == null
&& fieldSchema.getSchema().type() == AvroType.UNION
&& ((AvroUnionSchema) fieldSchema.getSchema()).getTypes().get(0).isFullyDefined())) {
AvroSchema defaultValueExpectedSchema = fieldSchema.getSchema();
if (defaultValueExpectedSchema.type() == AvroType.UNION) {
//(legal) default values are expected to match the 1st union branch
Expand Down

0 comments on commit 1a273ef

Please sign in to comment.