private Schema resolveSchema ( final Schema schema , final Map < String , Schema > knownRecordSchemas ) { switch ( schema . getType ( ) ) { case ARRAY : Schema componentSchema = resolveSchema ( schema . getComponentSchema ( ) , knownRecordSchemas ) ; return ( componentSchema == schema . getComponentSchema ( ) ) ? schema : Schema . arrayOf ( componentSchema ) ; case MAP : Map . Entry < Schema , Schema > entry = schema . getMapSchema ( ) ; Schema keySchema = resolveSchema ( entry . getKey ( ) , knownRecordSchemas ) ; Schema valueSchema = resolveSchema ( entry . getValue ( ) , knownRecordSchemas ) ; return ( keySchema == entry . getKey ( ) && valueSchema == entry . getValue ( ) ) ? schema : Schema . mapOf ( keySchema , valueSchema ) ; case UNION : ImmutableList . Builder < Schema > schemaBuilder = ImmutableList . builder ( ) ; boolean changed = false ; for ( Schema input : schema . getUnionSchemas ( ) ) { Schema output = resolveSchema ( input , knownRecordSchemas ) ; if ( output != input ) { changed = true ; } schemaBuilder . add ( output ) ; } return changed ? Schema . unionOf ( schemaBuilder . build ( ) ) : schema ; case RECORD : if ( schema . fields == null ) { // It is a named record that refers to previously defined record Schema knownSchema = knownRecordSchemas . get ( schema . recordName ) ; Preconditions . checkArgument ( knownSchema != null , "Undefined schema %s" , schema . recordName ) ; return knownSchema ; } else { // It is a concrete schema knownRecordSchemas . put ( schema . recordName , schema ) ; return schema ; } } return schema ; }
This method is to recursively resolves all name only record schema in the given schema .