ahmedabu98 commented on code in PR #24629:
URL: https://github.com/apache/beam/pull/24629#discussion_r1053614861
##########
sdks/java/io/debezium/src/main/java/org/apache/beam/io/debezium/KafkaConnectUtils.java:
##########
@@ -74,4 +77,45 @@ public static Schema.FieldType beamSchemaTypeFromKafkaType(
"Unable to convert Kafka field schema %s to Beam Schema",
kafkaFieldSchema));
}
}
+
+ public static SourceRecordMapper<Row> beamRowFromSourceRecordFn(final Schema
recordSchema) {
+ return new SourceRecordMapper<Row>() {
+ @Override
+ public Row mapSourceRecord(SourceRecord sourceRecord) throws Exception {
+ return beamRowFromKafkaStruct((Struct) sourceRecord.value(),
recordSchema);
+ }
+
+ private Row beamRowFromKafkaStruct(Struct kafkaStruct, Schema
beamSchema) {
+ Row.Builder rowBuilder = Row.withSchema(beamSchema);
+ for (Schema.Field f : beamSchema.getFields()) {
+ Object structField = kafkaStruct.getWithoutDefault(f.getName());
+ switch (kafkaStruct.schema().field(f.getName()).schema().type()) {
+ case ARRAY:
+ case MAP:
+ // TODO(pabloem): Handle nested structs
+ throw new IllegalArgumentException("UNABLE TO CONVERT FIELD " +
f);
+ case STRUCT:
+ Schema fieldSchema = f.getType().getRowSchema();
+ if (fieldSchema == null) {
+ throw new IllegalArgumentException(
+ String.format("Improper schema for Beam record: %s has no
row schema to build a Row from.", f.getName());
Review Comment:
```suggestion
String.format("Improper schema for Beam record: %s has
no row schema to build a Row from.", f.getName()));
```
Looks like I missed a parenthesis here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]