Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void configure(Map<String, ?> props) {

@Override
public R apply(R record) {
if (isTombstoneRecord(record)) {
if (operatingValue(record) == null) {
return record;
} else if (operatingSchema(record) == null) {
return applySchemaless(record);
Expand All @@ -136,10 +136,6 @@ public R apply(R record) {
}
}

private boolean isTombstoneRecord(R record) {
return record.value() == null;
}

private R applySchemaless(R record) {
final Map<String, Object> value = requireMap(operatingValue(record), PURPOSE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,50 @@ public void insertConfiguredFieldsIntoTombstoneEventWithSchemaLeavesValueUnchang
assertEquals(null, transformedRecord.value());
assertEquals(simpleStructSchema, transformedRecord.valueSchema());
}

@Test
public void insertConfiguredFieldsIntoNullKeyWithoutKeySchemaReturnsSameRecord() {
final Map<String, Object> props = new HashMap<>();
props.put("topic.field", "topic_field!");
props.put("partition.field", "partition_field");
props.put("timestamp.field", "timestamp_field?");
props.put("static.field", "instance_id");
props.put("static.value", "my-instance-id");

xform = new InsertField.Key<>();
xform.configure(props);

final Schema simpleStructSchema = SchemaBuilder.struct().name("name").version(1).doc("doc").field("magic", Schema.OPTIONAL_INT64_SCHEMA).build();
final Struct simpleStruct = new Struct(simpleStructSchema).put("magic", 42L);

final SourceRecord record = new SourceRecord(null, null, "test", 0,
null, null, simpleStructSchema, simpleStruct);

final SourceRecord transformedRecord = xform.apply(record);

assertSame(record, transformedRecord);
}

@Test
public void insertConfiguredFieldsIntoNullKeyWithKeySchemaReturnsSameRecord() {
final Map<String, Object> props = new HashMap<>();
props.put("topic.field", "topic_field!");
props.put("partition.field", "partition_field");
props.put("timestamp.field", "timestamp_field?");
props.put("static.field", "instance_id");
props.put("static.value", "my-instance-id");

xform = new InsertField.Key<>();
xform.configure(props);

final Schema simpleStructSchema = SchemaBuilder.struct().name("name").version(1).doc("doc").field("magic", Schema.OPTIONAL_INT64_SCHEMA).build();
final Struct simpleStruct = new Struct(simpleStructSchema).put("magic", 42L);

final SourceRecord record = new SourceRecord(null, null, "test", 0,
Schema.STRING_SCHEMA, null, simpleStructSchema, simpleStruct);

final SourceRecord transformedRecord = xform.apply(record);

assertSame(record, transformedRecord);
}
}