yihua commented on code in PR #12843:
URL: https://github.com/apache/hudi/pull/12843#discussion_r1999306636
##########
hudi-common/src/test/java/org/apache/hudi/common/table/read/TestHoodieFileGroupRecordBuffer.java:
##########
@@ -53,4 +101,89 @@ private void mockDeleteRecord(DeleteRecord deleteRecord,
Comparable orderingValue) {
when(deleteRecord.getOrderingValue()).thenReturn(orderingValue);
}
+
+ @Test
+ void testHasCustomDeleteConfigs() {
+ KeyBasedFileGroupRecordBuffer keyBasedBuffer =
+ new KeyBasedFileGroupRecordBuffer(
+ readerContext,
+ hoodieTableMetaClient,
+ RecordMergeMode.COMMIT_TIME_ORDERING,
+ partitionNameOverrideOpt,
+ partitionPathFieldOpt,
+ props,
+ readStats);
+
+ assertFalse(keyBasedBuffer.hasCustomDeleteConfigs(props, schema));
+ props.setProperty(DELETE_KEY, "op");
+ assertFalse(keyBasedBuffer.hasCustomDeleteConfigs(props, schema));
+ props.setProperty(DELETE_MARKER, "d");
+ assertThrows(
+ NullPointerException.class,
+ () -> keyBasedBuffer.hasCustomDeleteConfigs(props, null));
+ assertTrue(keyBasedBuffer.hasCustomDeleteConfigs(props, schema));
+ }
+
+ @Test
+ void testIsCustomDeleteRecord() {
+ GenericRecord record = new GenericData.Record(schema);
+ record.put("id", "12345");
+ record.put("ts", System.currentTimeMillis());
+ record.put("op", "d");
+
+ KeyBasedFileGroupRecordBuffer keyBasedBuffer =
+ new KeyBasedFileGroupRecordBuffer(
+ readerContext,
+ hoodieTableMetaClient,
+ RecordMergeMode.COMMIT_TIME_ORDERING,
+ partitionNameOverrideOpt,
+ partitionPathFieldOpt,
+ props,
+ readStats);
+ when(readerContext.getValue(any(), any(), any())).thenReturn(null);
+ assertFalse(keyBasedBuffer.isCustomDeleteRecord(record));
+
+ props.setProperty(DELETE_KEY, "op");
+ props.setProperty(DELETE_MARKER, "d");
+ keyBasedBuffer = new KeyBasedFileGroupRecordBuffer(
+ readerContext,
+ hoodieTableMetaClient,
+ RecordMergeMode.COMMIT_TIME_ORDERING,
+ partitionNameOverrideOpt,
+ partitionPathFieldOpt,
+ props,
+ readStats);
+ when(readerContext.getValue(any(), any(), any())).thenReturn("i");
+ assertFalse(keyBasedBuffer.isCustomDeleteRecord(record));
+ when(readerContext.getValue(any(), any(), any())).thenReturn("d");
+ assertTrue(keyBasedBuffer.isCustomDeleteRecord(record));
+ }
+
+ @Test
+ void testProcessCustomDeleteRecord() {
+ GenericRecord record = new GenericData.Record(schema);
+ record.put("id", "12345");
+ record.put("ts", System.currentTimeMillis());
+ record.put("op", "d");
+
+ KeyBasedFileGroupRecordBuffer keyBasedBuffer =
+ new KeyBasedFileGroupRecordBuffer(
+ readerContext,
+ hoodieTableMetaClient,
+ RecordMergeMode.COMMIT_TIME_ORDERING,
+ partitionNameOverrideOpt,
+ partitionPathFieldOpt,
+ props,
+ readStats);
+
+ Map<String, Object> metadata = new HashMap<>();
+ metadata.put(INTERNAL_META_RECORD_KEY, "12345");
+ metadata.put(INTERNAL_META_PARTITION_PATH, "partition1");
+ when(readerContext.getOrderingValue(any(), any(), any(),
any())).thenReturn(1);
+ keyBasedBuffer.processCustomDeleteRecord(record, metadata);
+ Map<Serializable, Pair<Option<GenericRecord>, Map<String, Object>>>
records =
+ keyBasedBuffer.getLogRecords();
+ assertEquals(1, records.size());
+ assertTrue(records.containsKey("12345"));
Review Comment:
Could you assert the whole delete record here, i.e.,
`records.get(recordKey)`?
--
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]