use of io.confluent.ksql.schema.ksql.SchemaConverters.ConnectToSqlTypeConverter in project ksql by confluentinc.
the class RowGenerator method buildLogicalSchema.
private static LogicalSchema buildLogicalSchema(final Generator generator, final AvroData avroData, final String keyFieldName) {
final org.apache.kafka.connect.data.Schema connectSchema = avroData.toConnectSchema(generator.schema());
final Field keyField = connectSchema.field(keyFieldName);
if (keyField == null) {
throw new IllegalArgumentException("key field does not exist in schema: " + keyFieldName);
}
final Builder schemaBuilder = LogicalSchema.builder();
final ConnectToSqlTypeConverter converter = SchemaConverters.connectToSqlConverter();
schemaBuilder.keyColumn(KEY_COL_NAME, converter.toSqlType(keyField.schema()));
connectSchema.fields().forEach(f -> schemaBuilder.valueColumn(ColumnName.of(f.name()), converter.toSqlType(f.schema())));
return schemaBuilder.build();
}
Aggregations