@Test public void testShowRollbacks() { CommandResult cr = getShell().executeCommand("show rollbacks"); assertTrue(cr.isSuccess()); HoodieActiveTimeline activeTimeline = new RollbacksCommand.RollbackTimeline(HoodieCLI.getTableMetaClient()); Stream<HoodieInstant> rollback = activeTimeline.getRollbackTimeline().filterCompletedInstants().getInstants(); List<Comparable[]> rows = new ArrayList<>(); rollback.sorted().forEach(instant -> { try { HoodieRollbackMetadata metadata = TimelineMetadataUtils .deserializeAvroMetadata(activeTimeline.getInstantDetails(instant).get(), HoodieRollbackMetadata.class); metadata.getCommitsRollback().forEach(c -> { Comparable[] row = new Comparable[5]; row[0] = metadata.getStartRollbackTime(); row[1] = c; row[2] = 3; row[3] = metadata.getTimeTakenInMillis(); row[4] = 3; rows.add(row); }); } catch (IOException e) { e.printStackTrace(); } }); TableHeader header = new TableHeader().addTableHeaderField(HoodieTableHeaderFields.HEADER_INSTANT) .addTableHeaderField(HoodieTableHeaderFields.HEADER_ROLLBACK_INSTANT) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_FILES_DELETED) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TIME_TOKEN_MILLIS) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_PARTITIONS); String expected = HoodiePrintHelper.print(header, new HashMap<>(), "", false, -1, false, rows); expected = removeNonWordAndStripSpace(expected); String got = removeNonWordAndStripSpace(cr.getResult().toString()); assertEquals(expected, got); }
@CliCommand(value = "show rollbacks", help = "List all rollback instants") public String showRollbacks( @CliOption(key = {"limit"}, help = "Limit #rows to be displayed", unspecifiedDefaultValue = "10") 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) { HoodieActiveTimeline activeTimeline = new RollbackTimeline(HoodieCLI.getTableMetaClient()); HoodieTimeline rollback = activeTimeline.getRollbackTimeline().filterCompletedInstants(); final List<Comparable[]> rows = new ArrayList<>(); rollback.getInstants().forEach(instant -> { try { HoodieRollbackMetadata metadata = TimelineMetadataUtils .deserializeAvroMetadata(activeTimeline.getInstantDetails(instant).get(), HoodieRollbackMetadata.class); metadata.getCommitsRollback().forEach(c -> { Comparable[] row = new Comparable[5]; row[0] = metadata.getStartRollbackTime(); row[1] = c; row[2] = metadata.getTotalFilesDeleted(); row[3] = metadata.getTimeTakenInMillis(); row[4] = metadata.getPartitionMetadata() != null ? metadata.getPartitionMetadata().size() : 0; rows.add(row); }); } catch (IOException e) { e.printStackTrace(); } }); TableHeader header = new TableHeader().addTableHeaderField(HoodieTableHeaderFields.HEADER_INSTANT) .addTableHeaderField(HoodieTableHeaderFields.HEADER_ROLLBACK_INSTANT) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_FILES_DELETED) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TIME_TOKEN_MILLIS) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_PARTITIONS); return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, rows); }
RollbacksCommand implements CommandMarker { @CliCommand(value = "show rollbacks", help = "List all rollback instants") public String showRollbacks( @CliOption(key = {"limit"}, help = "Limit #rows to be displayed", unspecifiedDefaultValue = "10") 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) { HoodieActiveTimeline activeTimeline = new RollbackTimeline(HoodieCLI.getTableMetaClient()); HoodieTimeline rollback = activeTimeline.getRollbackTimeline().filterCompletedInstants(); final List<Comparable[]> rows = new ArrayList<>(); rollback.getInstants().forEach(instant -> { try { HoodieRollbackMetadata metadata = TimelineMetadataUtils .deserializeAvroMetadata(activeTimeline.getInstantDetails(instant).get(), HoodieRollbackMetadata.class); metadata.getCommitsRollback().forEach(c -> { Comparable[] row = new Comparable[5]; row[0] = metadata.getStartRollbackTime(); row[1] = c; row[2] = metadata.getTotalFilesDeleted(); row[3] = metadata.getTimeTakenInMillis(); row[4] = metadata.getPartitionMetadata() != null ? metadata.getPartitionMetadata().size() : 0; rows.add(row); }); } catch (IOException e) { e.printStackTrace(); } }); TableHeader header = new TableHeader().addTableHeaderField(HoodieTableHeaderFields.HEADER_INSTANT) .addTableHeaderField(HoodieTableHeaderFields.HEADER_ROLLBACK_INSTANT) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_FILES_DELETED) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TIME_TOKEN_MILLIS) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_PARTITIONS); return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, rows); } }
RollbacksCommand implements CommandMarker { @CliCommand(value = "show rollbacks", help = "List all rollback instants") public String showRollbacks( @CliOption(key = {"limit"}, help = "Limit #rows to be displayed", unspecifiedDefaultValue = "10") 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) { HoodieActiveTimeline activeTimeline = new RollbackTimeline(HoodieCLI.getTableMetaClient()); HoodieTimeline rollback = activeTimeline.getRollbackTimeline().filterCompletedInstants(); final List<Comparable[]> rows = new ArrayList<>(); rollback.getInstants().forEach(instant -> { try { HoodieRollbackMetadata metadata = TimelineMetadataUtils .deserializeAvroMetadata(activeTimeline.getInstantDetails(instant).get(), HoodieRollbackMetadata.class); metadata.getCommitsRollback().forEach(c -> { Comparable[] row = new Comparable[5]; row[0] = metadata.getStartRollbackTime(); row[1] = c; row[2] = metadata.getTotalFilesDeleted(); row[3] = metadata.getTimeTakenInMillis(); row[4] = metadata.getPartitionMetadata() != null ? metadata.getPartitionMetadata().size() : 0; rows.add(row); }); } catch (IOException e) { e.printStackTrace(); } }); TableHeader header = new TableHeader().addTableHeaderField(HoodieTableHeaderFields.HEADER_INSTANT) .addTableHeaderField(HoodieTableHeaderFields.HEADER_ROLLBACK_INSTANT) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_FILES_DELETED) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TIME_TOKEN_MILLIS) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_PARTITIONS); return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, rows); }  }
RollbacksCommand implements CommandMarker { @CliCommand(value = "show rollbacks", help = "List all rollback instants") public String showRollbacks( @CliOption(key = {"limit"}, help = "Limit #rows to be displayed", unspecifiedDefaultValue = "10") 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) { HoodieActiveTimeline activeTimeline = new RollbackTimeline(HoodieCLI.getTableMetaClient()); HoodieTimeline rollback = activeTimeline.getRollbackTimeline().filterCompletedInstants(); final List<Comparable[]> rows = new ArrayList<>(); rollback.getInstants().forEach(instant -> { try { HoodieRollbackMetadata metadata = TimelineMetadataUtils .deserializeAvroMetadata(activeTimeline.getInstantDetails(instant).get(), HoodieRollbackMetadata.class); metadata.getCommitsRollback().forEach(c -> { Comparable[] row = new Comparable[5]; row[0] = metadata.getStartRollbackTime(); row[1] = c; row[2] = metadata.getTotalFilesDeleted(); row[3] = metadata.getTimeTakenInMillis(); row[4] = metadata.getPartitionMetadata() != null ? metadata.getPartitionMetadata().size() : 0; rows.add(row); }); } catch (IOException e) { e.printStackTrace(); } }); TableHeader header = new TableHeader().addTableHeaderField(HoodieTableHeaderFields.HEADER_INSTANT) .addTableHeaderField(HoodieTableHeaderFields.HEADER_ROLLBACK_INSTANT) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_FILES_DELETED) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TIME_TOKEN_MILLIS) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_PARTITIONS); return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, rows); }  @CliCommand(value = "show rollbacks", help = "List all rollback instants") String showRollbacks(
      @CliOption(key = {"limit"}, help = "Limit #rows to be displayed", unspecifiedDefaultValue = "10") 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 rollback", help = "Show details of a rollback instant") String showRollback(
      @CliOption(key = {"instant"}, help = "Rollback instant", mandatory = true) String rollbackInstant,
      @CliOption(key = {"limit"}, help = "Limit  #rows to be displayed", unspecifiedDefaultValue = "10") 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); }
RollbacksCommand implements CommandMarker { @CliCommand(value = "show rollbacks", help = "List all rollback instants") public String showRollbacks( @CliOption(key = {"limit"}, help = "Limit #rows to be displayed", unspecifiedDefaultValue = "10") 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) { HoodieActiveTimeline activeTimeline = new RollbackTimeline(HoodieCLI.getTableMetaClient()); HoodieTimeline rollback = activeTimeline.getRollbackTimeline().filterCompletedInstants(); final List<Comparable[]> rows = new ArrayList<>(); rollback.getInstants().forEach(instant -> { try { HoodieRollbackMetadata metadata = TimelineMetadataUtils .deserializeAvroMetadata(activeTimeline.getInstantDetails(instant).get(), HoodieRollbackMetadata.class); metadata.getCommitsRollback().forEach(c -> { Comparable[] row = new Comparable[5]; row[0] = metadata.getStartRollbackTime(); row[1] = c; row[2] = metadata.getTotalFilesDeleted(); row[3] = metadata.getTimeTakenInMillis(); row[4] = metadata.getPartitionMetadata() != null ? metadata.getPartitionMetadata().size() : 0; rows.add(row); }); } catch (IOException e) { e.printStackTrace(); } }); TableHeader header = new TableHeader().addTableHeaderField(HoodieTableHeaderFields.HEADER_INSTANT) .addTableHeaderField(HoodieTableHeaderFields.HEADER_ROLLBACK_INSTANT) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_FILES_DELETED) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TIME_TOKEN_MILLIS) .addTableHeaderField(HoodieTableHeaderFields.HEADER_TOTAL_PARTITIONS); return HoodiePrintHelper.print(header, new HashMap<>(), sortByField, descending, limit, headerOnly, rows); }  @CliCommand(value = "show rollbacks", help = "List all rollback instants") String showRollbacks(
      @CliOption(key = {"limit"}, help = "Limit #rows to be displayed", unspecifiedDefaultValue = "10") 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 rollback", help = "Show details of a rollback instant") String showRollback(
      @CliOption(key = {"instant"}, help = "Rollback instant", mandatory = true) String rollbackInstant,
      @CliOption(key = {"limit"}, help = "Limit  #rows to be displayed", unspecifiedDefaultValue = "10") 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);  }