use of io.confluent.ksql.schema.ksql.types.SqlStruct.Builder in project ksql by confluentinc.
the class GenericsUtil method applyResolved.
/**
* Replaces all generics in a schema with concrete schemas defined in {@code resolved}
*
* @param schema the schema which may contain generics
* @param resolved the mapping from generics to resolved types
* @return a schema with the same structure as {@code schema} but with no generics
*
* @throws KsqlException if there is a generic in {@code schema} that is not present
* in {@code mapping}
*/
public static SqlType applyResolved(final ParamType schema, final Map<GenericType, SqlType> resolved) {
if (schema instanceof ArrayType) {
return SqlTypes.array(applyResolved(((ArrayType) schema).element(), resolved));
}
if (schema instanceof MapType) {
final MapType mapType = (MapType) schema;
final SqlType keyType = applyResolved(mapType.key(), resolved);
final SqlType valueType = applyResolved(mapType.value(), resolved);
return SqlTypes.map(keyType, valueType);
}
if (schema instanceof StructType) {
final Builder struct = SqlTypes.struct();
((StructType) schema).getSchema().forEach((fieldName, type) -> struct.field(fieldName, applyResolved(type, resolved)));
return struct.build();
}
if (schema instanceof GenericType) {
final SqlType instance = resolved.get(schema);
if (instance == null) {
throw new KsqlException("Could not find mapping for generic type: " + schema);
}
return instance;
}
return SchemaConverters.functionToSqlConverter().toSqlType(schema);
}
Aggregations