clesaec commented on code in PR #1922:
URL: https://github.com/apache/avro/pull/1922#discussion_r1017528708
##########
lang/java/avro/src/main/java/org/apache/avro/Schema.java:
##########
@@ -1637,30 +1665,26 @@ private static boolean isValidDefault(Schema schema,
JsonNode defaultValue) {
return defaultValue.isNumber();
case BOOLEAN:
return defaultValue.isBoolean();
- case NULL:
- return defaultValue.isNull();
case ARRAY:
if (!defaultValue.isArray())
return false;
for (JsonNode element : defaultValue)
- if (!isValidDefault(schema.getElementType(), element))
+ if (!schema.getElementType().isValidValue(element))
return false;
return true;
case MAP:
if (!defaultValue.isObject())
return false;
for (JsonNode value : defaultValue)
- if (!isValidDefault(schema.getValueType(), value))
+ if (!schema.getValueType().isValidValue(value))
return false;
return true;
- case UNION: // union default: first branch
- return isValidDefault(schema.getTypes().get(0), defaultValue);
Review Comment:
static method isValidDefault (line 1650 on new version) is private, called
by new virtual function "public boolean isValidValue(final Object value) {",
line 1645.
This function is redefine for NULL Schema (line 1387) and for union schema
(line 1248).
May be the main flaw of this PR is to keep the static isValidDefault method
and not build function isValidValue for each schema type, but it also would
duplicate code for STRING, BYTES, ENUM for example ([See
here](https://github.com/apache/avro/blob/34a76eac6c9c19dd5f52286fc4d3c285e0f6608c/lang/java/avro/src/main/java/org/apache/avro/Schema.java#L1654))).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]