@Test public void testShowCommits() throws Exception { CommandResult cr = getShell().executeCommand("show archived commits"); assertTrue(cr.isSuccess()); final List<Comparable[]> rows = new ArrayList<>(); TableHeader header = new TableHeader().addTableHeaderField("CommitTime").addTableHeaderField("CommitType"); for (int i = 100; i < 103; i++) { String instant = String.valueOf(i); Comparable[] result = new Comparable[] {instant, "commit"}; rows.add(result); rows.add(result); rows.add(result); } rows.add(new Comparable[] {"103", "commit"}); String expected = HoodiePrintHelper.print(header, new HashMap<>(), "", false, 10, false, rows); expected = removeNonWordAndStripSpace(expected); String got = removeNonWordAndStripSpace(cr.getResult().toString()); assertEquals(expected, got); cr = getShell().executeCommand("show archived commits --skipMetadata false --limit -1"); assertTrue(cr.isSuccess()); rows.clear(); for (int i = 100; i < 104; i++) { String instant = String.valueOf(i); HoodieCommitMetadata metadata = HoodieTestCommitMetadataGenerator.generateCommitMetadata(tablePath, instant); Comparable[] result = new Comparable[] { instant, "commit", HoodieTestCommitUtilities.convertAndOrderCommitMetadata(metadata)}; rows.add(result); rows.add(result); rows.add(result); } header = header.addTableHeaderField("CommitDetails"); expected = HoodiePrintHelper.print(header, new HashMap<>(), "", false, -1, false, rows); expected = removeNonWordAndStripSpace(expected); got = removeNonWordAndStripSpace(cr.getResult().toString()); assertEquals(expected, got); }
@CliCommand(value = "show archived commits", help = "Read commits from archived files and show details") public String showCommits( @CliOption(key = {"skipMetadata"}, help = "Skip displaying commit metadata", unspecifiedDefaultValue = "true") boolean skipMetadata, @CliOption(key = {"limit"}, help = "Limit commits", unspecifiedDefaultValue = "10") final Integer limit, @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField, @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending, @CliOption(key = {"headeronly"}, help = "Print Header Only", unspecifiedDefaultValue = "false") final boolean headerOnly) throws IOException { System.out.println("===============> Showing only " + limit + " archived commits <==============="); HoodieTableMetaClient metaClient = HoodieCLI.getTableMetaClient(); String basePath = metaClient.getBasePath(); Path archivePath = new Path(metaClient.getArchivePath() + "/.commits_.archive*"); FileStatus[] fsStatuses = FSUtils.getFs(basePath, HoodieCLI.conf).globStatus(archivePath); List<Comparable[]> allCommits = new ArrayList<>(); for (FileStatus fs : fsStatuses) { HoodieLogFormat.Reader reader = HoodieLogFormat.newReader(FSUtils.getFs(basePath, HoodieCLI.conf), new HoodieLogFile(fs.getPath()), HoodieArchivedMetaEntry.getClassSchema()); List<IndexedRecord> readRecords = new ArrayList<>(); while (reader.hasNext()) { HoodieAvroDataBlock blk = (HoodieAvroDataBlock) reader.next(); List<IndexedRecord> records = blk.getRecords(); readRecords.addAll(records); } List<Comparable[]> readCommits = readRecords.stream().map(r -> (GenericRecord) r) .map(r -> readCommit(r, skipMetadata)).collect(Collectors.toList()); allCommits.addAll(readCommits); reader.close(); } TableHeader header = new TableHeader().addTableHeaderField("CommitTime").addTableHeaderField("CommitType"); if (!skipMetadata) { header = header.addTableHeaderField("CommitDetails"); } return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, allCommits); }
ArchivedCommitsCommand implements CommandMarker { @CliCommand(value = "show archived commits", help = "Read commits from archived files and show details") public String showCommits( @CliOption(key = {"skipMetadata"}, help = "Skip displaying commit metadata", unspecifiedDefaultValue = "true") boolean skipMetadata, @CliOption(key = {"limit"}, help = "Limit commits", unspecifiedDefaultValue = "10") final Integer limit, @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField, @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending, @CliOption(key = {"headeronly"}, help = "Print Header Only", unspecifiedDefaultValue = "false") final boolean headerOnly) throws IOException { System.out.println("===============> Showing only " + limit + " archived commits <==============="); HoodieTableMetaClient metaClient = HoodieCLI.getTableMetaClient(); String basePath = metaClient.getBasePath(); Path archivePath = new Path(metaClient.getArchivePath() + "/.commits_.archive*"); FileStatus[] fsStatuses = FSUtils.getFs(basePath, HoodieCLI.conf).globStatus(archivePath); List<Comparable[]> allCommits = new ArrayList<>(); for (FileStatus fs : fsStatuses) { HoodieLogFormat.Reader reader = HoodieLogFormat.newReader(FSUtils.getFs(basePath, HoodieCLI.conf), new HoodieLogFile(fs.getPath()), HoodieArchivedMetaEntry.getClassSchema()); List<IndexedRecord> readRecords = new ArrayList<>(); while (reader.hasNext()) { HoodieAvroDataBlock blk = (HoodieAvroDataBlock) reader.next(); List<IndexedRecord> records = blk.getRecords(); readRecords.addAll(records); } List<Comparable[]> readCommits = readRecords.stream().map(r -> (GenericRecord) r) .map(r -> readCommit(r, skipMetadata)).collect(Collectors.toList()); allCommits.addAll(readCommits); reader.close(); } TableHeader header = new TableHeader().addTableHeaderField("CommitTime").addTableHeaderField("CommitType"); if (!skipMetadata) { header = header.addTableHeaderField("CommitDetails"); } return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, allCommits); } }
ArchivedCommitsCommand implements CommandMarker { @CliCommand(value = "show archived commits", help = "Read commits from archived files and show details") public String showCommits( @CliOption(key = {"skipMetadata"}, help = "Skip displaying commit metadata", unspecifiedDefaultValue = "true") boolean skipMetadata, @CliOption(key = {"limit"}, help = "Limit commits", unspecifiedDefaultValue = "10") final Integer limit, @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField, @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending, @CliOption(key = {"headeronly"}, help = "Print Header Only", unspecifiedDefaultValue = "false") final boolean headerOnly) throws IOException { System.out.println("===============> Showing only " + limit + " archived commits <==============="); HoodieTableMetaClient metaClient = HoodieCLI.getTableMetaClient(); String basePath = metaClient.getBasePath(); Path archivePath = new Path(metaClient.getArchivePath() + "/.commits_.archive*"); FileStatus[] fsStatuses = FSUtils.getFs(basePath, HoodieCLI.conf).globStatus(archivePath); List<Comparable[]> allCommits = new ArrayList<>(); for (FileStatus fs : fsStatuses) { HoodieLogFormat.Reader reader = HoodieLogFormat.newReader(FSUtils.getFs(basePath, HoodieCLI.conf), new HoodieLogFile(fs.getPath()), HoodieArchivedMetaEntry.getClassSchema()); List<IndexedRecord> readRecords = new ArrayList<>(); while (reader.hasNext()) { HoodieAvroDataBlock blk = (HoodieAvroDataBlock) reader.next(); List<IndexedRecord> records = blk.getRecords(); readRecords.addAll(records); } List<Comparable[]> readCommits = readRecords.stream().map(r -> (GenericRecord) r) .map(r -> readCommit(r, skipMetadata)).collect(Collectors.toList()); allCommits.addAll(readCommits); reader.close(); } TableHeader header = new TableHeader().addTableHeaderField("CommitTime").addTableHeaderField("CommitType"); if (!skipMetadata) { header = header.addTableHeaderField("CommitDetails"); } return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, allCommits); }  }
ArchivedCommitsCommand implements CommandMarker { @CliCommand(value = "show archived commits", help = "Read commits from archived files and show details") public String showCommits( @CliOption(key = {"skipMetadata"}, help = "Skip displaying commit metadata", unspecifiedDefaultValue = "true") boolean skipMetadata, @CliOption(key = {"limit"}, help = "Limit commits", unspecifiedDefaultValue = "10") final Integer limit, @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField, @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending, @CliOption(key = {"headeronly"}, help = "Print Header Only", unspecifiedDefaultValue = "false") final boolean headerOnly) throws IOException { System.out.println("===============> Showing only " + limit + " archived commits <==============="); HoodieTableMetaClient metaClient = HoodieCLI.getTableMetaClient(); String basePath = metaClient.getBasePath(); Path archivePath = new Path(metaClient.getArchivePath() + "/.commits_.archive*"); FileStatus[] fsStatuses = FSUtils.getFs(basePath, HoodieCLI.conf).globStatus(archivePath); List<Comparable[]> allCommits = new ArrayList<>(); for (FileStatus fs : fsStatuses) { HoodieLogFormat.Reader reader = HoodieLogFormat.newReader(FSUtils.getFs(basePath, HoodieCLI.conf), new HoodieLogFile(fs.getPath()), HoodieArchivedMetaEntry.getClassSchema()); List<IndexedRecord> readRecords = new ArrayList<>(); while (reader.hasNext()) { HoodieAvroDataBlock blk = (HoodieAvroDataBlock) reader.next(); List<IndexedRecord> records = blk.getRecords(); readRecords.addAll(records); } List<Comparable[]> readCommits = readRecords.stream().map(r -> (GenericRecord) r) .map(r -> readCommit(r, skipMetadata)).collect(Collectors.toList()); allCommits.addAll(readCommits); reader.close(); } TableHeader header = new TableHeader().addTableHeaderField("CommitTime").addTableHeaderField("CommitType"); if (!skipMetadata) { header = header.addTableHeaderField("CommitDetails"); } return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, allCommits); }  @CliCommand(value = "show archived commit stats", help = "Read commits from archived files and show details") String showArchivedCommits(
      @CliOption(key = {"archiveFolderPattern"}, help = "Archive Folder", unspecifiedDefaultValue = "") String folder,
      @CliOption(key = {"limit"}, help = "Limit commits", unspecifiedDefaultValue = "-1") final Integer limit,
      @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField,
      @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending,
      @CliOption(key = {"headeronly"}, help = "Print Header Only",
          unspecifiedDefaultValue = "false") final boolean headerOnly); @CliCommand(value = "show archived commits", help = "Read commits from archived files and show details") String showCommits(
      @CliOption(key = {"skipMetadata"}, help = "Skip displaying commit metadata",
          unspecifiedDefaultValue = "true") boolean skipMetadata,
      @CliOption(key = {"limit"}, help = "Limit commits", unspecifiedDefaultValue = "10") final Integer limit,
      @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField,
      @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending,
      @CliOption(key = {"headeronly"}, help = "Print Header Only",
          unspecifiedDefaultValue = "false") final boolean headerOnly); }
ArchivedCommitsCommand implements CommandMarker { @CliCommand(value = "show archived commits", help = "Read commits from archived files and show details") public String showCommits( @CliOption(key = {"skipMetadata"}, help = "Skip displaying commit metadata", unspecifiedDefaultValue = "true") boolean skipMetadata, @CliOption(key = {"limit"}, help = "Limit commits", unspecifiedDefaultValue = "10") final Integer limit, @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField, @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending, @CliOption(key = {"headeronly"}, help = "Print Header Only", unspecifiedDefaultValue = "false") final boolean headerOnly) throws IOException { System.out.println("===============> Showing only " + limit + " archived commits <==============="); HoodieTableMetaClient metaClient = HoodieCLI.getTableMetaClient(); String basePath = metaClient.getBasePath(); Path archivePath = new Path(metaClient.getArchivePath() + "/.commits_.archive*"); FileStatus[] fsStatuses = FSUtils.getFs(basePath, HoodieCLI.conf).globStatus(archivePath); List<Comparable[]> allCommits = new ArrayList<>(); for (FileStatus fs : fsStatuses) { HoodieLogFormat.Reader reader = HoodieLogFormat.newReader(FSUtils.getFs(basePath, HoodieCLI.conf), new HoodieLogFile(fs.getPath()), HoodieArchivedMetaEntry.getClassSchema()); List<IndexedRecord> readRecords = new ArrayList<>(); while (reader.hasNext()) { HoodieAvroDataBlock blk = (HoodieAvroDataBlock) reader.next(); List<IndexedRecord> records = blk.getRecords(); readRecords.addAll(records); } List<Comparable[]> readCommits = readRecords.stream().map(r -> (GenericRecord) r) .map(r -> readCommit(r, skipMetadata)).collect(Collectors.toList()); allCommits.addAll(readCommits); reader.close(); } TableHeader header = new TableHeader().addTableHeaderField("CommitTime").addTableHeaderField("CommitType"); if (!skipMetadata) { header = header.addTableHeaderField("CommitDetails"); } return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, allCommits); }  @CliCommand(value = "show archived commit stats", help = "Read commits from archived files and show details") String showArchivedCommits(
      @CliOption(key = {"archiveFolderPattern"}, help = "Archive Folder", unspecifiedDefaultValue = "") String folder,
      @CliOption(key = {"limit"}, help = "Limit commits", unspecifiedDefaultValue = "-1") final Integer limit,
      @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField,
      @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending,
      @CliOption(key = {"headeronly"}, help = "Print Header Only",
          unspecifiedDefaultValue = "false") final boolean headerOnly); @CliCommand(value = "show archived commits", help = "Read commits from archived files and show details") String showCommits(
      @CliOption(key = {"skipMetadata"}, help = "Skip displaying commit metadata",
          unspecifiedDefaultValue = "true") boolean skipMetadata,
      @CliOption(key = {"limit"}, help = "Limit commits", unspecifiedDefaultValue = "10") final Integer limit,
      @CliOption(key = {"sortBy"}, help = "Sorting Field", unspecifiedDefaultValue = "") final String sortByField,
      @CliOption(key = {"desc"}, help = "Ordering", unspecifiedDefaultValue = "false") final boolean descending,
      @CliOption(key = {"headeronly"}, help = "Print Header Only",
          unspecifiedDefaultValue = "false") final boolean headerOnly);  }