From commits-return-24328-archive-asf-public=cust-asf.ponee.io@accumulo.apache.org Tue Nov 10 16:54:45 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mxout1-ec2-va.apache.org (mxout1-ec2-va.apache.org [3.227.148.255]) by mx-eu-01.ponee.io (Postfix) with ESMTPS id 14250180181 for ; Tue, 10 Nov 2020 17:54:45 +0100 (CET) Received: from mail.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by mxout1-ec2-va.apache.org (ASF Mail Server at mxout1-ec2-va.apache.org) with SMTP id 50E1746270 for ; Tue, 10 Nov 2020 16:54:44 +0000 (UTC) Received: (qmail 40802 invoked by uid 500); 10 Nov 2020 16:54:44 -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 40788 invoked by uid 99); 10 Nov 2020 16:54:43 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Nov 2020 16:54:43 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id CE51D820F7; Tue, 10 Nov 2020 16:54:43 +0000 (UTC) Date: Tue, 10 Nov 2020 16:54:43 +0000 To: "commits@accumulo.apache.org" Subject: [accumulo] branch main updated: Add tablename option to shell insert command. (#1771) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <160502728367.22857.16661978654881213553@gitbox.apache.org> From: jmark99@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: accumulo X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Oldrev: 18ba45e144ea8213a9637fe36bf0d8a68c3f15f5 X-Git-Newrev: 7e563c8e9ef94991efe3fde12f48b2e8e68cd964 X-Git-Rev: 7e563c8e9ef94991efe3fde12f48b2e8e68cd964 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. jmark99 pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo.git The following commit(s) were added to refs/heads/main by this push: new 7e563c8 Add tablename option to shell insert command. (#1771) 7e563c8 is described below commit 7e563c8e9ef94991efe3fde12f48b2e8e68cd964 Author: Mark Owens AuthorDate: Tue Nov 10 11:51:33 2020 -0500 Add tablename option to shell insert command. (#1771) This change adds the --table/-t option to the insert command when inside the shell or when using the accumulo command with 'accumulo shell -e '. The option is not required, but if used it allows data to be inserted into a table in situations where the shell is not within a table context or when in a table context to insert data into another table. Although I would not expect this option to be utilized very often, I found myself in need of it when working with the various accumulo examples in the accumulo-examples repo. I had many situations where I wished to insert some test data from a bash shell using the 'accumulo shell -e insert r f q v' form but this would fail due to there being no table context for the insertion. This update allows data inserts from a command line using the 'accumulo shell' format. --- .../accumulo/shell/commands/InsertCommand.java | 8 ++-- .../java/org/apache/accumulo/test/ShellIT.java | 49 ++++++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/InsertCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/InsertCommand.java index 051e307..283387f 100644 --- a/shell/src/main/java/org/apache/accumulo/shell/commands/InsertCommand.java +++ b/shell/src/main/java/org/apache/accumulo/shell/commands/InsertCommand.java @@ -63,7 +63,8 @@ public class InsertCommand extends Command { public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException, ConstraintViolationException { - shellState.checkTableState(); + + final String tableName = OptUtil.getTableOpt(cl, shellState); final Mutation m = new Mutation(new Text(cl.getArgs()[0].getBytes(Shell.CHARSET))); final Text colf = new Text(cl.getArgs()[1].getBytes(Shell.CHARSET)); @@ -105,8 +106,7 @@ public class InsertCommand extends Command { throw new IllegalArgumentException("Unknown durability: " + userDurability); } } - final BatchWriter bw = - shellState.getAccumuloClient().createBatchWriter(shellState.getTableName(), cfg); + final BatchWriter bw = shellState.getAccumuloClient().createBatchWriter(tableName, cfg); bw.addMutation(m); try { bw.close(); @@ -171,6 +171,8 @@ public class InsertCommand extends Command { "durability to use for insert, should be one of \"none\" \"log\" \"flush\" or \"sync\""); o.addOption(durabilityOption); + o.addOption(OptUtil.tableOpt("table into which data will be inserted")); + return o; } diff --git a/test/src/main/java/org/apache/accumulo/test/ShellIT.java b/test/src/main/java/org/apache/accumulo/test/ShellIT.java index 753aeca..a109f2d 100644 --- a/test/src/main/java/org/apache/accumulo/test/ShellIT.java +++ b/test/src/main/java/org/apache/accumulo/test/ShellIT.java @@ -239,6 +239,55 @@ public class ShellIT extends SharedMiniClusterBase { } @Test + public void insertIntoSpecifiedTableTest() throws IOException { + Shell.log.debug("Starting insertIntoSpecifiedTableTest -----------------"); + // create two tables for insertion tests + exec("createtable tab1", true); + exec("createtable tab2", true); + // insert data into tab2 while in tab2 context + exec("insert row1 f q tab2", true); + // insert another with the table and t argument to verify also works + exec("insert row2 f q tab2 --table tab2", true); + exec("insert row3 f q tab2 -t tab2", true); + // leave all table contexts + exec("notable", true); + // without option cannot insert when not in a table context, also cannot add to a table + // using 'accumulo shell -e "insert ...." fron command line due to no table context being set. + exec("insert row1 f q tab1", false, "java.lang.IllegalStateException: Not in a table context"); + // but using option can insert to a table with tablename option without being in a table context + exec("insert row1 f q tab1 --table tab1", true); + exec("insert row4 f q tab2 -t tab2", true); + exec("table tab2", true); + // can also insert into another table even if a different table context + exec("insert row2 f q tab1 -t tab1", true); + exec("notable", true); + // must supply a tablename if option is used + exec("insert row5 f q tab5 --table", false, + "org.apache.commons.cli.MissingArgumentException: Missing argument for option:"); + exec("insert row5 f q tab5 --t", false, + "org.apache.commons.cli.AmbiguousOptionException: Ambiguous option: '--t'"); + // verify expected data is in both tables + exec("scan -t tab1", true, "row1 f:q [] tab1\nrow2 f:q [] tab1"); + exec("scan -t tab2", true, + "row1 f:q [] tab2\nrow2 f:q [] tab2\nrow3 f:q [] tab2\nrow4 f:q [] tab2"); + // check that if in table context, inserting into a non-existent table does not change context + exec("createtable tab3", true); + exec("table tab3", true); + exec("insert row1 f1 q1 tab3", true); + exec("insert row2 f2 q2 tab3 --table idontexist", false, + "org.apache.accumulo.core.client.TableNotFoundException:"); + exec("insert row2 f2 q2 tab3 -t idontexist", false, + "org.apache.accumulo.core.client.TableNotFoundException:"); + exec("insert row3 f3 q3 tab3", true); // should be able to insert w/o changing tables + // verify expected data is in tab3 + exec("scan", true, "row1 f1:q1 [] tab3\nrow3 f3:q3 [] tab3"); + // cleanup + exec("deletetable tab1 -f", true, "Table: [tab1] has been deleted"); + exec("deletetable tab2 -f", true, "Table: [tab2] has been deleted"); + exec("deletetable tab3 -f", true, "Table: [tab3] has been deleted"); + } + + @Test public void deleteManyTest() throws IOException { exec("deletemany", false, "java.lang.IllegalStateException: Not in a table context"); exec("createtable test", true);