[ 
https://issues.apache.org/jira/browse/ACCUMULO-1399?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13661445#comment-13661445
 ] 

Dave Marion commented on ACCUMULO-1399:
---------------------------------------

2nd patch includes a script command. See the comment above for the extensions 
command. The script command allows you to run scripts using JSR-223 engines. A 
list of JSR-223 engines can be found in this thread: 
http://stackoverflow.com/questions/11838369/where-can-i-find-a-list-of-available-jsr-223-scripting-languages.
 Documentation for the scripting feature can be found at 
http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/.

Here are some examples:

echo "println(arg1)" > /tmp/hello.rhino

./accumulo shell --fake

list JSR-223 engines on the classpath
{code}
script -l
{code}

execute an inline script
{code}
script -e rhino -s "println('Hello')"
{code}

execute an inline script with 1 arg
{code}
script -e rhino -s "println(arg1)" -a arg1=Hello
{code}

execute an inline script with 2 args
{code}
script -e rhino -s "println(arg1+', '+arg2)" -a arg1=Hello -a arg2=World
{code}

execute a script in a file
{code}
script -e rhino -f /tmp/hello.rhino -a arg1=Hello
{code}

invoke a function in a script
{code}
script -e rhino -s "function hello(arg1) { println('Hello, ' + arg1); }" -fx 
hello -a arg1=Dave
{code}

invoke a method on a function
{code}
script -e js -s "var obj = new Object(); obj.hello = function(arg1) { 
println('Hello, ' + arg1); }" -obj obj:hello -a arg1=Dave
{code}

 I was trying to do something more complicated. The script below compiles and 
runs without error, but no data is in the table afterwards. Any idea what I am 
missing?
 
{code}
function testInsert(tableName, numRows) {
  connection.tableOperations().create(tableName);
  if (!connection.tableOperations().exists(tableName)) {
    println("Table does not exist");
    return;
  }
 
  var bwConfig = new org.apache.accumulo.core.client.BatchWriterConfig();
  bwConfig.setMaxMemory(1024);
  var bw = connection.createBatchWriter(tableName, bwConfig);
  for (var x = 0; x < numRows; x++) {
    var mut = new org.apache.accumulo.core.data.Mutation(new 
org.apache.hadoop.io.Text(x));
    bw.addMutation(mut);
    println("Adding " + x);
  }
  bw.flush();
  bw.close();

  var scanner = connection.createScanner(tableName, new 
org.apache.accumulo.core.security.Authorizations());
  var scanIterator = scanner.iterator();
  while (scanIterator.hasNext()) {
    var entry = scanIterator.next();
    println(entry.getKey().toString()+"  ->  "+entry.getValue());
  }
}
{code}

run the test function
{code}
script -e rhino -f /tmp/insert.js  -a tableName=foo -a numRows=10 -fx testInsert
{code}

                
> Pluggable commands for the shell
> --------------------------------
>
>                 Key: ACCUMULO-1399
>                 URL: https://issues.apache.org/jira/browse/ACCUMULO-1399
>             Project: Accumulo
>          Issue Type: New Feature
>          Components: shell
>            Reporter: Dave Marion
>            Assignee: Dave Marion
>            Priority: Minor
>             Fix For: 1.6.0
>
>         Attachments: ACCUMULO-1399-1.patch, ACCUMULO-1399-2.patch
>
>
> Proposing modification to the Shell to allow applications to create their own 
> set of commands. This might be accomplished using java.util.ServiceLoader or 
> something like it. Specifically, I'm thinking of a case where I have a create 
> table command that is different than the one provided by the Shell. In my 
> case, my create table command may create one or more tables and setup 
> iterators on them.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to