This is an automated email from the ASF dual-hosted git repository. ctubbsii pushed a commit to branch 2.1 in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.1 by this push: new db98f7d988 Fix show-few option for ScanCommand (#3905) db98f7d988 is described below commit db98f7d9888cddc8b9e19aa120ea395d8d857c91 Author: rsingh433 <74160026+rsingh...@users.noreply.github.com> AuthorDate: Tue Nov 14 11:03:39 2023 -0500 Fix show-few option for ScanCommand (#3905) Fix `-f, --show-few` options for ScanCommand and subclasses * Make GrepCommand (and EGrepCommand) respect the show-few option * Suppress the show-few option from appearing in the DeleteManyCommand, which has its own `-f, --force` option --------- Co-authored-by: Christopher Tubbs <ctubb...@apache.org> --- .../org/apache/accumulo/shell/commands/GrepCommand.java | 16 ++++++++++++++-- .../org/apache/accumulo/shell/commands/ScanCommand.java | 10 +++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/GrepCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/GrepCommand.java index f22339c53b..90c4a6fb44 100644 --- a/shell/src/main/java/org/apache/accumulo/shell/commands/GrepCommand.java +++ b/shell/src/main/java/org/apache/accumulo/shell/commands/GrepCommand.java @@ -49,6 +49,20 @@ public class GrepCommand extends ScanCommand { if (cl.getArgList().isEmpty()) { throw new MissingArgumentException("No terms specified"); } + // Configure formatting options + final FormatterConfig config = new FormatterConfig(); + config.setPrintTimestamps(cl.hasOption(timestampOpt.getOpt())); + if (cl.hasOption(showFewOpt.getOpt())) { + final String showLength = cl.getOptionValue(showFewOpt.getOpt()); + try { + final int length = Integer.parseInt(showLength); + config.setShownLength(length); + } catch (NumberFormatException nfe) { + Shell.log.error("Arg must be an integer.", nfe); + } catch (IllegalArgumentException iae) { + Shell.log.error("Arg must be greater than one.", iae); + } + } final Class<? extends Formatter> formatter = getFormatter(cl, tableName, shellState); @SuppressWarnings("deprecation") final org.apache.accumulo.core.util.interpret.ScanInterpreter interpeter = @@ -87,8 +101,6 @@ public class GrepCommand extends ScanCommand { fetchColumns(cl, scanner, interpeter); // output the records - final FormatterConfig config = new FormatterConfig(); - config.setPrintTimestamps(cl.hasOption(timestampOpt.getOpt())); printRecords(cl, shellState, config, scanner, formatter, printFile); } finally { scanner.close(); diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/ScanCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/ScanCommand.java index 76337d1b12..12ccc94350 100644 --- a/shell/src/main/java/org/apache/accumulo/shell/commands/ScanCommand.java +++ b/shell/src/main/java/org/apache/accumulo/shell/commands/ScanCommand.java @@ -57,9 +57,10 @@ import org.apache.hadoop.io.Text; public class ScanCommand extends Command { - private Option scanOptAuths, scanOptRow, scanOptColumns, disablePaginationOpt, showFewOpt, - formatterOpt, interpreterOpt, formatterInterpeterOpt, outputFileOpt, scanOptCf, scanOptCq; + private Option scanOptAuths, scanOptRow, scanOptColumns, disablePaginationOpt, formatterOpt, + interpreterOpt, formatterInterpeterOpt, outputFileOpt, scanOptCf, scanOptCq; + protected Option showFewOpt; protected Option timestampOpt; protected Option profileOpt; private Option optStartRowExclusive; @@ -110,8 +111,7 @@ public class ScanCommand extends Command { if (cl.hasOption(contextOpt.getOpt())) { classLoaderContext = cl.getOptionValue(contextOpt.getOpt()); } - // handle first argument, if present, the authorizations list to - // scan with + // handle first argument, if present, the authorizations list to scan with final Authorizations auths = getAuths(cl, shellState); final Scanner scanner = shellState.getAccumuloClient().createScanner(tableName, auths); if (classLoaderContext != null) { @@ -481,7 +481,6 @@ public class ScanCommand extends Command { o.addOption(timestampOpt); o.addOption(disablePaginationOpt); o.addOption(OptUtil.tableOpt("table to be scanned")); - o.addOption(showFewOpt); o.addOption(formatterOpt); o.addOption(interpreterOpt); o.addOption(formatterInterpeterOpt); @@ -491,6 +490,7 @@ public class ScanCommand extends Command { // supported subclasses must handle the output file option properly // only add this option to commands which handle it correctly o.addOption(outputFileOpt); + o.addOption(showFewOpt); } o.addOption(profileOpt); o.addOption(sampleOpt);