alexrosenfeld10 commented on code in PR #2292:
URL: https://github.com/apache/avro/pull/2292#discussion_r1232365808
##########
lang/csharp/src/apache/main/Schema/Schema.cs:
##########
@@ -231,6 +233,70 @@ public static Schema Parse(string json)
return Parse(json.Trim(), new SchemaNames(), null); // standalone
schema, so no enclosing namespace
}
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="schemaJsons"></param>
+ /// <returns></returns>
+ /// <exception cref="SchemaParseException"></exception>
+ public static IDictionary<string, Schema> ParseAll(IEnumerable<string>
schemaJsons)
+ {
+ var schemaNames = new SchemaNames();
+
+ var remainingSchemasToParse = schemaJsons.ToList();
+ int retriesRemaining = 20;
+ var parsedSchemasByName = new Dictionary<string, Schema>();
+ while (remainingSchemasToParse.Any() && retriesRemaining > 0)
+ {
+ var failedSchemaJsons = new List<string>();
+ foreach (string schemaJson in remainingSchemasToParse)
+ {
+ var successfulSchemaNames = schemaNames.Names
+ .ToDictionary(
+ kvp => kvp.Key,
+ kvp => kvp.Value);
+ try
+ {
+ var schema = Parse(schemaJson, schemaNames);
+ parsedSchemasByName[schema.Name] = schema;
+ }
+ catch (SchemaParseException e)
+ {
+ Console.WriteLine(
+ $"Failed to parse schema with exception
{e.Message}, its dependencies may not have been parsed yet and will be
retried.");
+ foreach (var failedSchemaName in
schemaNames.Names.Except(successfulSchemaNames))
+ {
+ schemaNames.Names.Remove(failedSchemaName);
Review Comment:
this is obviously a bit ugly. Better ideas welcome. I don't love that the
`Parse` method persists the schema in to the `schemaNames.Names` dictionary,
even if it didn't succeed. Feels side effect heavy / leaky to me. I don't know
if there are good reasons for it though, so I just bluntly worked around it
here,
--
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]