private void collectComplexTypes(Schema schema, Map<String, Schema> complexTypes) { switch (schema.getType()) { case RECORD: complexTypes.put(schema.getFullName(), schema); List<Schema.Field> fields = schema.getFields(); for (Schema.Field field : fields) { Schema fieldSchema = field.schema(); collectComplexTypes(fieldSchema, complexTypes); } break; case ARRAY: complexTypes.put(schema.getFullName(), schema); collectComplexTypes(schema.getElementType(), complexTypes); break; case UNION: complexTypes.put(schema.getFullName(), schema); List<Schema> unionSchemas = schema.getTypes(); for (Schema schemaEntry : unionSchemas) { collectComplexTypes(schemaEntry, complexTypes); } break; case MAP: complexTypes.put(schema.getFullName(), schema); collectComplexTypes(schema.getValueType(), complexTypes); break; default: } }
private void collectComplexTypes(Schema schema, Map<String, Schema> complexTypes) { switch (schema.getType()) { case RECORD: complexTypes.put(schema.getFullName(), schema); List<Schema.Field> fields = schema.getFields(); for (Schema.Field field : fields) { Schema fieldSchema = field.schema(); collectComplexTypes(fieldSchema, complexTypes); } break; case ARRAY: complexTypes.put(schema.getFullName(), schema); collectComplexTypes(schema.getElementType(), complexTypes); break; case UNION: complexTypes.put(schema.getFullName(), schema); List<Schema> unionSchemas = schema.getTypes(); for (Schema schemaEntry : unionSchemas) { collectComplexTypes(schemaEntry, complexTypes); } break; case MAP: complexTypes.put(schema.getFullName(), schema); collectComplexTypes(schema.getValueType(), complexTypes); break; default: } }
private Map<String, Schema> collectSchemaTypes(SchemaVersionKey schemaVersionKey, Map<String, SchemaParsingState> schemaParsingStates) throws SchemaNotFoundException, InvalidSchemaException { String schemaName = schemaVersionKey.getSchemaName(); SchemaParsingState schemaParsingState = schemaParsingStates.putIfAbsent(schemaName, SchemaParsingState.PARSING); // if it is already parsed then the respective schema types would have been already collected. if (SchemaParsingState.PARSED == schemaParsingState) { return null; } // if it is in parsing state earlier and it is visted again then ther eis circular dependency!! if (SchemaParsingState.PARSING == schemaParsingState) { throw new CyclicSchemaDependencyException("Cyclic dependency of schema imports with schema [" + schemaName + "]"); } // this schema is not yet parsed till now if (schemaParsingState == null) { Schema.Parser parser = new Schema.Parser(); Schema schema = parser.parse(getResultantSchema(schemaVersionKey, schemaParsingStates)); Map<String, Schema> complexTypes = new HashMap<>(); collectComplexTypes(schema, complexTypes); schemaParsingStates.put(schemaName, SchemaParsingState.PARSED); return complexTypes; } throw new IllegalStateException("Schema parsing with schema version " + schemaVersionKey + " is in invalid state!!"); }
private Map<String, Schema> collectSchemaTypes(SchemaVersionKey schemaVersionKey, Map<String, SchemaParsingState> schemaParsingStates) throws SchemaNotFoundException, InvalidSchemaException { String schemaName = schemaVersionKey.getSchemaName(); SchemaParsingState schemaParsingState = schemaParsingStates.putIfAbsent(schemaName, SchemaParsingState.PARSING); // if it is already parsed then the respective schema types would have been already collected. if (SchemaParsingState.PARSED == schemaParsingState) { return null; } // if it is in parsing state earlier and it is visted again then ther eis circular dependency!! if (SchemaParsingState.PARSING == schemaParsingState) { throw new CyclicSchemaDependencyException("Cyclic dependency of schema imports with schema [" + schemaName + "]"); } // this schema is not yet parsed till now if (schemaParsingState == null) { Schema.Parser parser = new Schema.Parser(); Schema schema = parser.parse(getResultantSchema(schemaVersionKey, schemaParsingStates)); Map<String, Schema> complexTypes = new HashMap<>(); collectComplexTypes(schema, complexTypes); schemaParsingStates.put(schemaName, SchemaParsingState.PARSED); return complexTypes; } throw new IllegalStateException("Schema parsing with schema version " + schemaVersionKey + " is in invalid state!!"); }