nsivabalan commented on code in PR #13157:
URL: https://github.com/apache/hudi/pull/13157#discussion_r2049452602


##########
hudi-common/src/test/java/org/apache/hudi/common/table/read/TestHoodieFileGroupReaderBase.java:
##########
@@ -366,4 +400,70 @@ private boolean shouldValidatePartialRead(FileSlice 
fileSlice, Schema requestedS
     }
     return false;
   }
+
+  private List<HoodieRecord> mergeRecordLists(List<HoodieRecord> updates, 
List<HoodieRecord> existing) {
+    Set<String> updatedKeys = 
updates.stream().map(HoodieRecord::getRecordKey).collect(Collectors.toSet());
+    return Stream.concat(updates.stream(), existing.stream().filter(record -> 
!updatedKeys.contains(record.getRecordKey())))
+            .collect(Collectors.toList());
+  }
+
+  private List<RecordIdentifier> convertHoodieRecords(List<HoodieRecord> 
records, Schema schema) {
+    int keyFieldIndex = schema.getField(KEY_FIELD_NAME).pos();
+    int orderingFieldIndex = schema.getField(PRECOMBINE_FIELD_NAME).pos();
+    int partitionFieldIndex = schema.getField(PARTITION_FIELD_NAME).pos();
+    int riderFieldIndex = schema.getField(RIDER_FIELD_NAME).pos();
+    return records.stream().map(record -> {
+      try {
+        RawTripTestPayload payload = (RawTripTestPayload) record.getData();
+        IndexedRecord indexedRecord = payload.getRecordToInsert(schema);
+        return new 
RecordIdentifier(indexedRecord.get(keyFieldIndex).toString(), 
indexedRecord.get(orderingFieldIndex).toString(),
+            indexedRecord.get(partitionFieldIndex).toString(), 
indexedRecord.get(riderFieldIndex).toString());
+      } catch (IOException e) {
+        throw new UncheckedIOException(e);
+      }
+    }).collect(Collectors.toList());
+  }
+
+  private List<RecordIdentifier> convertEngineRecords(List<T> records, Schema 
schema, HoodieReaderContext<T> readerContext) {
+    return records.stream()
+        .map(record -> new RecordIdentifier(readerContext.getValue(record, 
schema, KEY_FIELD_NAME).toString(),
+            readerContext.getValue(record, schema, 
PRECOMBINE_FIELD_NAME).toString(),
+            readerContext.getValue(record, schema, 
PARTITION_FIELD_NAME).toString(),
+            readerContext.getValue(record, schema, 
RIDER_FIELD_NAME).toString()))
+        .collect(Collectors.toList());
+  }
+
+  /**
+   * Used for equality checks between the expected and actual records for the 
FileGroupReader.
+   */
+  private static class RecordIdentifier {

Review Comment:
   do you think we can move this to HoodieTestDataGenerator only and also, 
converting from HoodieRecord to RecordIndentifier so that we can start using it 
across the board for test assertions. 



##########
hudi-common/src/test/java/org/apache/hudi/common/testutils/HoodieTestDataGenerator.java:
##########
@@ -952,10 +952,15 @@ public List<HoodieRecord> generateUpdates(String 
instantTime, Integer n) throws
    */
   public List<HoodieRecord> generateUpdates(String instantTime, Integer n, 
String schemaStr) throws IOException {
     List<HoodieRecord> updates = new ArrayList<>();
+    Map<Integer, KeyPartition> existingKeys = 
existingKeysBySchema.get(schemaStr);

Review Comment:
   we do have another method called generateUniqueUpdates. may be we can dedup 
and retain just 1 method. 



##########
hudi-common/src/test/java/org/apache/hudi/common/table/read/TestHoodieFileGroupReaderBase.java:
##########
@@ -366,4 +400,70 @@ private boolean shouldValidatePartialRead(FileSlice 
fileSlice, Schema requestedS
     }
     return false;
   }
+
+  private List<HoodieRecord> mergeRecordLists(List<HoodieRecord> updates, 
List<HoodieRecord> existing) {
+    Set<String> updatedKeys = 
updates.stream().map(HoodieRecord::getRecordKey).collect(Collectors.toSet());
+    return Stream.concat(updates.stream(), existing.stream().filter(record -> 
!updatedKeys.contains(record.getRecordKey())))
+            .collect(Collectors.toList());
+  }
+
+  private List<RecordIdentifier> convertHoodieRecords(List<HoodieRecord> 
records, Schema schema) {
+    int keyFieldIndex = schema.getField(KEY_FIELD_NAME).pos();
+    int orderingFieldIndex = schema.getField(PRECOMBINE_FIELD_NAME).pos();
+    int partitionFieldIndex = schema.getField(PARTITION_FIELD_NAME).pos();
+    int riderFieldIndex = schema.getField(RIDER_FIELD_NAME).pos();
+    return records.stream().map(record -> {
+      try {
+        RawTripTestPayload payload = (RawTripTestPayload) record.getData();
+        IndexedRecord indexedRecord = payload.getRecordToInsert(schema);
+        return new 
RecordIdentifier(indexedRecord.get(keyFieldIndex).toString(), 
indexedRecord.get(orderingFieldIndex).toString(),
+            indexedRecord.get(partitionFieldIndex).toString(), 
indexedRecord.get(riderFieldIndex).toString());
+      } catch (IOException e) {
+        throw new UncheckedIOException(e);
+      }
+    }).collect(Collectors.toList());
+  }
+
+  private List<RecordIdentifier> convertEngineRecords(List<T> records, Schema 
schema, HoodieReaderContext<T> readerContext) {
+    return records.stream()
+        .map(record -> new RecordIdentifier(readerContext.getValue(record, 
schema, KEY_FIELD_NAME).toString(),
+            readerContext.getValue(record, schema, 
PRECOMBINE_FIELD_NAME).toString(),
+            readerContext.getValue(record, schema, 
PARTITION_FIELD_NAME).toString(),
+            readerContext.getValue(record, schema, 
RIDER_FIELD_NAME).toString()))
+        .collect(Collectors.toList());
+  }
+
+  /**
+   * Used for equality checks between the expected and actual records for the 
FileGroupReader.
+   */
+  private static class RecordIdentifier {
+    private final String recordKey;
+    private final String orderingVal;
+    private final String partitionPath;
+    private final String riderValue;

Review Comment:
   if I am not wrong, for a given batch of records generated using 
HoodieTestDataGenerator, we will have same value for rider. Can we also pick 
"fare" column may be since its expected to have diff values for diff records. 
   not too strong on this suggestion. will let you take a call. 



-- 
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]

Reply via email to