Search in sources :

Example 1 with PrintLine

use of org.apache.accumulo.shell.Shell.PrintLine in project accumulo by apache.

the class GetSplitsCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException, AccumuloException, AccumuloSecurityException, TableNotFoundException {
    final String tableName = OptUtil.getTableOpt(cl, shellState);
    final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
    final String m = cl.getOptionValue(maxSplitsOpt.getOpt());
    final int maxSplits = m == null ? 0 : Integer.parseInt(m);
    final boolean encode = cl.hasOption(base64Opt.getOpt());
    final boolean verbose = cl.hasOption(verboseOpt.getOpt());
    try (PrintLine p = outputFile == null ? new PrintShell(shellState.getReader()) : new PrintFile(outputFile)) {
        if (!verbose) {
            for (Text row : maxSplits > 0 ? shellState.getConnector().tableOperations().listSplits(tableName, maxSplits) : shellState.getConnector().tableOperations().listSplits(tableName)) {
                p.print(encode(encode, row));
            }
        } else {
            String systemTableToCheck = MetadataTable.NAME.equals(tableName) ? RootTable.NAME : MetadataTable.NAME;
            final Scanner scanner = shellState.getConnector().createScanner(systemTableToCheck, Authorizations.EMPTY);
            TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
            final Text start = new Text(shellState.getConnector().tableOperations().tableIdMap().get(tableName));
            final Text end = new Text(start);
            end.append(new byte[] { '<' }, 0, 1);
            scanner.setRange(new Range(start, end));
            for (Iterator<Entry<Key, Value>> iterator = scanner.iterator(); iterator.hasNext(); ) {
                final Entry<Key, Value> next = iterator.next();
                if (TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.hasColumns(next.getKey())) {
                    KeyExtent extent = new KeyExtent(next.getKey().getRow(), next.getValue());
                    final String pr = encode(encode, extent.getPrevEndRow());
                    final String er = encode(encode, extent.getEndRow());
                    final String line = String.format("%-26s (%s, %s%s", obscuredTabletName(extent), pr == null ? "-inf" : pr, er == null ? "+inf" : er, er == null ? ") Default Tablet " : "]");
                    p.print(line);
                }
            }
        }
    }
    return 0;
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) PrintShell(org.apache.accumulo.shell.Shell.PrintShell) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) Entry(java.util.Map.Entry) PrintLine(org.apache.accumulo.shell.Shell.PrintLine) Value(org.apache.accumulo.core.data.Value) PrintFile(org.apache.accumulo.shell.Shell.PrintFile) Key(org.apache.accumulo.core.data.Key)

Aggregations

Entry (java.util.Map.Entry)1 Scanner (org.apache.accumulo.core.client.Scanner)1 Key (org.apache.accumulo.core.data.Key)1 Range (org.apache.accumulo.core.data.Range)1 Value (org.apache.accumulo.core.data.Value)1 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)1 PrintFile (org.apache.accumulo.shell.Shell.PrintFile)1 PrintLine (org.apache.accumulo.shell.Shell.PrintLine)1 PrintShell (org.apache.accumulo.shell.Shell.PrintShell)1 Text (org.apache.hadoop.io.Text)1