rayokota commented on a change in pull request #805:
URL: https://github.com/apache/avro/pull/805#discussion_r816516049
##########
File path: lang/java/avro/src/main/java/org/apache/avro/SchemaNormalization.java
##########
@@ -160,14 +200,73 @@ private static Appendable build(Map<String, String> env,
Schema s, Appendable o)
else
firstTime = false;
o.append("{\"name\":\"").append(f.name()).append("\"");
- build(env, f.schema(), o.append(",\"type\":")).append("}");
+ build(env, f.schema(), o.append(",\"type\":"), ps, aps);
+ if (!ps)
+ setFieldProps(o, f, aps); // if standard canonical form then add
reserved properties
+ o.append("}");
}
o.append("]");
}
+ if (!ps) {
+ setComplexProps(o, s);
+ setSimpleProps(o, s.getObjectProps(), aps);
+ } // adding the reserved property if not parser canonical schema
return o.append("}");
}
}
+ private static Appendable writeLogicalType(Schema s, LogicalType lt,
Appendable o, LinkedHashSet<String> aps)
+ throws IOException {
+ o.append("{\"type\":\"").append(s.getType().getName()).append("\"");
+ // adding the logical property
+ setLogicalProps(o, lt);
+ // adding the reserved property
+ setSimpleProps(o, s.getObjectProps(), aps);
+ return o.append("}");
+ }
+
+ private static void setLogicalProps(Appendable o, LogicalType lt) throws
IOException {
+
o.append(",\"").append(LogicalType.LOGICAL_TYPE_PROP).append("\":\"").append(lt.getName()).append("\"");
+ if (lt.getName().equals("decimal")) {
+ LogicalTypes.Decimal dlt = (LogicalTypes.Decimal) lt;
+ o.append(",\"precision\":").append(Integer.toString(dlt.getPrecision()));
+ if (dlt.getScale() != 0)
+ o.append(",\"scale\":").append(Integer.toString(dlt.getScale()));
+ }
+ }
+
+ private static void setSimpleProps(Appendable o, Map<String, Object>
schemaProps, LinkedHashSet<String> aps)
+ throws IOException {
+ for (String propKey : aps) {
+ if (schemaProps.containsKey(propKey)) {
+ String propValue =
JacksonUtils.toJsonNode(schemaProps.get(propKey)).toString();
+ o.append(",\"").append(propKey).append("\":").append(propValue);
+ }
+ }
+ }
+
+ private static void setComplexProps(Appendable o, Schema s) throws
IOException {
+ if (s.getDoc() != null && !s.getDoc().isEmpty())
+ o.append(",\"doc\":\"").append(s.getDoc()).append("\"");
+ if (s.getAliases() != null && !s.getAliases().isEmpty())
+ o.append(",\"aliases\":").append(JacksonUtils.toJsonNode(new
TreeSet<String>(s.getAliases())).toString());
+ if (s.getType() == Schema.Type.ENUM && s.getEnumDefault() != null) {
+
o.append(",\"default\":").append(JacksonUtils.toJsonNode(s.getEnumDefault()).toString());
+ }
+ }
+
+ private static void setFieldProps(Appendable o, Schema.Field f,
LinkedHashSet<String> aps) throws IOException {
+ if (f.order() != null)
+ o.append(",\"order\":\"").append(f.order().toString()).append("\"");
+ if (f.doc() != null)
+ o.append(",\"doc\":\"").append(f.doc()).append("\"");
Review comment:
This should be
`o.append(",\"doc\":").append(toJsonNode(f.doc()).toString());`
##########
File path: lang/java/avro/src/main/java/org/apache/avro/SchemaNormalization.java
##########
@@ -160,14 +200,73 @@ private static Appendable build(Map<String, String> env,
Schema s, Appendable o)
else
firstTime = false;
o.append("{\"name\":\"").append(f.name()).append("\"");
- build(env, f.schema(), o.append(",\"type\":")).append("}");
+ build(env, f.schema(), o.append(",\"type\":"), ps, aps);
+ if (!ps)
+ setFieldProps(o, f, aps); // if standard canonical form then add
reserved properties
+ o.append("}");
}
o.append("]");
}
+ if (!ps) {
+ setComplexProps(o, s);
+ setSimpleProps(o, s.getObjectProps(), aps);
+ } // adding the reserved property if not parser canonical schema
return o.append("}");
}
}
+ private static Appendable writeLogicalType(Schema s, LogicalType lt,
Appendable o, LinkedHashSet<String> aps)
+ throws IOException {
+ o.append("{\"type\":\"").append(s.getType().getName()).append("\"");
+ // adding the logical property
+ setLogicalProps(o, lt);
+ // adding the reserved property
+ setSimpleProps(o, s.getObjectProps(), aps);
+ return o.append("}");
+ }
+
+ private static void setLogicalProps(Appendable o, LogicalType lt) throws
IOException {
+
o.append(",\"").append(LogicalType.LOGICAL_TYPE_PROP).append("\":\"").append(lt.getName()).append("\"");
+ if (lt.getName().equals("decimal")) {
+ LogicalTypes.Decimal dlt = (LogicalTypes.Decimal) lt;
+ o.append(",\"precision\":").append(Integer.toString(dlt.getPrecision()));
+ if (dlt.getScale() != 0)
+ o.append(",\"scale\":").append(Integer.toString(dlt.getScale()));
+ }
+ }
+
+ private static void setSimpleProps(Appendable o, Map<String, Object>
schemaProps, LinkedHashSet<String> aps)
+ throws IOException {
+ for (String propKey : aps) {
+ if (schemaProps.containsKey(propKey)) {
+ String propValue =
JacksonUtils.toJsonNode(schemaProps.get(propKey)).toString();
+ o.append(",\"").append(propKey).append("\":").append(propValue);
+ }
+ }
+ }
+
+ private static void setComplexProps(Appendable o, Schema s) throws
IOException {
+ if (s.getDoc() != null && !s.getDoc().isEmpty())
+ o.append(",\"doc\":\"").append(s.getDoc()).append("\"");
Review comment:
This should be
`o.append(",\"doc\":").append(toJsonNode(s.getDoc()).toString());`
--
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]