Search in sources :

Example 1 with ScanInterpreter

use of org.apache.accumulo.core.util.interpret.ScanInterpreter in project accumulo by apache.

the class MaxRowCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
    final String tableName = OptUtil.getTableOpt(cl, shellState);
    final ScanInterpreter interpeter = getInterpreter(cl, tableName, shellState);
    final Range range = getRange(cl, interpeter);
    final Authorizations auths = getAuths(cl, shellState);
    final Text startRow = range.getStartKey() == null ? null : range.getStartKey().getRow();
    final Text endRow = range.getEndKey() == null ? null : range.getEndKey().getRow();
    try {
        final Text max = shellState.getConnector().tableOperations().getMaxRow(tableName, auths, startRow, range.isStartKeyInclusive(), endRow, range.isEndKeyInclusive());
        if (max != null) {
            shellState.getReader().println(max.toString());
        }
    } catch (Exception e) {
        log.debug("Could not get shell state.", e);
    }
    return 0;
}
Also used : ScanInterpreter(org.apache.accumulo.core.util.interpret.ScanInterpreter) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range)

Example 2 with ScanInterpreter

use of org.apache.accumulo.core.util.interpret.ScanInterpreter in project accumulo by apache.

the class DeleteManyCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
    final String tableName = OptUtil.getTableOpt(cl, shellState);
    final ScanInterpreter interpeter = getInterpreter(cl, tableName, shellState);
    // handle first argument, if present, the authorizations list to
    // scan with
    final Authorizations auths = getAuths(cl, shellState);
    final Scanner scanner = shellState.getConnector().createScanner(tableName, auths);
    scanner.addScanIterator(new IteratorSetting(Integer.MAX_VALUE, "NOVALUE", SortedKeyIterator.class));
    // handle session-specific scan iterators
    addScanIterators(shellState, cl, scanner, tableName);
    // handle remaining optional arguments
    scanner.setRange(getRange(cl, interpeter));
    scanner.setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS);
    // handle columns
    fetchColumns(cl, scanner, interpeter);
    // output / delete the records
    final BatchWriter writer = shellState.getConnector().createBatchWriter(tableName, new BatchWriterConfig().setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS));
    FormatterConfig config = new FormatterConfig();
    config.setPrintTimestamps(cl.hasOption(timestampOpt.getOpt()));
    shellState.printLines(new DeleterFormatter(writer, scanner, config, shellState, cl.hasOption(forceOpt.getOpt())), false);
    return 0;
}
Also used : ScanInterpreter(org.apache.accumulo.core.util.interpret.ScanInterpreter) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) FormatterConfig(org.apache.accumulo.core.util.format.FormatterConfig) SortedKeyIterator(org.apache.accumulo.core.iterators.SortedKeyIterator) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) DeleterFormatter(org.apache.accumulo.shell.format.DeleterFormatter)

Example 3 with ScanInterpreter

use of org.apache.accumulo.core.util.interpret.ScanInterpreter in project accumulo by apache.

the class ScanCommand 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);
        final Class<? extends Formatter> formatter = getFormatter(cl, tableName, shellState);
        final ScanInterpreter interpeter = getInterpreter(cl, tableName, shellState);
        String classLoaderContext = null;
        if (cl.hasOption(contextOpt.getOpt())) {
            classLoaderContext = cl.getOptionValue(contextOpt.getOpt());
        }
        // handle first argument, if present, the authorizations list to
        // scan with
        final Authorizations auths = getAuths(cl, shellState);
        final Scanner scanner = shellState.getConnector().createScanner(tableName, auths);
        if (null != classLoaderContext) {
            scanner.setClassLoaderContext(classLoaderContext);
        }
        // handle session-specific scan iterators
        addScanIterators(shellState, cl, scanner, tableName);
        // handle remaining optional arguments
        scanner.setRange(getRange(cl, interpeter));
        // handle columns
        fetchColumns(cl, scanner, interpeter);
        // set timeout
        scanner.setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS);
        setupSampling(tableName, cl, shellState, scanner);
        // output the records
        final FormatterConfig config = new FormatterConfig();
        config.setPrintTimestamps(cl.hasOption(timestampOpt.getOpt()));
        if (cl.hasOption(showFewOpt.getOpt())) {
            final String showLength = cl.getOptionValue(showFewOpt.getOpt());
            try {
                final int length = Integer.parseInt(showLength);
                config.setShownLength(length);
            } catch (NumberFormatException nfe) {
                shellState.getReader().println("Arg must be an integer.");
            } catch (IllegalArgumentException iae) {
                shellState.getReader().println("Arg must be greater than one.");
            }
        }
        printRecords(cl, shellState, config, scanner, formatter, printFile);
    }
    return 0;
}
Also used : DefaultScanInterpreter(org.apache.accumulo.core.util.interpret.DefaultScanInterpreter) ScanInterpreter(org.apache.accumulo.core.util.interpret.ScanInterpreter) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) FormatterConfig(org.apache.accumulo.core.util.format.FormatterConfig) PrintFile(org.apache.accumulo.shell.Shell.PrintFile)

Example 4 with ScanInterpreter

use of org.apache.accumulo.core.util.interpret.ScanInterpreter 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

Authorizations (org.apache.accumulo.core.security.Authorizations)4 ScanInterpreter (org.apache.accumulo.core.util.interpret.ScanInterpreter)4 FormatterConfig (org.apache.accumulo.core.util.format.FormatterConfig)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 Range (org.apache.accumulo.core.data.Range)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 Text (org.apache.hadoop.io.Text)1