Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.hudi.common.table.log.HoodieLogFormat.Reader;
import org.apache.hudi.common.table.log.block.HoodieAvroDataBlock;
import org.apache.hudi.common.table.timeline.HoodieTimeline;
import org.apache.hudi.common.util.Option;

import org.apache.avro.generic.GenericRecord;
import org.apache.avro.generic.IndexedRecord;
Expand Down Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @hddong, how about return an empty array here as before. it seems will cause an NPE in org/apache/hudi/cli/HoodiePrintHelper.java:92

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wangxianghu : yes, empty is better here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wangxianghu : yes, empty is better here.

@hddong thanks for addressing my concern, LGTM now
cc @yanghua

}
return commitDetails.toArray(new Comparable[commitDetails.size()]);
}
}