You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "danny0405 (via GitHub)" <gi...@apache.org> on 2023/02/14 10:46:45 UTC

[GitHub] [hudi] danny0405 commented on a diff in pull request #7752: [MINOR] De-duplicating Iterator implementations

danny0405 commented on code in PR #7752:
URL: https://github.com/apache/hudi/pull/7752#discussion_r1105614300


##########
hudi-common/src/main/java/org/apache/hudi/common/table/log/AbstractHoodieLogRecordReader.java:
##########
@@ -807,16 +809,17 @@ private ClosableIteratorWithSchema<HoodieRecord> getRecordsIterator(
 
     Option<Pair<Function<HoodieRecord, HoodieRecord>, Schema>> schemaEvolutionTransformerOpt =
         composeEvolvedSchemaTransformer(dataBlock);
+
     // In case when schema has been evolved original persisted records will have to be
     // transformed to adhere to the new schema
-    if (schemaEvolutionTransformerOpt.isPresent()) {
-      return ClosableIteratorWithSchema.newInstance(
-          new CloseableMappingIterator<>(blockRecordsIterator,
-              schemaEvolutionTransformerOpt.get().getLeft()),
-          schemaEvolutionTransformerOpt.get().getRight());
-    } else {
-      return ClosableIteratorWithSchema.newInstance(blockRecordsIterator, dataBlock.getSchema());
-    }
+    Function<HoodieRecord, HoodieRecord> transformer =
+        schemaEvolutionTransformerOpt.map(Pair::getLeft)
+            .orElse(Function.identity());
+
+    Schema schema = schemaEvolutionTransformerOpt.map(Pair::getRight)
+        .orElse(dataBlock.getSchema());
+

Review Comment:
   The code looks clean but for use case when `schemaEvolutionTransformerOpt.isPresent()` is false, there is unnecessary invocation of `Function.identity()`.



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org