Search in sources :

Example 1 with FileDataIngest

use of org.apache.accumulo.examples.filedata.FileDataIngest in project accumulo-examples by apache.

the class Ingest method main.

public static void main(String[] args) throws Exception {
    Opts opts = new Opts();
    BatchWriterOpts bwOpts = new BatchWriterOpts();
    opts.parseArgs(Ingest.class.getName(), args, bwOpts);
    Connector conn = opts.getConnector();
    if (!conn.tableOperations().exists(opts.nameTable))
        conn.tableOperations().create(opts.nameTable);
    if (!conn.tableOperations().exists(opts.indexTable))
        conn.tableOperations().create(opts.indexTable);
    if (!conn.tableOperations().exists(opts.dataTable)) {
        conn.tableOperations().create(opts.dataTable);
        conn.tableOperations().attachIterator(opts.dataTable, new IteratorSetting(1, ChunkCombiner.class));
    }
    BatchWriter dirBW = conn.createBatchWriter(opts.nameTable, bwOpts.getBatchWriterConfig());
    BatchWriter indexBW = conn.createBatchWriter(opts.indexTable, bwOpts.getBatchWriterConfig());
    BatchWriter dataBW = conn.createBatchWriter(opts.dataTable, bwOpts.getBatchWriterConfig());
    FileDataIngest fdi = new FileDataIngest(opts.chunkSize, opts.visibility);
    for (String dir : opts.directories) {
        recurse(new File(dir), opts.visibility, dirBW, indexBW, fdi, dataBW);
        // fill in parent directory info
        int slashIndex = -1;
        while ((slashIndex = dir.lastIndexOf("/")) > 0) {
            dir = dir.substring(0, slashIndex);
            ingest(new File(dir), opts.visibility, dirBW, indexBW, fdi, dataBW);
        }
    }
    ingest(new File("/"), opts.visibility, dirBW, indexBW, fdi, dataBW);
    dirBW.close();
    indexBW.close();
    dataBW.close();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) FileDataIngest(org.apache.accumulo.examples.filedata.FileDataIngest) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) ClientOpts(org.apache.accumulo.examples.cli.ClientOpts) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) BatchWriterOpts(org.apache.accumulo.examples.cli.BatchWriterOpts) BatchWriter(org.apache.accumulo.core.client.BatchWriter) ChunkCombiner(org.apache.accumulo.examples.filedata.ChunkCombiner) File(java.io.File) FileDataIngest(org.apache.accumulo.examples.filedata.FileDataIngest)

Aggregations

File (java.io.File)1 BatchWriter (org.apache.accumulo.core.client.BatchWriter)1 Connector (org.apache.accumulo.core.client.Connector)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 BatchWriterOpts (org.apache.accumulo.examples.cli.BatchWriterOpts)1 ClientOpts (org.apache.accumulo.examples.cli.ClientOpts)1 ChunkCombiner (org.apache.accumulo.examples.filedata.ChunkCombiner)1 FileDataIngest (org.apache.accumulo.examples.filedata.FileDataIngest)1