use of io.confluent.ksql.schema.ksql.types.SqlBaseType.MAP in project ksql by confluentinc.
the class CastEvaluator method castStructToStruct.
@SuppressWarnings("OptionalGetWithoutIsPresent")
private static String castStructToStruct(final String innerCode, final SqlType from, final SqlType to, final KsqlConfig config) {
final SqlStruct fromStruct = (SqlStruct) from;
final SqlStruct toStruct = (SqlStruct) to;
try {
final String mappers = fromStruct.fields().stream().filter(fromField -> toStruct.field(fromField.name()).isPresent()).map(fromField -> castFieldToField(fromField, toStruct.field(fromField.name()).get(), config)).collect(Collectors.joining(System.lineSeparator(), "ImmutableMap.builder()\n\t\t", "\n\t\t.build()"));
// Inefficient, but only way to pass type until SqlToJavaVisitor supports passing
// additional parameters to the generated code. Hopefully, JVM optimises this away.
final String schemaCode = "SchemaConverters.sqlToConnectConverter()" + ".toConnectSchema(" + SqlTypeCodeGen.generateCode(toStruct) + ")";
return "CastEvaluator.castStruct(" + innerCode + ", " + mappers + "," + schemaCode + ")";
} catch (final UnsupportedCastException e) {
throw new UnsupportedCastException(from, to, e);
}
}
Aggregations