Search in sources :

Example 1 with ConnectSchema

use of org.apache.kafka.connect.data.ConnectSchema in project apache-kafka-on-k8s by banzaicloud.

the class SetSchemaMetadata method apply.

@Override
public R apply(R record) {
    final Schema schema = operatingSchema(record);
    requireSchema(schema, "updating schema metadata");
    final boolean isArray = schema.type() == Schema.Type.ARRAY;
    final boolean isMap = schema.type() == Schema.Type.MAP;
    final Schema updatedSchema = new ConnectSchema(schema.type(), schema.isOptional(), schema.defaultValue(), schemaName != null ? schemaName : schema.name(), schemaVersion != null ? schemaVersion : schema.version(), schema.doc(), schema.parameters(), schema.fields(), isMap ? schema.keySchema() : null, isMap || isArray ? schema.valueSchema() : null);
    return newRecord(record, updatedSchema);
}
Also used : Requirements.requireSchema(org.apache.kafka.connect.transforms.util.Requirements.requireSchema) ConnectSchema(org.apache.kafka.connect.data.ConnectSchema) Schema(org.apache.kafka.connect.data.Schema) ConnectSchema(org.apache.kafka.connect.data.ConnectSchema)

Example 2 with ConnectSchema

use of org.apache.kafka.connect.data.ConnectSchema in project kafka by apache.

the class SetSchemaMetadata method apply.

@Override
public R apply(R record) {
    final Schema schema = operatingSchema(record);
    requireSchema(schema, "updating schema metadata");
    final boolean isArray = schema.type() == Schema.Type.ARRAY;
    final boolean isMap = schema.type() == Schema.Type.MAP;
    final Schema updatedSchema = new ConnectSchema(schema.type(), schema.isOptional(), schema.defaultValue(), schemaName != null ? schemaName : schema.name(), schemaVersion != null ? schemaVersion : schema.version(), schema.doc(), schema.parameters(), schema.fields(), isMap ? schema.keySchema() : null, isMap || isArray ? schema.valueSchema() : null);
    log.trace("Applying SetSchemaMetadata SMT. Original schema: {}, updated schema: {}", schema, updatedSchema);
    return newRecord(record, updatedSchema);
}
Also used : Requirements.requireSchema(org.apache.kafka.connect.transforms.util.Requirements.requireSchema) ConnectSchema(org.apache.kafka.connect.data.ConnectSchema) Schema(org.apache.kafka.connect.data.Schema) ConnectSchema(org.apache.kafka.connect.data.ConnectSchema)

Aggregations

ConnectSchema (org.apache.kafka.connect.data.ConnectSchema)2 Schema (org.apache.kafka.connect.data.Schema)2 Requirements.requireSchema (org.apache.kafka.connect.transforms.util.Requirements.requireSchema)2