Search in sources :

Example 1 with ScannerOpts

use of org.apache.accumulo.examples.cli.ScannerOpts in project accumulo-examples by apache.

the class Reverse method main.

public static void main(String[] args) throws Exception {
    Opts opts = new Opts();
    ScannerOpts scanOpts = new ScannerOpts();
    BatchWriterOpts bwOpts = new BatchWriterOpts();
    opts.parseArgs(Reverse.class.getName(), args, scanOpts, bwOpts);
    Connector conn = opts.getConnector();
    Scanner scanner = conn.createScanner(opts.shardTable, opts.auths);
    scanner.setBatchSize(scanOpts.scanBatchSize);
    BatchWriter bw = conn.createBatchWriter(opts.doc2TermTable, bwOpts.getBatchWriterConfig());
    for (Entry<Key, Value> entry : scanner) {
        Key key = entry.getKey();
        Mutation m = new Mutation(key.getColumnQualifier());
        m.put(key.getColumnFamily(), new Text(), new Value(new byte[0]));
        bw.addMutation(m);
    }
    bw.close();
}
Also used : ScannerOpts(org.apache.accumulo.examples.cli.ScannerOpts) Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) ScannerOpts(org.apache.accumulo.examples.cli.ScannerOpts) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) ClientOpts(org.apache.accumulo.examples.cli.ClientOpts) Value(org.apache.accumulo.core.data.Value) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) Text(org.apache.hadoop.io.Text) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key)

Example 2 with ScannerOpts

use of org.apache.accumulo.examples.cli.ScannerOpts in project accumulo-examples by apache.

the class FileCount method main.

public static void main(String[] args) throws Exception {
    Opts opts = new Opts();
    ScannerOpts scanOpts = new ScannerOpts();
    BatchWriterOpts bwOpts = new BatchWriterOpts();
    String programName = FileCount.class.getName();
    opts.parseArgs(programName, args, scanOpts, bwOpts);
    FileCount fileCount = new FileCount(opts.getConnector(), opts.getTableName(), opts.auths, opts.visibility, scanOpts, bwOpts);
    fileCount.run();
}
Also used : ScannerOpts(org.apache.accumulo.examples.cli.ScannerOpts) ScannerOpts(org.apache.accumulo.examples.cli.ScannerOpts) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts)

Example 3 with ScannerOpts

use of org.apache.accumulo.examples.cli.ScannerOpts in project accumulo-examples by apache.

the class RowOperations method main.

public static void main(String[] args) throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, MutationsRejectedException {
    ClientOpts opts = new ClientOpts();
    ScannerOpts scanOpts = new ScannerOpts();
    BatchWriterOpts bwOpts = new BatchWriterOpts();
    opts.parseArgs(RowOperations.class.getName(), args, scanOpts, bwOpts);
    // First the setup work
    connector = opts.getConnector();
    // lets create an example table
    connector.tableOperations().create(tableName);
    // lets create 3 rows of information
    Text row1 = new Text("row1");
    Text row2 = new Text("row2");
    Text row3 = new Text("row3");
    // Which means 3 different mutations
    Mutation mut1 = new Mutation(row1);
    Mutation mut2 = new Mutation(row2);
    Mutation mut3 = new Mutation(row3);
    // And we'll put 4 columns in each row
    Text col1 = new Text("1");
    Text col2 = new Text("2");
    Text col3 = new Text("3");
    Text col4 = new Text("4");
    // Now we'll add them to the mutations
    mut1.put(new Text("column"), col1, System.currentTimeMillis(), new Value("This is the value for this key".getBytes(UTF_8)));
    mut1.put(new Text("column"), col2, System.currentTimeMillis(), new Value("This is the value for this key".getBytes(UTF_8)));
    mut1.put(new Text("column"), col3, System.currentTimeMillis(), new Value("This is the value for this key".getBytes(UTF_8)));
    mut1.put(new Text("column"), col4, System.currentTimeMillis(), new Value("This is the value for this key".getBytes(UTF_8)));
    mut2.put(new Text("column"), col1, System.currentTimeMillis(), new Value("This is the value for this key".getBytes(UTF_8)));
    mut2.put(new Text("column"), col2, System.currentTimeMillis(), new Value("This is the value for this key".getBytes(UTF_8)));
    mut2.put(new Text("column"), col3, System.currentTimeMillis(), new Value("This is the value for this key".getBytes(UTF_8)));
    mut2.put(new Text("column"), col4, System.currentTimeMillis(), new Value("This is the value for this key".getBytes(UTF_8)));
    mut3.put(new Text("column"), col1, System.currentTimeMillis(), new Value("This is the value for this key".getBytes(UTF_8)));
    mut3.put(new Text("column"), col2, System.currentTimeMillis(), new Value("This is the value for this key".getBytes(UTF_8)));
    mut3.put(new Text("column"), col3, System.currentTimeMillis(), new Value("This is the value for this key".getBytes(UTF_8)));
    mut3.put(new Text("column"), col4, System.currentTimeMillis(), new Value("This is the value for this key".getBytes(UTF_8)));
    // Now we'll make a Batch Writer
    bw = connector.createBatchWriter(tableName, bwOpts.getBatchWriterConfig());
    // And add the mutations
    bw.addMutation(mut1);
    bw.addMutation(mut2);
    bw.addMutation(mut3);
    // Force a send
    bw.flush();
    // Now lets look at the rows
    Scanner rowThree = getRow(scanOpts, new Text("row3"));
    Scanner rowTwo = getRow(scanOpts, new Text("row2"));
    Scanner rowOne = getRow(scanOpts, new Text("row1"));
    // And print them
    log.info("This is everything");
    printRow(rowOne);
    printRow(rowTwo);
    printRow(rowThree);
    System.out.flush();
    // Now lets delete rowTwo with the iterator
    rowTwo = getRow(scanOpts, new Text("row2"));
    deleteRow(rowTwo);
    // Now lets look at the rows again
    rowThree = getRow(scanOpts, new Text("row3"));
    rowTwo = getRow(scanOpts, new Text("row2"));
    rowOne = getRow(scanOpts, new Text("row1"));
    // And print them
    log.info("This is row1 and row3");
    printRow(rowOne);
    printRow(rowTwo);
    printRow(rowThree);
    System.out.flush();
    // Should only see the two rows
    // Now lets delete rowOne without passing in the iterator
    deleteRow(scanOpts, row1);
    // Now lets look at the rows one last time
    rowThree = getRow(scanOpts, new Text("row3"));
    rowTwo = getRow(scanOpts, new Text("row2"));
    rowOne = getRow(scanOpts, new Text("row1"));
    // And print them
    log.info("This is just row3");
    printRow(rowOne);
    printRow(rowTwo);
    printRow(rowThree);
    System.out.flush();
    // Should only see rowThree
    // Always close your batchwriter
    bw.close();
    // and lets clean up our mess
    connector.tableOperations().delete(tableName);
// fin~
}
Also used : ScannerOpts(org.apache.accumulo.examples.cli.ScannerOpts) Scanner(org.apache.accumulo.core.client.Scanner) Value(org.apache.accumulo.core.data.Value) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) Text(org.apache.hadoop.io.Text) Mutation(org.apache.accumulo.core.data.Mutation) ClientOpts(org.apache.accumulo.examples.cli.ClientOpts)

Example 4 with ScannerOpts

use of org.apache.accumulo.examples.cli.ScannerOpts in project accumulo-examples by apache.

the class TraceDumpExample method main.

public static void main(String[] args) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
    TraceDumpExample traceDumpExample = new TraceDumpExample();
    Opts opts = new Opts();
    ScannerOpts scannerOpts = new ScannerOpts();
    opts.parseArgs(TraceDumpExample.class.getName(), args, scannerOpts);
    traceDumpExample.dump(opts);
}
Also used : ScannerOpts(org.apache.accumulo.examples.cli.ScannerOpts) ScannerOpts(org.apache.accumulo.examples.cli.ScannerOpts)

Example 5 with ScannerOpts

use of org.apache.accumulo.examples.cli.ScannerOpts in project accumulo-examples by apache.

the class ReadWriteExample method main.

public static void main(String[] args) throws Exception {
    ReadWriteExample rwe = new ReadWriteExample();
    Opts opts = new Opts();
    ScannerOpts scanOpts = new ScannerOpts();
    opts.parseArgs(ReadWriteExample.class.getName(), args, scanOpts);
    rwe.execute(opts, scanOpts);
}
Also used : ScannerOpts(org.apache.accumulo.examples.cli.ScannerOpts) ScannerOpts(org.apache.accumulo.examples.cli.ScannerOpts)

Aggregations

ScannerOpts (org.apache.accumulo.examples.cli.ScannerOpts)7 BatchWriterOpts (org.apache.accumulo.examples.cli.BatchWriterOpts)4 Scanner (org.apache.accumulo.core.client.Scanner)3 Value (org.apache.accumulo.core.data.Value)3 Text (org.apache.hadoop.io.Text)3 Key (org.apache.accumulo.core.data.Key)2 Mutation (org.apache.accumulo.core.data.Mutation)2 ClientOpts (org.apache.accumulo.examples.cli.ClientOpts)2 ArrayList (java.util.ArrayList)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 BatchWriter (org.apache.accumulo.core.client.BatchWriter)1 Connector (org.apache.accumulo.core.client.Connector)1 TableExistsException (org.apache.accumulo.core.client.TableExistsException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 Authorizations (org.apache.accumulo.core.security.Authorizations)1 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)1 Pair (org.apache.accumulo.core.util.Pair)1 Test (org.junit.Test)1