Search in sources :

Example 1 with SummaryRetriever

use of org.apache.accumulo.core.client.admin.SummaryRetriever in project accumulo by apache.

the class TableOperationsImpl method summaries.

@Override
public SummaryRetriever summaries(String tableName) {
    return new SummaryRetriever() {

        private Text startRow = null;

        private Text endRow = null;

        private List<TSummarizerConfiguration> summariesToFetch = Collections.emptyList();

        private String summarizerClassRegex;

        private boolean flush = false;

        @Override
        public SummaryRetriever startRow(Text startRow) {
            Objects.requireNonNull(startRow);
            if (endRow != null) {
                Preconditions.checkArgument(startRow.compareTo(endRow) < 0, "Start row must be less than end row : %s >= %s", startRow, endRow);
            }
            this.startRow = startRow;
            return this;
        }

        @Override
        public SummaryRetriever startRow(CharSequence startRow) {
            return startRow(new Text(startRow.toString()));
        }

        @Override
        public List<Summary> retrieve() throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
            Table.ID tableId = Tables.getTableId(context.getInstance(), tableName);
            if (Tables.getTableState(context.getInstance(), tableId) == TableState.OFFLINE)
                throw new TableOfflineException(context.getInstance(), tableId.canonicalID());
            TRowRange range = new TRowRange(TextUtil.getByteBuffer(startRow), TextUtil.getByteBuffer(endRow));
            TSummaryRequest request = new TSummaryRequest(tableId.canonicalID(), range, summariesToFetch, summarizerClassRegex);
            if (flush) {
                _flush(tableId, startRow, endRow, true);
            }
            TSummaries ret = ServerClient.execute(context, new TabletClientService.Client.Factory(), client -> {
                TSummaries tsr = client.startGetSummaries(Tracer.traceInfo(), context.rpcCreds(), request);
                while (!tsr.finished) {
                    tsr = client.contiuneGetSummaries(Tracer.traceInfo(), tsr.sessionId);
                }
                return tsr;
            });
            return new SummaryCollection(ret).getSummaries();
        }

        @Override
        public SummaryRetriever endRow(Text endRow) {
            Objects.requireNonNull(endRow);
            if (startRow != null) {
                Preconditions.checkArgument(startRow.compareTo(endRow) < 0, "Start row must be less than end row : %s >= %s", startRow, endRow);
            }
            this.endRow = endRow;
            return this;
        }

        @Override
        public SummaryRetriever endRow(CharSequence endRow) {
            return endRow(new Text(endRow.toString()));
        }

        @Override
        public SummaryRetriever withConfiguration(Collection<SummarizerConfiguration> configs) {
            Objects.requireNonNull(configs);
            summariesToFetch = configs.stream().map(SummarizerConfigurationUtil::toThrift).collect(Collectors.toList());
            return this;
        }

        @Override
        public SummaryRetriever withConfiguration(SummarizerConfiguration... config) {
            Objects.requireNonNull(config);
            return withConfiguration(Arrays.asList(config));
        }

        @Override
        public SummaryRetriever withMatchingConfiguration(String regex) {
            Objects.requireNonNull(regex);
            // Do a sanity check here to make sure that regex compiles, instead of having it fail on a tserver.
            Pattern.compile(regex);
            this.summarizerClassRegex = regex;
            return this;
        }

        @Override
        public SummaryRetriever flush(boolean b) {
            this.flush = b;
            return this;
        }
    };
}
Also used : RootTable(org.apache.accumulo.core.metadata.RootTable) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) Text(org.apache.hadoop.io.Text) SummarizerConfigurationUtil(org.apache.accumulo.core.summary.SummarizerConfigurationUtil) SummaryRetriever(org.apache.accumulo.core.client.admin.SummaryRetriever) TSummaryRequest(org.apache.accumulo.core.data.thrift.TSummaryRequest) TSummaries(org.apache.accumulo.core.data.thrift.TSummaries) Summary(org.apache.accumulo.core.client.summary.Summary) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client) TRowRange(org.apache.accumulo.core.data.thrift.TRowRange) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) TSummarizerConfiguration(org.apache.accumulo.core.data.thrift.TSummarizerConfiguration)

Example 2 with SummaryRetriever

use of org.apache.accumulo.core.client.admin.SummaryRetriever in project accumulo by apache.

the class SummariesCommand method doTableOp.

@Override
protected void doTableOp(final Shell shellState, final String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException {
    Connector conn = shellState.getConnector();
    SummaryRetriever retriever = conn.tableOperations().summaries(tableName).withMatchingConfiguration(selectionRegex);
    if (startRow != null) {
        retriever.startRow(startRow);
    }
    if (endRow != null) {
        retriever.endRow(endRow);
    }
    Collection<Summary> summaries = retriever.retrieve();
    ArrayList<String> lines = new ArrayList<>();
    boolean addEmpty = false;
    for (Summary summary : summaries) {
        if (addEmpty)
            lines.add("");
        addEmpty = true;
        lines.add(String.format(" Summarizer         : %s", summary.getSummarizerConfiguration()));
        lines.add(String.format(" File Statistics    : %s", summary.getFileStatistics()));
        lines.add(String.format(" Summary Statistics : "));
        Map<String, Long> stats = summary.getStatistics();
        ArrayList<String> keys = new ArrayList<>(stats.keySet());
        Collections.sort(keys);
        for (String key : keys) {
            lines.add(String.format("    %-60s = %,d", key, stats.get(key)));
        }
    }
    shellState.printLines(lines.iterator(), paginate);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ArrayList(java.util.ArrayList) Summary(org.apache.accumulo.core.client.summary.Summary) SummaryRetriever(org.apache.accumulo.core.client.admin.SummaryRetriever)

Aggregations

ArrayList (java.util.ArrayList)2 SummaryRetriever (org.apache.accumulo.core.client.admin.SummaryRetriever)2 Summary (org.apache.accumulo.core.client.summary.Summary)2 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Connector (org.apache.accumulo.core.client.Connector)1 TableOfflineException (org.apache.accumulo.core.client.TableOfflineException)1 Client (org.apache.accumulo.core.client.impl.thrift.ClientService.Client)1 SummarizerConfiguration (org.apache.accumulo.core.client.summary.SummarizerConfiguration)1 TRowRange (org.apache.accumulo.core.data.thrift.TRowRange)1 TSummaries (org.apache.accumulo.core.data.thrift.TSummaries)1 TSummarizerConfiguration (org.apache.accumulo.core.data.thrift.TSummarizerConfiguration)1 TSummaryRequest (org.apache.accumulo.core.data.thrift.TSummaryRequest)1 MetadataTable (org.apache.accumulo.core.metadata.MetadataTable)1 RootTable (org.apache.accumulo.core.metadata.RootTable)1 SummarizerConfigurationUtil (org.apache.accumulo.core.summary.SummarizerConfigurationUtil)1 SummaryCollection (org.apache.accumulo.core.summary.SummaryCollection)1 Text (org.apache.hadoop.io.Text)1