Search in sources :

Example 1 with ConnectToSqlTypeConverter

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();
}
Also used : Field(org.apache.kafka.connect.data.Field) ConnectToSqlTypeConverter(io.confluent.ksql.schema.ksql.SchemaConverters.ConnectToSqlTypeConverter) Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder)

Aggregations

Builder (io.confluent.ksql.schema.ksql.LogicalSchema.Builder)1 ConnectToSqlTypeConverter (io.confluent.ksql.schema.ksql.SchemaConverters.ConnectToSqlTypeConverter)1 Field (org.apache.kafka.connect.data.Field)1