Search in sources :

Example 11 with FormatterConfig

use of org.apache.accumulo.core.util.format.FormatterConfig in project accumulo by apache.

the class GrepCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
    try (final PrintFile printFile = getOutputFile(cl)) {
        final String tableName = OptUtil.getTableOpt(cl, shellState);
        if (cl.getArgList().isEmpty()) {
            throw new MissingArgumentException("No terms specified");
        }
        final Class<? extends Formatter> formatter = getFormatter(cl, tableName, shellState);
        final ScanInterpreter interpeter = getInterpreter(cl, tableName, shellState);
        // handle first argument, if present, the authorizations list to
        // scan with
        int numThreads = 20;
        if (cl.hasOption(numThreadsOpt.getOpt())) {
            numThreads = Integer.parseInt(cl.getOptionValue(numThreadsOpt.getOpt()));
        }
        final Authorizations auths = getAuths(cl, shellState);
        final BatchScanner scanner = shellState.getConnector().createBatchScanner(tableName, auths, numThreads);
        scanner.setRanges(Collections.singletonList(getRange(cl, interpeter)));
        scanner.setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS);
        setupSampling(tableName, cl, shellState, scanner);
        for (int i = 0; i < cl.getArgs().length; i++) {
            setUpIterator(Integer.MAX_VALUE - cl.getArgs().length + i, "grep" + i, cl.getArgs()[i], scanner, cl);
        }
        try {
            // handle columns
            fetchColumns(cl, scanner, interpeter);
            // output the records
            final FormatterConfig config = new FormatterConfig();
            config.setPrintTimestamps(cl.hasOption(timestampOpt.getOpt()));
            printRecords(cl, shellState, config, scanner, formatter, printFile);
        } finally {
            scanner.close();
        }
    }
    return 0;
}
Also used : ScanInterpreter(org.apache.accumulo.core.util.interpret.ScanInterpreter) Authorizations(org.apache.accumulo.core.security.Authorizations) FormatterConfig(org.apache.accumulo.core.util.format.FormatterConfig) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) BatchScanner(org.apache.accumulo.core.client.BatchScanner) PrintFile(org.apache.accumulo.shell.Shell.PrintFile)

Aggregations

FormatterConfig (org.apache.accumulo.core.util.format.FormatterConfig)11 Test (org.junit.Test)6 Key (org.apache.accumulo.core.data.Key)3 Value (org.apache.accumulo.core.data.Value)3 Authorizations (org.apache.accumulo.core.security.Authorizations)3 ScanInterpreter (org.apache.accumulo.core.util.interpret.ScanInterpreter)3 Scanner (org.apache.accumulo.core.client.Scanner)2 PrintFile (org.apache.accumulo.shell.Shell.PrintFile)2 BatchScanner (org.apache.accumulo.core.client.BatchScanner)1 BatchWriter (org.apache.accumulo.core.client.BatchWriter)1 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 SortedKeyIterator (org.apache.accumulo.core.iterators.SortedKeyIterator)1 DefaultScanInterpreter (org.apache.accumulo.core.util.interpret.DefaultScanInterpreter)1 DeleterFormatter (org.apache.accumulo.shell.format.DeleterFormatter)1 MissingArgumentException (org.apache.commons.cli.MissingArgumentException)1