You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2020/11/23 05:59:57 UTC

[GitHub] [hudi] hddong commented on a change in pull request #2246: [HUDI-1393]Add compaction action in archive command

hddong commented on a change in pull request #2246:
URL: https://github.com/apache/hudi/pull/2246#discussion_r528484320



##########
File path: hudi-cli/src/main/java/org/apache/hudi/cli/commands/ArchivedCommitsCommand.java
##########
@@ -172,49 +173,38 @@ public String showCommits(
     return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, allCommits);
   }
 
-  private Comparable[] readCommit(GenericRecord record, boolean skipMetadata) {
+  private Comparable[] commitDetail(GenericRecord record, String metadataName,
+                                    boolean skipMetadata) {
     List<Object> commitDetails = new ArrayList<>();
+    commitDetails.add(record.get("commitTime"));
+    commitDetails.add(record.get("actionType").toString());
+    if (!skipMetadata) {
+      commitDetails.add(Option.ofNullable(record.get(metadataName)).orElse("{}").toString());
+    }
+    return commitDetails.toArray(new Comparable[commitDetails.size()]);
+  }
+
+  private Comparable[] readCommit(GenericRecord record, boolean skipMetadata) {
     try {
       switch (record.get("actionType").toString()) {
-        case HoodieTimeline.CLEAN_ACTION: {
-          commitDetails.add(record.get("commitTime"));
-          commitDetails.add(record.get("actionType").toString());
-          if (!skipMetadata) {
-            commitDetails.add(record.get("hoodieCleanMetadata").toString());
-          }
-          break;
-        }
+        case HoodieTimeline.CLEAN_ACTION:
+          return commitDetail(record, "hoodieCleanMetadata", skipMetadata);
         case HoodieTimeline.COMMIT_ACTION:
-        case HoodieTimeline.DELTA_COMMIT_ACTION: {
-          commitDetails.add(record.get("commitTime"));
-          commitDetails.add(record.get("actionType").toString());
-          if (!skipMetadata) {
-            commitDetails.add(record.get("hoodieCommitMetadata").toString());
-          }
-          break;
-        }
-        case HoodieTimeline.ROLLBACK_ACTION: {
-          commitDetails.add(record.get("commitTime"));
-          commitDetails.add(record.get("actionType").toString());
-          if (!skipMetadata) {
-            commitDetails.add(record.get("hoodieRollbackMetadata").toString());
-          }
-          break;
+        case HoodieTimeline.DELTA_COMMIT_ACTION:
+          return commitDetail(record, "hoodieCommitMetadata", skipMetadata);
+        case HoodieTimeline.ROLLBACK_ACTION:
+          return commitDetail(record, "hoodieRollbackMetadata", skipMetadata);
+        case HoodieTimeline.SAVEPOINT_ACTION:
+          return commitDetail(record, "hoodieSavePointMetadata", skipMetadata);
+        case HoodieTimeline.COMPACTION_ACTION:
+          return commitDetail(record, "hoodieCompactionMetadata", skipMetadata);
+        default: {
+          return new Comparable[]{};
         }
-        case HoodieTimeline.SAVEPOINT_ACTION: {
-          commitDetails.add(record.get("commitTime"));
-          commitDetails.add(record.get("actionType").toString());
-          if (!skipMetadata) {
-            commitDetails.add(record.get("hoodieSavePointMetadata").toString());
-          }
-          break;
-        }
-        default:
-          return commitDetails.toArray(new Comparable[commitDetails.size()]);
       }
     } catch (Exception e) {
       e.printStackTrace();
+      return null;

Review comment:
       @wangxianghu : yes, empty is better here.




----------------------------------------------------------------
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:
users@infra.apache.org