This reverts commit 433d7d2c98.
This commit is contained in:
committed by
GitHub
parent
539621bd33
commit
ab11ba43e1
@@ -36,8 +36,6 @@ import java.io.IOException;
|
||||
public class OverwriteWithLatestAvroPayload extends BaseAvroPayload
|
||||
implements HoodieRecordPayload<OverwriteWithLatestAvroPayload> {
|
||||
|
||||
private String deleteMarkerField = "_hoodie_is_deleted";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -49,12 +47,6 @@ public class OverwriteWithLatestAvroPayload extends BaseAvroPayload
|
||||
this(record.isPresent() ? record.get() : null, (record1) -> 0); // natural order
|
||||
}
|
||||
|
||||
public OverwriteWithLatestAvroPayload(GenericRecord record, Comparable orderingVal,
|
||||
String deleteMarkerField) {
|
||||
this(record, orderingVal);
|
||||
this.deleteMarkerField = deleteMarkerField;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OverwriteWithLatestAvroPayload preCombine(OverwriteWithLatestAvroPayload another) {
|
||||
// pick the payload with greatest ordering value
|
||||
@@ -88,7 +80,7 @@ public class OverwriteWithLatestAvroPayload extends BaseAvroPayload
|
||||
* @returns {@code true} if record represents a delete record. {@code false} otherwise.
|
||||
*/
|
||||
private boolean isDeleteRecord(GenericRecord genericRecord) {
|
||||
Object deleteMarker = genericRecord.get(deleteMarkerField);
|
||||
Object deleteMarker = genericRecord.get("_hoodie_is_deleted");
|
||||
return (deleteMarker instanceof Boolean && (boolean) deleteMarker);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
public class TestOverwriteWithLatestAvroPayload {
|
||||
|
||||
private Schema schema;
|
||||
String defaultDeleteMarkerField = "_hoodie_is_deleted";
|
||||
String deleteMarkerField = "delete_marker_field";
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
@@ -46,56 +44,26 @@ public class TestOverwriteWithLatestAvroPayload {
|
||||
new Schema.Field("id", Schema.create(Schema.Type.STRING), "", null),
|
||||
new Schema.Field("partition", Schema.create(Schema.Type.STRING), "", null),
|
||||
new Schema.Field("ts", Schema.create(Schema.Type.LONG), "", null),
|
||||
new Schema.Field(defaultDeleteMarkerField, Schema.create(Type.BOOLEAN), "", false),
|
||||
new Schema.Field(deleteMarkerField, Schema.create(Type.BOOLEAN), "", false)
|
||||
new Schema.Field("_hoodie_is_deleted", Schema.create(Type.BOOLEAN), "", false)
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverwriteWithLatestAvroPayload() throws IOException {
|
||||
public void testActiveRecords() throws IOException {
|
||||
GenericRecord record1 = new GenericData.Record(schema);
|
||||
record1.put("id", "1");
|
||||
record1.put("partition", "partition0");
|
||||
record1.put("ts", 0L);
|
||||
record1.put(defaultDeleteMarkerField, false);
|
||||
record1.put(deleteMarkerField, false);
|
||||
record1.put("_hoodie_is_deleted", false);
|
||||
|
||||
// test1: set default marker field value to true and user defined to false
|
||||
GenericRecord record2 = new GenericData.Record(schema);
|
||||
record2.put("id", "2");
|
||||
record2.put("partition", "partition1");
|
||||
record2.put("ts", 1L);
|
||||
record2.put(defaultDeleteMarkerField, true);
|
||||
record2.put(deleteMarkerField, false);
|
||||
|
||||
// set to user defined marker field with false, the record should be considered active.
|
||||
assertActiveRecord(record1, record2, deleteMarkerField);
|
||||
|
||||
// set to default marker field with true, the record should be considered delete.
|
||||
assertDeletedRecord(record1, record2, defaultDeleteMarkerField);
|
||||
|
||||
// test2: set default marker field value to false and user defined to true
|
||||
GenericRecord record3 = new GenericData.Record(schema);
|
||||
record3.put("id", "2");
|
||||
record3.put("partition", "partition1");
|
||||
record3.put("ts", 1L);
|
||||
record3.put(defaultDeleteMarkerField, false);
|
||||
record3.put(deleteMarkerField, true);
|
||||
|
||||
// set to user defined marker field with true, the record should be considered delete.
|
||||
assertDeletedRecord(record1, record3, deleteMarkerField);
|
||||
|
||||
// set to default marker field with false, the record should be considered active.
|
||||
assertActiveRecord(record1, record3, defaultDeleteMarkerField);
|
||||
}
|
||||
|
||||
private void assertActiveRecord(GenericRecord record1,
|
||||
GenericRecord record2, String field) throws IOException {
|
||||
OverwriteWithLatestAvroPayload payload1 = new OverwriteWithLatestAvroPayload(
|
||||
record1, 1, field);
|
||||
OverwriteWithLatestAvroPayload payload2 = new OverwriteWithLatestAvroPayload(
|
||||
record2, 2, field);
|
||||
record2.put("_hoodie_is_deleted", false);
|
||||
|
||||
OverwriteWithLatestAvroPayload payload1 = new OverwriteWithLatestAvroPayload(record1, 1);
|
||||
OverwriteWithLatestAvroPayload payload2 = new OverwriteWithLatestAvroPayload(record2, 2);
|
||||
assertEquals(payload1.preCombine(payload2), payload2);
|
||||
assertEquals(payload2.preCombine(payload1), payload2);
|
||||
|
||||
@@ -106,12 +74,22 @@ public class TestOverwriteWithLatestAvroPayload {
|
||||
assertEquals(payload2.combineAndGetUpdateValue(record1, schema).get(), record2);
|
||||
}
|
||||
|
||||
private void assertDeletedRecord(GenericRecord record1,
|
||||
GenericRecord delRecord1, String field) throws IOException {
|
||||
OverwriteWithLatestAvroPayload payload1 = new OverwriteWithLatestAvroPayload(
|
||||
record1, 1, field);
|
||||
OverwriteWithLatestAvroPayload payload2 = new OverwriteWithLatestAvroPayload(
|
||||
delRecord1, 2, field);
|
||||
@Test
|
||||
public void testDeletedRecord() throws IOException {
|
||||
GenericRecord record1 = new GenericData.Record(schema);
|
||||
record1.put("id", "1");
|
||||
record1.put("partition", "partition0");
|
||||
record1.put("ts", 0L);
|
||||
record1.put("_hoodie_is_deleted", false);
|
||||
|
||||
GenericRecord delRecord1 = new GenericData.Record(schema);
|
||||
delRecord1.put("id", "2");
|
||||
delRecord1.put("partition", "partition1");
|
||||
delRecord1.put("ts", 1L);
|
||||
delRecord1.put("_hoodie_is_deleted", true);
|
||||
|
||||
OverwriteWithLatestAvroPayload payload1 = new OverwriteWithLatestAvroPayload(record1, 1);
|
||||
OverwriteWithLatestAvroPayload payload2 = new OverwriteWithLatestAvroPayload(delRecord1, 2);
|
||||
assertEquals(payload1.preCombine(payload2), payload2);
|
||||
assertEquals(payload2.preCombine(payload1), payload2);
|
||||
|
||||
@@ -121,4 +99,5 @@ public class TestOverwriteWithLatestAvroPayload {
|
||||
assertEquals(payload1.combineAndGetUpdateValue(delRecord1, schema).get(), record1);
|
||||
assertFalse(payload2.combineAndGetUpdateValue(record1, schema).isPresent());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -106,7 +106,6 @@ public class HoodieTestDataGenerator {
|
||||
+ "{\"name\": \"seconds_since_epoch\", \"type\": \"long\"},"
|
||||
+ "{\"name\": \"weight\", \"type\": \"float\"},"
|
||||
+ "{\"name\": \"nation\", \"type\": \"bytes\"},"
|
||||
+ "{\"name\": \"user_defined_delete_marker_field\", \"type\": \"boolean\", \"default\": false},"
|
||||
+ "{\"name\":\"current_date\",\"type\": {\"type\": \"int\", \"logicalType\": \"date\"}},"
|
||||
+ "{\"name\":\"current_ts\",\"type\": {\"type\": \"long\"}},"
|
||||
+ "{\"name\":\"height\",\"type\":{\"type\":\"fixed\",\"name\":\"abc\",\"size\":5,\"logicalType\":\"decimal\",\"precision\":10,\"scale\":6}},";
|
||||
@@ -124,7 +123,7 @@ public class HoodieTestDataGenerator {
|
||||
+ "{\"name\":\"driver\",\"type\":\"string\"},{\"name\":\"fare\",\"type\":\"double\"},{\"name\": \"_hoodie_is_deleted\", \"type\": \"boolean\", \"default\": false}]}";
|
||||
|
||||
public static final String NULL_SCHEMA = Schema.create(Schema.Type.NULL).toString();
|
||||
public static final String TRIP_HIVE_COLUMN_TYPES = "double,string,string,string,double,double,double,double,int,bigint,float,binary,boolean,int,bigint,decimal(10,6),"
|
||||
public static final String TRIP_HIVE_COLUMN_TYPES = "double,string,string,string,double,double,double,double,int,bigint,float,binary,int,bigint,decimal(10,6),"
|
||||
+ "map<string,string>,struct<amount:double,currency:string>,array<struct<amount:double,currency:string>>,boolean";
|
||||
|
||||
|
||||
@@ -180,18 +179,6 @@ public class HoodieTestDataGenerator {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<GenericRecord> generateGenericRecords(int n, boolean isDeleteRecord, int instantTime) {
|
||||
return IntStream.range(0, n).boxed().map(i -> {
|
||||
String partitionPath = DEFAULT_FIRST_PARTITION_PATH;
|
||||
HoodieKey key = new HoodieKey("id_" + i, partitionPath);
|
||||
HoodieTestDataGenerator.KeyPartition kp = new HoodieTestDataGenerator.KeyPartition();
|
||||
kp.key = key;
|
||||
kp.partitionPath = partitionPath;
|
||||
return HoodieTestDataGenerator.generateGenericRecord(
|
||||
key.getRecordKey(), "rider-" + instantTime, "driver-" + instantTime, instantTime, isDeleteRecord, false);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new avro record of the above nested schema format,
|
||||
* retaining the key if optionally provided.
|
||||
@@ -278,11 +265,11 @@ public class HoodieTestDataGenerator {
|
||||
rec.put("weight", RAND.nextFloat());
|
||||
byte[] bytes = "Canada".getBytes();
|
||||
rec.put("nation", ByteBuffer.wrap(bytes));
|
||||
rec.put("user_defined_delete_marker_field", isDeleteRecord);
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
Date date = new Date(currentTimeMillis);
|
||||
rec.put("current_date", (int) date.toLocalDate().toEpochDay());
|
||||
rec.put("current_ts", currentTimeMillis);
|
||||
|
||||
BigDecimal bigDecimal = new BigDecimal(String.format("%5f", RAND.nextFloat()));
|
||||
Schema decimalSchema = AVRO_SCHEMA.getField("height").schema();
|
||||
Conversions.DecimalConversion decimalConversions = new Conversions.DecimalConversion();
|
||||
@@ -305,7 +292,11 @@ public class HoodieTestDataGenerator {
|
||||
rec.put("tip_history", tipHistoryArray);
|
||||
}
|
||||
|
||||
rec.put("_hoodie_is_deleted", isDeleteRecord);
|
||||
if (isDeleteRecord) {
|
||||
rec.put("_hoodie_is_deleted", true);
|
||||
} else {
|
||||
rec.put("_hoodie_is_deleted", false);
|
||||
}
|
||||
return rec;
|
||||
}
|
||||
|
||||
@@ -769,8 +760,8 @@ public class HoodieTestDataGenerator {
|
||||
|
||||
public static class KeyPartition implements Serializable {
|
||||
|
||||
public HoodieKey key;
|
||||
public String partitionPath;
|
||||
HoodieKey key;
|
||||
String partitionPath;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
||||
Reference in New Issue
Block a user