Slackbot
11/03/2023, 7:54 AMAsaf Mesika
11/06/2023, 1:02 PMNeng
11/06/2023, 5:14 PMSomeFunction implements Function<GenericObject, Record<GenericObject>>
For some generic processing.Oneeb
11/07/2023, 10:58 AMpublic class CustomFunction implements Function<GenericRecord, GenericRecord> {
@Override
public GenericRecord process(GenericRecord input, Context context) {
System.out.println("Schema type: " + input.getSchemaType());
KeyValue<?, ?> kvInput = (KeyValue<?, ?>) input.getNativeObject();
GenericRecord value = (GenericRecord) kvInput.getValue();
System.out.println("kv Value: " + value);
System.out.println("GenericRecord Value: " + value.getFields());
String payloadOperation = (String) value.getField("op");
GenericRecord payload = value;
if (payloadOperation.equals("c") || payloadOperation.equals("r") || payloadOperation.equals("u")) {
payload = (GenericRecord) value.getField("after");
} else if (payloadOperation.equals("d")) {
payload = (GenericRecord) value.getField("before");
}
return payload;
}
}Oneeb
11/07/2023, 10:59 AMpayload as a Record<GenericObject>?Oneeb
11/08/2023, 11:05 AMAsaf Mesika
11/08/2023, 2:24 PMAlexander Preuß
11/08/2023, 5:54 PMNeng
11/08/2023, 6:35 PMpublic class XFunction implements Function<GenericObject, Record<GenericObject>> {
...
}
And then you can
Record<GenericObject> record = (Record<GenericObject>) context.getCurrentRecord();
Schema<T> schema = record.getSchema();
// conversion schema to outputSchema based on your need
FunctionRecordBuilder recordBuilder =
context.newOutputRecordBuilder(outputSchema).destinationTopic(targetTopic);