use of org.apache.accumulo.examples.cli.BatchWriterOpts 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();
}
use of org.apache.accumulo.examples.cli.BatchWriterOpts in project accumulo-examples by apache.
the class SampleExample method main.
public static void main(String[] args) throws Exception {
Opts opts = new Opts();
BatchWriterOpts bwOpts = new BatchWriterOpts();
opts.parseArgs(RandomBatchWriter.class.getName(), args, bwOpts);
Connector conn = opts.getConnector();
if (!conn.tableOperations().exists(opts.getTableName())) {
conn.tableOperations().create(opts.getTableName());
} else {
System.out.println("Table exists, not doing anything.");
return;
}
// write some data
BatchWriter bw = conn.createBatchWriter(opts.getTableName(), bwOpts.getBatchWriterConfig());
bw.addMutation(createMutation("9225", "abcde", "file://foo.txt"));
bw.addMutation(createMutation("8934", "accumulo scales", "file://accumulo_notes.txt"));
bw.addMutation(createMutation("2317", "milk, eggs, bread, parmigiano-reggiano", "file://groceries/9/txt"));
bw.addMutation(createMutation("3900", "EC2 ate my homework", "file://final_project.txt"));
bw.flush();
SamplerConfiguration sc1 = new SamplerConfiguration(RowSampler.class.getName());
sc1.setOptions(ImmutableMap.of("hasher", "murmur3_32", "modulus", "3"));
conn.tableOperations().setSamplerConfiguration(opts.getTableName(), sc1);
Scanner scanner = conn.createScanner(opts.getTableName(), Authorizations.EMPTY);
System.out.println("Scanning all data :");
print(scanner);
System.out.println();
System.out.println("Scanning with sampler configuration. Data was written before sampler was set on table, scan should fail.");
scanner.setSamplerConfiguration(sc1);
try {
print(scanner);
} catch (SampleNotPresentException e) {
System.out.println(" Saw sample not present exception as expected.");
}
System.out.println();
// compact table to recreate sample data
conn.tableOperations().compact(opts.getTableName(), new CompactionConfig().setCompactionStrategy(NO_SAMPLE_STRATEGY));
System.out.println("Scanning after compaction (compaction should have created sample data) : ");
print(scanner);
System.out.println();
// update a document in the sample data
bw.addMutation(createMutation("2317", "milk, eggs, bread, parmigiano-reggiano, butter", "file://groceries/9/txt"));
bw.close();
System.out.println("Scanning sample after updating content for docId 2317 (should see content change in sample data) : ");
print(scanner);
System.out.println();
// change tables sampling configuration...
SamplerConfiguration sc2 = new SamplerConfiguration(RowSampler.class.getName());
sc2.setOptions(ImmutableMap.of("hasher", "murmur3_32", "modulus", "2"));
conn.tableOperations().setSamplerConfiguration(opts.getTableName(), sc2);
// compact table to recreate sample data using new configuration
conn.tableOperations().compact(opts.getTableName(), new CompactionConfig().setCompactionStrategy(NO_SAMPLE_STRATEGY));
System.out.println("Scanning with old sampler configuration. Sample data was created using new configuration with a compaction. Scan should fail.");
try {
// try scanning with old sampler configuration
print(scanner);
} catch (SampleNotPresentException e) {
System.out.println(" Saw sample not present exception as expected ");
}
System.out.println();
// update expected sampler configuration on scanner
scanner.setSamplerConfiguration(sc2);
System.out.println("Scanning with new sampler configuration : ");
print(scanner);
System.out.println();
}
use of org.apache.accumulo.examples.cli.BatchWriterOpts in project accumulo-examples by apache.
the class Index method main.
public static void main(String[] args) throws Exception {
Opts opts = new Opts();
BatchWriterOpts bwOpts = new BatchWriterOpts();
opts.parseArgs(Index.class.getName(), args, bwOpts);
String splitRegex = "\\W+";
BatchWriter bw = opts.getConnector().createBatchWriter(opts.getTableName(), bwOpts.getBatchWriterConfig());
for (String filename : opts.files) {
index(opts.partitions, new File(filename), splitRegex, bw);
}
bw.close();
}
use of org.apache.accumulo.examples.cli.BatchWriterOpts in project accumulo-examples by apache.
the class InterferenceTest method main.
public static void main(String[] args) throws Exception {
Opts opts = new Opts();
BatchWriterOpts bwOpts = new BatchWriterOpts();
opts.parseArgs(InterferenceTest.class.getName(), args, bwOpts);
if (opts.iterations < 1)
opts.iterations = Long.MAX_VALUE;
Connector conn = opts.getConnector();
if (!conn.tableOperations().exists(opts.getTableName()))
conn.tableOperations().create(opts.getTableName());
Thread writer = new Thread(new Writer(conn.createBatchWriter(opts.getTableName(), bwOpts.getBatchWriterConfig()), opts.iterations));
writer.start();
Reader r;
if (opts.isolated)
r = new Reader(new IsolatedScanner(conn.createScanner(opts.getTableName(), opts.auths)));
else
r = new Reader(conn.createScanner(opts.getTableName(), opts.auths));
Thread reader;
reader = new Thread(r);
reader.start();
writer.join();
r.stopNow();
reader.join();
System.out.println("finished");
}
use of org.apache.accumulo.examples.cli.BatchWriterOpts 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();
}
Aggregations