Skip to content

Commit 647d881

Browse files
rahil-cRahil Chertara
authored andcommitted
[HUDI-4831] Fix AWSDmsAvroPayload#getInsertValue,combineAndGetUpdateValue to invoke correct api (apache#6637)
Co-authored-by: Rahil Chertara <[email protected]> (cherry picked from commit 8dea9cf)
1 parent c0c1b6c commit 647d881

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

hudi-common/src/main/java/org/apache/hudi/common/model/AWSDmsAvroPayload.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ private Option<IndexedRecord> handleDeleteOperation(IndexedRecord insertValue) t
6969

7070
@Override
7171
public Option<IndexedRecord> getInsertValue(Schema schema, Properties properties) throws IOException {
72-
IndexedRecord insertValue = super.getInsertValue(schema, properties).get();
73-
return handleDeleteOperation(insertValue);
72+
return getInsertValue(schema);
7473
}
7574

7675
@Override
@@ -82,8 +81,7 @@ public Option<IndexedRecord> getInsertValue(Schema schema) throws IOException {
8281
@Override
8382
public Option<IndexedRecord> combineAndGetUpdateValue(IndexedRecord currentValue, Schema schema, Properties properties)
8483
throws IOException {
85-
IndexedRecord insertValue = super.getInsertValue(schema, properties).get();
86-
return handleDeleteOperation(insertValue);
84+
return combineAndGetUpdateValue(currentValue, schema);
8785
}
8886

8987
@Override

hudi-common/src/test/java/org/apache/hudi/common/model/TestAWSDmsAvroPayload.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.apache.hudi.common.util.Option;
2626
import org.junit.jupiter.api.Test;
2727

28+
import java.util.Properties;
29+
2830
import static org.junit.jupiter.api.Assertions.assertFalse;
2931
import static org.junit.jupiter.api.Assertions.assertTrue;
3032
import static org.junit.jupiter.api.Assertions.fail;
@@ -42,13 +44,14 @@ public void testInsert() {
4244

4345
Schema avroSchema = new Schema.Parser().parse(AVRO_SCHEMA_STRING);
4446
GenericRecord record = new GenericData.Record(avroSchema);
47+
Properties properties = new Properties();
4548
record.put("field1", 0);
4649
record.put("Op", "I");
4750

4851
AWSDmsAvroPayload payload = new AWSDmsAvroPayload(Option.of(record));
4952

5053
try {
51-
Option<IndexedRecord> outputPayload = payload.getInsertValue(avroSchema);
54+
Option<IndexedRecord> outputPayload = payload.getInsertValue(avroSchema, properties);
5255
assertTrue((int) outputPayload.get().get(0) == 0);
5356
assertTrue(outputPayload.get().get(1).toString().equals("I"));
5457
} catch (Exception e) {
@@ -61,6 +64,7 @@ public void testInsert() {
6164
public void testUpdate() {
6265
Schema avroSchema = new Schema.Parser().parse(AVRO_SCHEMA_STRING);
6366
GenericRecord newRecord = new GenericData.Record(avroSchema);
67+
Properties properties = new Properties();
6468
newRecord.put("field1", 1);
6569
newRecord.put("Op", "U");
6670

@@ -71,7 +75,7 @@ public void testUpdate() {
7175
AWSDmsAvroPayload payload = new AWSDmsAvroPayload(Option.of(newRecord));
7276

7377
try {
74-
Option<IndexedRecord> outputPayload = payload.combineAndGetUpdateValue(oldRecord, avroSchema);
78+
Option<IndexedRecord> outputPayload = payload.combineAndGetUpdateValue(oldRecord, avroSchema, properties);
7579
assertTrue((int) outputPayload.get().get(0) == 1);
7680
assertTrue(outputPayload.get().get(1).toString().equals("U"));
7781
} catch (Exception e) {
@@ -84,6 +88,7 @@ public void testUpdate() {
8488
public void testDelete() {
8589
Schema avroSchema = new Schema.Parser().parse(AVRO_SCHEMA_STRING);
8690
GenericRecord deleteRecord = new GenericData.Record(avroSchema);
91+
Properties properties = new Properties();
8792
deleteRecord.put("field1", 2);
8893
deleteRecord.put("Op", "D");
8994

@@ -94,7 +99,7 @@ public void testDelete() {
9499
AWSDmsAvroPayload payload = new AWSDmsAvroPayload(Option.of(deleteRecord));
95100

96101
try {
97-
Option<IndexedRecord> outputPayload = payload.combineAndGetUpdateValue(oldRecord, avroSchema);
102+
Option<IndexedRecord> outputPayload = payload.combineAndGetUpdateValue(oldRecord, avroSchema, properties);
98103
// expect nothing to be committed to table
99104
assertFalse(outputPayload.isPresent());
100105
} catch (Exception e) {
@@ -107,6 +112,7 @@ public void testDelete() {
107112
public void testPreCombineWithDelete() {
108113
Schema avroSchema = new Schema.Parser().parse(AVRO_SCHEMA_STRING);
109114
GenericRecord deleteRecord = new GenericData.Record(avroSchema);
115+
Properties properties = new Properties();
110116
deleteRecord.put("field1", 4);
111117
deleteRecord.put("Op", "D");
112118

@@ -119,7 +125,7 @@ public void testPreCombineWithDelete() {
119125

120126
try {
121127
OverwriteWithLatestAvroPayload output = payload.preCombine(insertPayload);
122-
Option<IndexedRecord> outputPayload = output.getInsertValue(avroSchema);
128+
Option<IndexedRecord> outputPayload = output.getInsertValue(avroSchema, properties);
123129
// expect nothing to be committed to table
124130
assertFalse(outputPayload.isPresent());
125131
} catch (Exception e) {

0 commit comments

Comments
 (0)