bvaradar commented on a change in pull request #2141:
URL: https://github.com/apache/hudi/pull/2141#discussion_r498938639
##########
File path:
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/table/action/commit/SparkWriteHelper.java
##########
@@ -49,21 +52,48 @@ public static SparkWriteHelper newInstance() {
@Override
public JavaRDD<HoodieRecord<T>> deduplicateRecords(JavaRDD<HoodieRecord<T>>
records,
HoodieIndex<T,
JavaRDD<HoodieRecord<T>>, JavaRDD<HoodieKey>, JavaRDD<WriteStatus>> index,
- int parallelism) {
- boolean isIndexingGlobal = index.isGlobal();
- return records.mapToPair(record -> {
- HoodieKey hoodieKey = record.getKey();
- // If index used is global, then records are expected to differ in their
partitionPath
- Object key = isIndexingGlobal ? hoodieKey.getRecordKey() : hoodieKey;
- return new Tuple2<>(key, record);
- }).reduceByKey((rec1, rec2) -> {
- @SuppressWarnings("unchecked")
- T reducedData = (T) rec1.getData().preCombine(rec2.getData());
- // we cannot allow the user to change the key or partitionPath, since
that will affect
- // everything
- // so pick it from one of the records.
- return new HoodieRecord<T>(rec1.getKey(), reducedData);
- }, parallelism).map(Tuple2::_2);
+ HoodieWriteConfig
writeConfig, int parallelism) {
+ return new RecordDeduper<T>(index.isGlobal(), writeConfig.getSchema(),
parallelism).deduplicateRecords(records);
}
+ /**
+ * Helper class to dedupe records.
+ * @param <T>
+ */
+ private static class RecordDeduper<T extends HoodieRecordPayload> implements
Serializable {
Review comment:
Made this to a class to take advantatage of lazy creation of Schema in
executors.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]