Repository navigation
[fix][io] KCA sink: handle null values with KeyValue<Avro,Avro> schema - #19861
Conversation
(cherry picked from commit f3747a1978c539c3f5a5f408988b9cc9125471a9)
|
Looking at this a bit deeper: So the fix will hack this for the top level key value schema, but the issue may reappear if the schema is generated for something like and the nested value is null. We may need to remove "if (kafkaSchema.isOptional())" check in KafkaConnectData.defaultOrThrow() |
|
actually in Pulsar a KeyValue schema allows null for both the key and the value. @dlg99 in Pulsar it is not allowed to nest KeyValue schemas. KeyValue schema is a (bad) trick to provide a Schema to the key of the message. any usage of nested KeyValue schemas is not supported (we may issue a warning or throw an error in Pulsar 3.0) and it cannot work properly so this schema doesn't work |
that's fine, nest any other pulsar schema. The problem is in the loss of optional flag in nested schema in translation form kafka schema to pulsar (source -> topic -> transform -> sink chain) |
|
|
||
| public static Schema getOptionalKafkaConnectSchema(org.apache.pulsar.client.api.Schema pulsarSchema) { | ||
| Schema s = getKafkaConnectSchema(pulsarSchema); | ||
| return new OptionalForcingSchema(s); |
There was a problem hiding this comment.
the only place it is used is within cache's get() call:
return schemaCache.get(pulsarSchema.getSchemaInfo().getSchema(), () -> {
if (pulsarSchema.getSchemaInfo().getType() == SchemaType.KEY_VALUE) {
KeyValueSchema kvSchema = (KeyValueSchema) pulsarSchema;
return SchemaBuilder.map(getKafkaConnectSchema(kvSchema.getKeySchema()),
getOptionalKafkaConnectSchema(kvSchema.getValueSchema()))
.build();
}
apache#19861) Co-authored-by: Andrey Yegorov <[email protected]> (cherry picked from commit 03f8b80)
apache#19861) (#169) Co-authored-by: Andrey Yegorov <[email protected]> (cherry picked from commit 03f8b80) Co-authored-by: Nicolò Boschi <[email protected]>
#19861) Co-authored-by: Andrey Yegorov <[email protected]> (cherry picked from commit 03f8b80)
Motivation
When using a KCA based sink connector with a topic with schema KeyValue<Avro, Avro>, if a message has a null value, the connector throws:
Modifications
Handle null value conversion to the kafka value
Verifying this change
Documentation
docdoc-requireddoc-not-neededdoc-complete