public Map < CqlIdentifier , UserDefinedType > parse ( Collection < AdminRow > typeRows , CqlIdentifier keyspaceId ) { if ( typeRows . isEmpty ( ) ) { return Collections . emptyMap ( ) ; } else { Map < CqlIdentifier , UserDefinedType > types = new LinkedHashMap <> ( ) ; for ( AdminRow row : topologicalSort ( typeRows , keyspaceId ) ) { UserDefinedType type = parseType ( row , keyspaceId , types ) ; types . put ( type . getName ( ) , type ) ; } return ImmutableMap . copyOf ( types ) ; } }
Contrary to other element parsers this one processes all the types of a keyspace in one go . UDTs can depend on each other but the system table returns them in alphabetical order . In order to properly build the definitions we need to do a topological sort of the rows first so that each type is parsed after its dependencies .