Search in sources :

Example 1 with SqlToConnectTypeConverter

use of io.confluent.ksql.schema.ksql.SchemaConverters.SqlToConnectTypeConverter in project ksql by confluentinc.

the class ConnectSchemas method columnsToConnectSchema.

/**
 * Convert a list of columns into a Connect Struct schema with fields to match.
 *
 * @param columns the list of columns.
 * @return the Struct schema.
 */
public static ConnectSchema columnsToConnectSchema(final List<? extends SimpleColumn> columns) {
    final SqlToConnectTypeConverter converter = SchemaConverters.sqlToConnectConverter();
    final SchemaBuilder builder = SchemaBuilder.struct();
    for (final SimpleColumn column : columns) {
        final Schema colSchema = converter.toConnectSchema(column.type());
        builder.field(column.name().text(), colSchema);
    }
    return (ConnectSchema) builder.build();
}
Also used : ConnectSchema(org.apache.kafka.connect.data.ConnectSchema) Schema(org.apache.kafka.connect.data.Schema) SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder) ConnectSchema(org.apache.kafka.connect.data.ConnectSchema) SqlToConnectTypeConverter(io.confluent.ksql.schema.ksql.SchemaConverters.SqlToConnectTypeConverter) SimpleColumn(io.confluent.ksql.schema.ksql.SimpleColumn)

Aggregations

SqlToConnectTypeConverter (io.confluent.ksql.schema.ksql.SchemaConverters.SqlToConnectTypeConverter)1 SimpleColumn (io.confluent.ksql.schema.ksql.SimpleColumn)1 ConnectSchema (org.apache.kafka.connect.data.ConnectSchema)1 Schema (org.apache.kafka.connect.data.Schema)1 SchemaBuilder (org.apache.kafka.connect.data.SchemaBuilder)1