Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CD7E6109AF for ; Wed, 13 Nov 2013 19:20:16 +0000 (UTC) Received: (qmail 59342 invoked by uid 500); 13 Nov 2013 19:20:16 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 59307 invoked by uid 500); 13 Nov 2013 19:20:16 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 59300 invoked by uid 99); 13 Nov 2013 19:20:16 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Nov 2013 19:20:16 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 673488A857D; Wed, 13 Nov 2013 19:20:16 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ecn@apache.org To: commits@accumulo.apache.org Message-Id: <008d0254f75c418f9e0709eed56d0d5c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: ACCUMULO-748 applying [~treardon]'s patch, added unit test Date: Wed, 13 Nov 2013 19:20:16 +0000 (UTC) Updated Branches: refs/heads/1.6.0-SNAPSHOT fce4ee74e -> 9c16ef015 ACCUMULO-748 applying [~treardon]'s patch, added unit test Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/9c16ef01 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/9c16ef01 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/9c16ef01 Branch: refs/heads/1.6.0-SNAPSHOT Commit: 9c16ef0153b9f47cfcf3b54b19563b713af2cad3 Parents: fce4ee7 Author: Eric Newton Authored: Wed Nov 13 14:20:03 2013 -0500 Committer: Eric Newton Committed: Wed Nov 13 14:20:03 2013 -0500 ---------------------------------------------------------------------- .../core/util/shell/commands/TablesCommand.java | 34 ++++++++++++++++---- .../org/apache/accumulo/test/ShellServerIT.java | 11 +++++++ 2 files changed, 38 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/9c16ef01/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TablesCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TablesCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TablesCommand.java index 19b49e9..e1fb4b3 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TablesCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TablesCommand.java @@ -29,37 +29,55 @@ import org.apache.accumulo.core.util.shell.Shell.Command; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; +import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.iterators.AbstractIteratorDecorator; public class TablesCommand extends Command { + private static final String NAME_AND_ID_FORMAT = "%-15s => %10s%n"; + private Option tableIdOption; + private Option sortByTableIdOption; private Option disablePaginationOpt; @SuppressWarnings("unchecked") @Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException { + Iterator it = null; if (cl.hasOption(tableIdOption.getOpt())) { - final Map tableIds = new TreeMap(shellState.getConnector().tableOperations().tableIdMap()); - shellState.printLines(new TableIdIterator(tableIds.entrySet().iterator()), !cl.hasOption(disablePaginationOpt.getOpt())); + it = new TableIdIterator(shellState.getConnector().tableOperations().tableIdMap(), cl.hasOption(sortByTableIdOption.getOpt())); } else { - shellState.printLines(shellState.getConnector().tableOperations().list().iterator(), !cl.hasOption(disablePaginationOpt.getOpt())); + it = shellState.getConnector().tableOperations().list().iterator(); } + + shellState.printLines(it, !cl.hasOption(disablePaginationOpt.getOpt())); return 0; } /** - * Decorator that formats table id and name for display. + * Decorator that formats table name and id for display. */ private static final class TableIdIterator extends AbstractIteratorDecorator { - public TableIdIterator(Iterator> iterator) { - super(iterator); + private final boolean sortByTableId; + + /** + * @param tableIdMap tableName -> tableId + * @param sortByTableId + */ + @SuppressWarnings("unchecked") + public TableIdIterator(Map tableIdMap, boolean sortByTableId) { + super(new TreeMap((sortByTableId ? MapUtils.invertMap(tableIdMap) : tableIdMap)).entrySet().iterator()); + this.sortByTableId = sortByTableId; } @SuppressWarnings("rawtypes") @Override public Object next() { Entry entry = (Entry) super.next(); - return String.format("%-15s => %10s%n", entry.getKey(), entry.getValue()); + if (sortByTableId) { + return String.format(NAME_AND_ID_FORMAT, entry.getValue(), entry.getKey()); + } else { + return String.format(NAME_AND_ID_FORMAT, entry.getKey(), entry.getValue()); + } } } @@ -73,6 +91,8 @@ public class TablesCommand extends Command { final Options o = new Options(); tableIdOption = new Option("l", "list-ids", false, "display internal table ids along with the table name"); o.addOption(tableIdOption); + sortByTableIdOption = new Option("s", "sort-ids", false, "with -l: sort output by table ids"); + o.addOption(sortByTableIdOption); disablePaginationOpt = new Option("np", "no-pagination", false, "disable pagination of output"); o.addOption(disablePaginationOpt); return o; http://git-wip-us.apache.org/repos/asf/accumulo/blob/9c16ef01/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java b/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java index 31867f3..dbf5f4c 100644 --- a/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java +++ b/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java @@ -718,6 +718,17 @@ public class ShellServerIT extends SimpleMacIT { exec("scan -t xyzzy", true, "value", true); exec("deletetable -f xyzzy", true); } + + @Test(timeout = 30 * 1000) + public void tables() throws Exception { + exec("createtable zzzz"); + exec("createtable aaaa"); + exec("notable"); + String lst = exec("tables -l"); + assertTrue(lst.indexOf("aaaa") < lst.indexOf("zzzz")); + lst = exec("tables -l -s"); + assertTrue(lst.indexOf("zzzz") < lst.indexOf("aaaa")); + } @Test(timeout = 30 * 1000) public void systempermission() throws Exception {