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;
}
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;
}
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;
}
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;
}
Aggregations