github-advanced-security[bot] commented on code in PR #2642:
URL: https://github.com/apache/avro/pull/2642#discussion_r1463492814
##########
lang/java/avro/src/main/java/org/apache/avro/Schema.java:
##########
@@ -1867,267 +1780,187 @@
}
}
- /**
- * Parse named schema in order to fill names map. This method does not parse
- * field of record/error schema.
- *
- * @param schema : json schema representation.
- * @param names : map of named schema.
- * @param currentNameSpace : current working name space.
- * @return schema.
- */
- static Schema parseNamesDeclared(JsonNode schema, Names names, String
currentNameSpace) {
+ /** @see #parse(String) */
+ static Schema parse(JsonNode schema, ParseContext context, String
currentNameSpace) {
if (schema == null) {
- return null;
- }
- if (schema.isObject()) {
-
- String type = Schema.getOptionalText(schema, "type");
- Name name = null;
-
- String doc = null;
- Schema result = null;
+ throw new SchemaParseException("Cannot parse <null> schema");
+ } else if (schema.isTextual()) { // name
+ return context.find(schema.textValue(), currentNameSpace);
+ } else if (schema.isObject()) {
+ String type = getRequiredText(schema, "type", "No type");
final boolean isTypeError = "error".equals(type);
- final boolean isTypeRecord = "record".equals(type);
- final boolean isTypeEnum = "enum".equals(type);
- final boolean isTypeFixed = "fixed".equals(type);
-
- if (isTypeRecord || isTypeError || isTypeEnum || isTypeFixed) {
- String space = getOptionalText(schema, "namespace");
- doc = getOptionalText(schema, "doc");
- if (space == null)
- space = currentNameSpace;
- name = new Name(getRequiredText(schema, "name", "No name in schema"),
space);
- }
- if (isTypeRecord || isTypeError) { // record
- result = new RecordSchema(name, doc, isTypeError);
- names.add(result);
- JsonNode fieldsNode = schema.get("fields");
-
- if (fieldsNode == null || !fieldsNode.isArray())
- throw new SchemaParseException("Record has no fields: " + schema);
- exploreFields(fieldsNode, names, name != null ? name.space : null);
-
- } else if (isTypeEnum) { // enum
- JsonNode symbolsNode = schema.get("symbols");
- if (symbolsNode == null || !symbolsNode.isArray())
- throw new SchemaParseException("Enum has no symbols: " + schema);
- LockableArrayList<String> symbols = new
LockableArrayList<>(symbolsNode.size());
- for (JsonNode n : symbolsNode)
- symbols.add(n.textValue());
- JsonNode enumDefault = schema.get("default");
- String defaultSymbol = null;
- if (enumDefault != null)
- defaultSymbol = enumDefault.textValue();
- result = new EnumSchema(name, doc, symbols, defaultSymbol);
- names.add(result);
+ if (PRIMITIVES.containsKey(type)) { // primitive
+ return parsePrimitive(schema, type);
+ } else if ("record".equals(type) || isTypeError) { // record
+ return parseRecord(schema, context, currentNameSpace, isTypeError);
+ } else if ("enum".equals(type)) { // enum
+ return parseEnum(schema, context, currentNameSpace);
} else if (type.equals("array")) { // array
- JsonNode itemsNode = schema.get("items");
- if (itemsNode == null)
- throw new SchemaParseException("Array has no items type: " + schema);
- final Schema items = Schema.parseNamesDeclared(itemsNode, names,
currentNameSpace);
- result = Schema.createArray(items);
+ return parseArray(schema, context, currentNameSpace);
} else if (type.equals("map")) { // map
- JsonNode valuesNode = schema.get("values");
- if (valuesNode == null)
- throw new SchemaParseException("Map has no values type: " + schema);
- final Schema values = Schema.parseNamesDeclared(valuesNode, names,
currentNameSpace);
- result = Schema.createMap(values);
- } else if (isTypeFixed) { // fixed
- JsonNode sizeNode = schema.get("size");
- if (sizeNode == null || !sizeNode.isInt())
- throw new SchemaParseException("Invalid or no size: " + schema);
- result = new FixedSchema(name, doc, sizeNode.intValue());
- if (name != null)
- names.add(result);
- } else if (PRIMITIVES.containsKey(type)) {
- result = Schema.create(PRIMITIVES.get(type));
+ return parseMap(schema, context, currentNameSpace);
+ } else if ("fixed".equals(type)) { // fixed
+ return parseFixed(schema, context, currentNameSpace);
+ } else { // For unions with self reference
+ return context.find(type, currentNameSpace);
}
- if (result != null) {
- Set<String> reserved = SCHEMA_RESERVED;
- if (isTypeEnum) {
- reserved = ENUM_RESERVED;
- }
- Schema.addProperties(schema, reserved, result);
- }
- return result;
- } else if (schema.isArray()) {
- List<Schema> subs = new ArrayList<>(schema.size());
- schema.forEach((JsonNode item) -> {
- Schema sub = Schema.parseNamesDeclared(item, names, currentNameSpace);
- if (sub != null) {
- subs.add(sub);
- }
- });
- return Schema.createUnion(subs);
- } else if (schema.isTextual()) {
- String value = schema.asText();
- return names.get(value);
+ } else if (schema.isArray()) { // union
+ return parseUnion(schema, context, currentNameSpace);
+ } else {
+ throw new SchemaParseException("Schema not yet supported: " + schema);
}
- return null;
}
- private static void addProperties(JsonNode schema, Set<String> reserved,
Schema avroSchema) {
- Iterator<String> i = schema.fieldNames();
- while (i.hasNext()) { // add properties
- String prop = i.next();
- if (!reserved.contains(prop)) // ignore reserved
- avroSchema.addProp(prop, schema.get(prop));
- }
- // parse logical type if present
- avroSchema.logicalType = LogicalTypes.fromSchemaIgnoreInvalid(avroSchema);
- // names.space(savedSpace); // restore space
- if (avroSchema instanceof NamedSchema) {
- Set<String> aliases = parseAliases(schema);
- if (aliases != null) // add aliases
- for (String alias : aliases)
- avroSchema.addAlias(alias);
- }
+ private static Schema parsePrimitive(JsonNode schema, String type) {
+ Schema result = create(PRIMITIVES.get(type));
+ parseProperties(schema, result, SCHEMA_RESERVED);
+ return result;
}
- /**
- * Explore record fields in order to fill names map with inner defined named
- * types.
- *
- * @param fieldsNode : json node for field.
- * @param names : names map.
- * @param nameSpace : current working namespace.
- */
- private static void exploreFields(JsonNode fieldsNode, Names names, String
nameSpace) {
+ private static Schema parseRecord(JsonNode schema, ParseContext context,
String currentNameSpace,
+ boolean isTypeError) {
+ Name name = parseName(schema, currentNameSpace);
+ String doc = parseDoc(schema);
+ Schema result = new RecordSchema(name, doc, isTypeError);
+ context.put(result);
+
+ JsonNode fieldsNode = schema.get("fields");
+ if (fieldsNode == null || !fieldsNode.isArray())
+ throw new SchemaParseException("Record has no fields: " + schema);
+ List<Field> fields = new ArrayList<>();
for (JsonNode field : fieldsNode) {
- final JsonNode fieldType = field.get("type");
- if (fieldType != null) {
- if (fieldType.isObject()) {
- parseNamesDeclared(fieldType, names, nameSpace);
- } else if (fieldType.isArray()) {
- exploreFields(fieldType, names, nameSpace);
- } else if (fieldType.isTextual() && field.isObject()) {
- parseNamesDeclared(field, names, nameSpace);
- }
- }
+ Field f = parseField(field, context, name.space);
+ fields.add(f);
+ if (f.schema().getLogicalType() == null && getOptionalText(field,
LOGICAL_TYPE_PROP) != null)
+ LOG.warn(
+ "Ignored the {}.{}.logicalType property (\"{}\"). It should
probably be nested inside the \"type\" for the field.",
+ name, f.name(), getOptionalText(field, "logicalType"));
}
+ result.setFields(fields);
+ parseProperties(schema, result, SCHEMA_RESERVED);
+ parseAliases(schema, result);
+ return result;
}
- /**
- * in complement of parseNamesDeclared, this method parse schema in details.
- *
- * @param schema : json schema.
- * @param names : names map.
- * @param currentSpace : current working name space.
- * @return complete schema.
- */
- static Schema parseCompleteSchema(JsonNode schema, Names names, String
currentSpace) {
- if (schema == null) {
- throw new SchemaParseException("Cannot parse <null> schema");
- }
- if (schema.isTextual()) {
- String type = schema.asText();
- Schema avroSchema = names.get(type);
- if (avroSchema == null) {
- avroSchema = names.get(currentSpace + "." + type);
- }
- return avroSchema;
- }
- if (schema.isArray()) {
- List<Schema> schemas = StreamSupport.stream(schema.spliterator(), false)
- .map((JsonNode sub) -> parseCompleteSchema(sub, names,
currentSpace)).collect(Collectors.toList());
- return Schema.createUnion(schemas);
- }
- if (schema.isObject()) {
- Schema result = null;
- String type = getRequiredText(schema, "type", "No type");
- Name name = null;
+ private static Field parseField(JsonNode field, ParseContext context, String
namespace) {
+ String fieldName = getRequiredText(field, "name", "No field name");
+ String fieldDoc = parseDoc(field);
+ JsonNode fieldTypeNode = field.get("type");
+ if (fieldTypeNode == null)
+ throw new SchemaParseException("No field type: " + field);
+ Schema fieldSchema = parse(fieldTypeNode, context, namespace);
- final boolean isTypeError = "error".equals(type);
- final boolean isTypeRecord = "record".equals(type);
- final boolean isTypeArray = "array".equals(type);
+ Field.Order order = Field.Order.ASCENDING;
+ JsonNode orderNode = field.get("order");
+ if (orderNode != null)
+ order =
Field.Order.valueOf(orderNode.textValue().toUpperCase(Locale.ENGLISH));
- if (isTypeRecord || isTypeError || "enum".equals(type) ||
"fixed".equals(type)) {
- // named schema
- String space = getOptionalText(schema, "namespace");
+ JsonNode defaultValue = field.get("default");
+ if (defaultValue != null && (Type.FLOAT.equals(fieldSchema.getType()) ||
Type.DOUBLE.equals(fieldSchema.getType()))
+ && defaultValue.isTextual())
+ defaultValue = new
DoubleNode(Double.parseDouble(defaultValue.textValue()));
Review Comment:
## Missing catch of NumberFormatException
Potential uncaught 'java.lang.NumberFormatException'.
[Show more
details](https://github.com/apache/avro/security/code-scanning/3176)
##########
lang/java/avro/src/main/java/org/apache/avro/Schema.java:
##########
@@ -1867,267 +1780,187 @@
}
}
- /**
- * Parse named schema in order to fill names map. This method does not parse
- * field of record/error schema.
- *
- * @param schema : json schema representation.
- * @param names : map of named schema.
- * @param currentNameSpace : current working name space.
- * @return schema.
- */
- static Schema parseNamesDeclared(JsonNode schema, Names names, String
currentNameSpace) {
+ /** @see #parse(String) */
+ static Schema parse(JsonNode schema, ParseContext context, String
currentNameSpace) {
if (schema == null) {
- return null;
- }
- if (schema.isObject()) {
-
- String type = Schema.getOptionalText(schema, "type");
- Name name = null;
-
- String doc = null;
- Schema result = null;
+ throw new SchemaParseException("Cannot parse <null> schema");
+ } else if (schema.isTextual()) { // name
+ return context.find(schema.textValue(), currentNameSpace);
+ } else if (schema.isObject()) {
+ String type = getRequiredText(schema, "type", "No type");
final boolean isTypeError = "error".equals(type);
- final boolean isTypeRecord = "record".equals(type);
- final boolean isTypeEnum = "enum".equals(type);
- final boolean isTypeFixed = "fixed".equals(type);
-
- if (isTypeRecord || isTypeError || isTypeEnum || isTypeFixed) {
- String space = getOptionalText(schema, "namespace");
- doc = getOptionalText(schema, "doc");
- if (space == null)
- space = currentNameSpace;
- name = new Name(getRequiredText(schema, "name", "No name in schema"),
space);
- }
- if (isTypeRecord || isTypeError) { // record
- result = new RecordSchema(name, doc, isTypeError);
- names.add(result);
- JsonNode fieldsNode = schema.get("fields");
-
- if (fieldsNode == null || !fieldsNode.isArray())
- throw new SchemaParseException("Record has no fields: " + schema);
- exploreFields(fieldsNode, names, name != null ? name.space : null);
-
- } else if (isTypeEnum) { // enum
- JsonNode symbolsNode = schema.get("symbols");
- if (symbolsNode == null || !symbolsNode.isArray())
- throw new SchemaParseException("Enum has no symbols: " + schema);
- LockableArrayList<String> symbols = new
LockableArrayList<>(symbolsNode.size());
- for (JsonNode n : symbolsNode)
- symbols.add(n.textValue());
- JsonNode enumDefault = schema.get("default");
- String defaultSymbol = null;
- if (enumDefault != null)
- defaultSymbol = enumDefault.textValue();
- result = new EnumSchema(name, doc, symbols, defaultSymbol);
- names.add(result);
+ if (PRIMITIVES.containsKey(type)) { // primitive
+ return parsePrimitive(schema, type);
+ } else if ("record".equals(type) || isTypeError) { // record
+ return parseRecord(schema, context, currentNameSpace, isTypeError);
+ } else if ("enum".equals(type)) { // enum
+ return parseEnum(schema, context, currentNameSpace);
} else if (type.equals("array")) { // array
- JsonNode itemsNode = schema.get("items");
- if (itemsNode == null)
- throw new SchemaParseException("Array has no items type: " + schema);
- final Schema items = Schema.parseNamesDeclared(itemsNode, names,
currentNameSpace);
- result = Schema.createArray(items);
+ return parseArray(schema, context, currentNameSpace);
} else if (type.equals("map")) { // map
- JsonNode valuesNode = schema.get("values");
- if (valuesNode == null)
- throw new SchemaParseException("Map has no values type: " + schema);
- final Schema values = Schema.parseNamesDeclared(valuesNode, names,
currentNameSpace);
- result = Schema.createMap(values);
- } else if (isTypeFixed) { // fixed
- JsonNode sizeNode = schema.get("size");
- if (sizeNode == null || !sizeNode.isInt())
- throw new SchemaParseException("Invalid or no size: " + schema);
- result = new FixedSchema(name, doc, sizeNode.intValue());
- if (name != null)
- names.add(result);
- } else if (PRIMITIVES.containsKey(type)) {
- result = Schema.create(PRIMITIVES.get(type));
+ return parseMap(schema, context, currentNameSpace);
+ } else if ("fixed".equals(type)) { // fixed
+ return parseFixed(schema, context, currentNameSpace);
+ } else { // For unions with self reference
+ return context.find(type, currentNameSpace);
}
- if (result != null) {
- Set<String> reserved = SCHEMA_RESERVED;
- if (isTypeEnum) {
- reserved = ENUM_RESERVED;
- }
- Schema.addProperties(schema, reserved, result);
- }
- return result;
- } else if (schema.isArray()) {
- List<Schema> subs = new ArrayList<>(schema.size());
- schema.forEach((JsonNode item) -> {
- Schema sub = Schema.parseNamesDeclared(item, names, currentNameSpace);
- if (sub != null) {
- subs.add(sub);
- }
- });
- return Schema.createUnion(subs);
- } else if (schema.isTextual()) {
- String value = schema.asText();
- return names.get(value);
+ } else if (schema.isArray()) { // union
+ return parseUnion(schema, context, currentNameSpace);
+ } else {
+ throw new SchemaParseException("Schema not yet supported: " + schema);
}
- return null;
}
- private static void addProperties(JsonNode schema, Set<String> reserved,
Schema avroSchema) {
- Iterator<String> i = schema.fieldNames();
- while (i.hasNext()) { // add properties
- String prop = i.next();
- if (!reserved.contains(prop)) // ignore reserved
- avroSchema.addProp(prop, schema.get(prop));
- }
- // parse logical type if present
- avroSchema.logicalType = LogicalTypes.fromSchemaIgnoreInvalid(avroSchema);
- // names.space(savedSpace); // restore space
- if (avroSchema instanceof NamedSchema) {
- Set<String> aliases = parseAliases(schema);
- if (aliases != null) // add aliases
- for (String alias : aliases)
- avroSchema.addAlias(alias);
- }
+ private static Schema parsePrimitive(JsonNode schema, String type) {
+ Schema result = create(PRIMITIVES.get(type));
+ parseProperties(schema, result, SCHEMA_RESERVED);
+ return result;
}
- /**
- * Explore record fields in order to fill names map with inner defined named
- * types.
- *
- * @param fieldsNode : json node for field.
- * @param names : names map.
- * @param nameSpace : current working namespace.
- */
- private static void exploreFields(JsonNode fieldsNode, Names names, String
nameSpace) {
+ private static Schema parseRecord(JsonNode schema, ParseContext context,
String currentNameSpace,
+ boolean isTypeError) {
+ Name name = parseName(schema, currentNameSpace);
+ String doc = parseDoc(schema);
+ Schema result = new RecordSchema(name, doc, isTypeError);
+ context.put(result);
+
+ JsonNode fieldsNode = schema.get("fields");
+ if (fieldsNode == null || !fieldsNode.isArray())
+ throw new SchemaParseException("Record has no fields: " + schema);
+ List<Field> fields = new ArrayList<>();
for (JsonNode field : fieldsNode) {
- final JsonNode fieldType = field.get("type");
- if (fieldType != null) {
- if (fieldType.isObject()) {
- parseNamesDeclared(fieldType, names, nameSpace);
- } else if (fieldType.isArray()) {
- exploreFields(fieldType, names, nameSpace);
- } else if (fieldType.isTextual() && field.isObject()) {
- parseNamesDeclared(field, names, nameSpace);
- }
- }
+ Field f = parseField(field, context, name.space);
+ fields.add(f);
+ if (f.schema().getLogicalType() == null && getOptionalText(field,
LOGICAL_TYPE_PROP) != null)
+ LOG.warn(
+ "Ignored the {}.{}.logicalType property (\"{}\"). It should
probably be nested inside the \"type\" for the field.",
+ name, f.name(), getOptionalText(field, "logicalType"));
}
+ result.setFields(fields);
+ parseProperties(schema, result, SCHEMA_RESERVED);
+ parseAliases(schema, result);
+ return result;
}
- /**
- * in complement of parseNamesDeclared, this method parse schema in details.
- *
- * @param schema : json schema.
- * @param names : names map.
- * @param currentSpace : current working name space.
- * @return complete schema.
- */
- static Schema parseCompleteSchema(JsonNode schema, Names names, String
currentSpace) {
- if (schema == null) {
- throw new SchemaParseException("Cannot parse <null> schema");
- }
- if (schema.isTextual()) {
- String type = schema.asText();
- Schema avroSchema = names.get(type);
- if (avroSchema == null) {
- avroSchema = names.get(currentSpace + "." + type);
- }
- return avroSchema;
- }
- if (schema.isArray()) {
- List<Schema> schemas = StreamSupport.stream(schema.spliterator(), false)
- .map((JsonNode sub) -> parseCompleteSchema(sub, names,
currentSpace)).collect(Collectors.toList());
- return Schema.createUnion(schemas);
- }
- if (schema.isObject()) {
- Schema result = null;
- String type = getRequiredText(schema, "type", "No type");
- Name name = null;
+ private static Field parseField(JsonNode field, ParseContext context, String
namespace) {
+ String fieldName = getRequiredText(field, "name", "No field name");
+ String fieldDoc = parseDoc(field);
+ JsonNode fieldTypeNode = field.get("type");
+ if (fieldTypeNode == null)
+ throw new SchemaParseException("No field type: " + field);
+ Schema fieldSchema = parse(fieldTypeNode, context, namespace);
- final boolean isTypeError = "error".equals(type);
- final boolean isTypeRecord = "record".equals(type);
- final boolean isTypeArray = "array".equals(type);
+ Field.Order order = Field.Order.ASCENDING;
+ JsonNode orderNode = field.get("order");
+ if (orderNode != null)
+ order =
Field.Order.valueOf(orderNode.textValue().toUpperCase(Locale.ENGLISH));
- if (isTypeRecord || isTypeError || "enum".equals(type) ||
"fixed".equals(type)) {
- // named schema
- String space = getOptionalText(schema, "namespace");
+ JsonNode defaultValue = field.get("default");
+ if (defaultValue != null && (Type.FLOAT.equals(fieldSchema.getType()) ||
Type.DOUBLE.equals(fieldSchema.getType()))
+ && defaultValue.isTextual())
+ defaultValue = new
DoubleNode(Double.parseDouble(defaultValue.textValue()));
- if (space == null)
- space = currentSpace;
- name = new Name(getRequiredText(schema, "name", "No name in schema"),
space);
+ Field f = new Field(fieldName, fieldSchema, fieldDoc, defaultValue, true,
order);
+ parseProperties(field, f, FIELD_RESERVED);
+ f.aliases = parseAliases(field);
+ return f;
+ }
- result = names.get(name);
- if (result == null) {
- throw new SchemaParseException("Unparsed field type " + name);
- }
- }
- if (isTypeRecord || isTypeError) {
- if (result != null && !result.hasFields()) {
- final List<Field> fields = new ArrayList<>();
- JsonNode fieldsNode = schema.get("fields");
- if (fieldsNode == null || !fieldsNode.isArray())
- throw new SchemaParseException("Record has no fields: " + schema);
-
- for (JsonNode field : fieldsNode) {
- Field f = Field.parse(field, names, name.space);
-
- fields.add(f);
- if (f.schema.getLogicalType() == null && getOptionalText(field,
LOGICAL_TYPE_PROP) != null)
- LOG.warn(
- "Ignored the {}.{}.logicalType property (\"{}\"). It should
probably be nested inside the \"type\" for the field.",
- name, f.name, getOptionalText(field, "logicalType"));
- }
- result.setFields(fields);
- }
- } else if (isTypeArray) {
- JsonNode items = schema.get("items");
- Schema schemaItems = parseCompleteSchema(items, names, currentSpace);
- result = Schema.createArray(schemaItems);
- } else if ("map".equals(type)) {
- JsonNode values = schema.get("values");
- Schema mapItems = parseCompleteSchema(values, names, currentSpace);
- result = Schema.createMap(mapItems);
- } else if (result == null) {
- result = names.get(currentSpace + "." + type);
- if (result == null) {
- result = names.get(type);
- }
- }
+ private static Schema parseEnum(JsonNode schema, ParseContext context,
String currentNameSpace) {
+ Name name = parseName(schema, currentNameSpace);
+ String doc = parseDoc(schema);
- Set<String> reserved = SCHEMA_RESERVED;
- if ("enum".equals(type)) {
- reserved = ENUM_RESERVED;
- }
- Schema.addProperties(schema, reserved, result);
- return result;
+ JsonNode symbolsNode = schema.get("symbols");
+ if (symbolsNode == null || !symbolsNode.isArray()) {
+ throw new SchemaParseException("Enum has no symbols: " + schema);
}
- return null;
+ LockableArrayList<String> symbols = new
LockableArrayList<>(symbolsNode.size());
+ for (JsonNode n : symbolsNode)
+ symbols.add(n.textValue());
+ JsonNode enumDefault = schema.get("default");
+ String defaultSymbol = null;
+ if (enumDefault != null) {
+ defaultSymbol = enumDefault.textValue();
+ }
+
+ Schema result = new EnumSchema(name, doc, symbols, defaultSymbol);
+ context.put(result);
+ parseProperties(schema, result, ENUM_RESERVED);
+ parseAliases(schema, result);
+ return result;
}
- static Schema parse(JsonNode schema, Names names) {
- if (schema == null) {
- throw new SchemaParseException("Cannot parse <null> schema");
- }
+ private static Schema parseArray(JsonNode schema, ParseContext context,
String currentNameSpace) {
+ Schema result;
+ JsonNode itemsNode = schema.get("items");
+ if (itemsNode == null)
+ throw new SchemaParseException("Array has no items type: " + schema);
+ result = new ArraySchema(parse(itemsNode, context, currentNameSpace));
+ parseProperties(schema, result, SCHEMA_RESERVED);
+ return result;
+ }
+
+ private static Schema parseMap(JsonNode schema, ParseContext context, String
currentNameSpace) {
+ Schema result;
+ JsonNode valuesNode = schema.get("values");
+ if (valuesNode == null)
+ throw new SchemaParseException("Map has no values type: " + schema);
+ result = new MapSchema(parse(valuesNode, context, currentNameSpace));
+ parseProperties(schema, result, SCHEMA_RESERVED);
+ return result;
+ }
+
+ private static Schema parseFixed(JsonNode schema, ParseContext context,
String currentNameSpace) {
+ Name name = parseName(schema, currentNameSpace);
+ String doc = parseDoc(schema);
- Schema result = Schema.parseNamesDeclared(schema, names, names.space);
- Schema.parseCompleteSchema(schema, names, names.space);
+ JsonNode sizeNode = schema.get("size");
+ if (sizeNode == null || !sizeNode.isInt())
+ throw new SchemaParseException("Invalid or no size: " + schema);
+ Schema result = new FixedSchema(name, doc, sizeNode.intValue());
+ context.put(result);
+ parseProperties(schema, result, SCHEMA_RESERVED);
+ parseAliases(schema, result);
return result;
}
- static Schema resolveSchema(JsonNode schema, Names names, String
currentNameSpace) {
- String np = currentNameSpace;
- String nodeName = getOptionalText(schema, "name");
- if (nodeName != null) {
- final JsonNode nameSpace = schema.get("namespace");
- StringBuilder fullName = new StringBuilder();
- if (nameSpace != null && nameSpace.isTextual()) {
- fullName.append(nameSpace.asText()).append(".");
- np = nameSpace.asText();
- }
- fullName.append(nodeName);
- Schema schema1 = names.get(fullName.toString());
+ private static UnionSchema parseUnion(JsonNode schema, ParseContext context,
String currentNameSpace) {
+ LockableArrayList<Schema> types = new LockableArrayList<>(schema.size());
+ for (JsonNode typeNode : schema)
+ types.add(parse(typeNode, context, currentNameSpace));
+ return new UnionSchema(types);
+ }
- if (schema1 != null && schema1.getType() == Type.RECORD &&
!schema1.hasFields()) {
- Schema.parseCompleteSchema(schema, names, np);
- }
- return schema1;
- }
- return null;
+ private static void parseProperties(JsonNode jsonNode, Schema result,
Set<String> propertiesToSkip) {
+ parseProperties(jsonNode, (JsonProperties) result, propertiesToSkip);
+ // parse logical type if present
+ result.logicalType = LogicalTypes.fromSchemaIgnoreInvalid(result);
+ }
+
+ private static void parseProperties(JsonNode schema, JsonProperties result,
Set<String> propertiesToSkip) {
Review Comment:
## Confusing overloading of methods
Method Schema.parseProperties(..) could be confused with overloaded method
[parseProperties](1), since dispatch depends on static types.
[Show more
details](https://github.com/apache/avro/security/code-scanning/3175)
--
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]