Skip to content
Merged
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 @@ -49,7 +49,7 @@ public AWSDmsAvroPayload(GenericRecord record, Comparable orderingVal) {
}

public AWSDmsAvroPayload(Option<GenericRecord> record) {
this(record.get(), 0); // natural order
this(record.isPresent() ? record.get() : null, 0); // natural order
}

/**
Expand Down Expand Up @@ -87,7 +87,10 @@ public Option<IndexedRecord> combineAndGetUpdateValue(IndexedRecord currentValue
@Override
public Option<IndexedRecord> combineAndGetUpdateValue(IndexedRecord currentValue, Schema schema)
throws IOException {
IndexedRecord insertValue = super.getInsertValue(schema).get();
return handleDeleteOperation(insertValue);
Option<IndexedRecord> insertValue = super.getInsertValue(schema);
if (!insertValue.isPresent()) {
return Option.empty();
}
return handleDeleteOperation(insertValue.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ public void testDelete() {

}

@Test
public void testDeleteWithEmptyPayLoad() {
Schema avroSchema = new Schema.Parser().parse(AVRO_SCHEMA_STRING);
Properties properties = new Properties();

GenericRecord oldRecord = new GenericData.Record(avroSchema);
oldRecord.put("field1", 2);
oldRecord.put("Op", "U");

AWSDmsAvroPayload payload = new AWSDmsAvroPayload(Option.empty());

try {
Option<IndexedRecord> outputPayload = payload.combineAndGetUpdateValue(oldRecord, avroSchema, properties);
// expect nothing to be committed to table
assertFalse(outputPayload.isPresent());
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception");
}
}

@Test
public void testPreCombineWithDelete() {
Schema avroSchema = new Schema.Parser().parse(AVRO_SCHEMA_STRING);
Expand Down