autumnust commented on a change in pull request #2806: GOBBLIN-957: Add
recursion eliminating converter for Avro
URL: https://github.com/apache/incubator-gobblin/pull/2806#discussion_r346451738
##########
File path: gobblin-utility/src/main/java/org/apache/gobblin/util/AvroUtils.java
##########
@@ -935,4 +941,141 @@ public static Schema overrideNameAndNamespace(Schema
input, String nameOverride,
return newSchema;
}
+ @Builder
+ @ToString
+ public static class SchemaEntry {
+ @Getter
+ final String fieldName;
+ final Schema schema;
+ String fullyQualifiedType() {
+ return schema.getFullName();
+ }
+ }
+
+ /**
+ * Drop recursive fields from a Schema. Recursive fields are fields that
refer to types that are part of the
+ * parent tree.
+ * e.g. consider this Schema for a User
+ * {
+ * "type": "record",
+ * "name": "User",
+ * "fields": [
+ * {"name": "name", "type": "string",
+ * {"name": "friend", "type": "User"}
+ * ]
+ * }
+ * the friend field is a recursive field. After recursion has been
eliminated we expect the output Schema to look like
+ * {
+ * "type": "record",
+ * "name": "User",
+ * "fields": [
+ * {"name": "name", "type": "string"}
+ * ]
+ * }
+ *
+ * @param schema
+ * @return a Pair of (The transformed schema with recursion eliminated, A
list of @link{SchemaEntry} objects which
+ * represent the fields that were removed from the original schema)
+ */
+ public static Pair<Schema, List<SchemaEntry>> dropRecursiveFields(Schema
schema) {
Review comment:
Can we add one more utility method like `containsRecurisveSchema(Schema
schema)` as a easy-to-check tool ?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services