use of org.locationtech.geowave.core.cli.utils.ConsoleTablePrinter in project geowave by locationtech.
the class ListStatTypesCommand method computeResults.
@Override
public Void computeResults(final OperationParams params) {
if (parameters.isEmpty()) {
listAllRegisteredStatistics(params.getConsole());
return null;
}
final String storeName = parameters.get(0);
// Attempt to load store.
final DataStorePluginOptions storeOptions = CLIUtils.loadStore(storeName, getGeoWaveConfigFile(params), params.getConsole());
final DataStore dataStore = storeOptions.createDataStore();
if ((indexName != null) && (typeName != null)) {
throw new ParameterException("Specify either index name or type name, not both.");
}
final Index index = indexName != null ? dataStore.getIndex(indexName) : null;
if ((indexName != null) && (index == null)) {
throw new ParameterException("Unable to find index: " + indexName);
}
final DataTypeAdapter<?> adapter = typeName != null ? dataStore.getType(typeName) : null;
if ((typeName != null) && (adapter == null)) {
throw new ParameterException("Unrecognized type name: " + typeName);
}
final Map<String, List<? extends Statistic<? extends StatisticValue<?>>>> indexStats = Maps.newHashMap();
final Map<String, List<? extends Statistic<? extends StatisticValue<?>>>> adapterStats = Maps.newHashMap();
final Map<String, Map<String, List<? extends Statistic<? extends StatisticValue<?>>>>> fieldStats = Maps.newHashMap();
boolean hasAdapters = false;
if (adapter == null) {
if (index != null) {
indexStats.put(index.getName(), StatisticsRegistry.instance().getRegisteredIndexStatistics(index.getClass()));
} else {
final DataTypeAdapter<?>[] adapters = dataStore.getTypes();
for (final DataTypeAdapter<?> dataAdapter : adapters) {
hasAdapters = true;
adapterStats.put(dataAdapter.getTypeName(), StatisticsRegistry.instance().getRegisteredDataTypeStatistics(dataAdapter.getDataClass()));
fieldStats.put(dataAdapter.getTypeName(), StatisticsRegistry.instance().getRegisteredFieldStatistics(dataAdapter, fieldName));
}
final Index[] indices = dataStore.getIndices();
for (final Index idx : indices) {
indexStats.put(idx.getName(), StatisticsRegistry.instance().getRegisteredIndexStatistics(idx.getClass()));
}
}
} else {
hasAdapters = true;
adapterStats.put(adapter.getTypeName(), StatisticsRegistry.instance().getRegisteredDataTypeStatistics(adapter.getDataClass()));
fieldStats.put(adapter.getTypeName(), StatisticsRegistry.instance().getRegisteredFieldStatistics(adapter, fieldName));
}
final ConsoleTablePrinter printer = new ConsoleTablePrinter(0, Integer.MAX_VALUE, params.getConsole());
if (hasAdapters) {
displayIndexStats(printer, indexStats);
displayAdapterStats(printer, adapterStats);
displayFieldStats(printer, fieldStats);
displayBinningStrategies(printer);
} else {
params.getConsole().println("There are no types in the data store.");
}
return null;
}
use of org.locationtech.geowave.core.cli.utils.ConsoleTablePrinter in project geowave by locationtech.
the class ListStatTypesCommand method listAllRegisteredStatistics.
private void listAllRegisteredStatistics(final Console console) {
final List<Statistic<?>> indexStats = Lists.newLinkedList();
final List<Statistic<?>> adapterStats = Lists.newLinkedList();
final List<Statistic<?>> fieldStats = Lists.newLinkedList();
final List<? extends Statistic<? extends StatisticValue<?>>> allStats = StatisticsRegistry.instance().getAllRegisteredStatistics();
Collections.sort(allStats, (s1, s2) -> s1.getStatisticType().getString().compareTo(s2.getStatisticType().getString()));
for (final Statistic<?> statistic : allStats) {
if (statistic instanceof IndexStatistic) {
indexStats.add(statistic);
} else if (statistic instanceof DataTypeStatistic) {
adapterStats.add(statistic);
} else if (statistic instanceof FieldStatistic) {
fieldStats.add(statistic);
}
}
final ConsoleTablePrinter printer = new ConsoleTablePrinter(0, Integer.MAX_VALUE, console);
displayStatList(printer, indexStats, "Registered Index Statistics");
displayStatList(printer, adapterStats, "Registered Adapter Statistics");
displayStatList(printer, fieldStats, "Registered Field Statistics");
displayBinningStrategies(printer);
}
use of org.locationtech.geowave.core.cli.utils.ConsoleTablePrinter in project geowave by locationtech.
the class ListStatsCommand method performStatsCommand.
@Override
protected boolean performStatsCommand(final DataStorePluginOptions storeOptions, final StatsCommandLineOptions statsOptions, final Console console) throws IOException {
final DataStatisticsStore statsStore = storeOptions.createDataStatisticsStore();
final IndexStore indexStore = storeOptions.createIndexStore();
final String[] authorizations = getAuthorizations(statsOptions.getAuthorizations());
DataTypeAdapter<?> adapter = null;
if (statsOptions.getTypeName() != null) {
adapter = storeOptions.createDataStore().getType(statsOptions.getTypeName());
if (adapter == null) {
throw new ParameterException("A type called " + statsOptions.getTypeName() + " was not found.");
}
}
StatisticType<StatisticValue<Object>> statisticType = null;
if (statsOptions.getStatType() != null) {
statisticType = StatisticsRegistry.instance().getStatisticType(statsOptions.getStatType());
if (statisticType == null) {
throw new ParameterException("Unrecognized statistic type: " + statsOptions.getStatType());
}
}
List<String> headers = null;
List<Statistic<?>> statsToList = Lists.newLinkedList();
ValueTransformer transformer = null;
Predicate<StatisticValue<?>> filter;
if (statsOptions.getIndexName() != null) {
if (statisticType != null && !(statisticType instanceof IndexStatisticType)) {
throw new ParameterException("Only index statistic types can be specified when listing statistics for a specific index.");
}
Index index = indexStore.getIndex(statsOptions.getIndexName());
if (index == null) {
throw new ParameterException("An index called " + statsOptions.getIndexName() + " was not found.");
}
headers = Lists.newArrayList("Statistic", "Tag", "Bin", "Value");
transformer = new ValueToRow();
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> stats = statsStore.getIndexStatistics(index, statisticType, statsOptions.getTag())) {
if (adapter != null) {
stats.forEachRemaining(stat -> {
if (stat.getBinningStrategy() instanceof DataTypeBinningStrategy || (stat.getBinningStrategy() instanceof CompositeBinningStrategy && ((CompositeBinningStrategy) stat.getBinningStrategy()).usesStrategy(DataTypeBinningStrategy.class))) {
statsToList.add(stat);
}
});
filter = new IndexAdapterFilter(adapter.getTypeName());
} else {
stats.forEachRemaining(statsToList::add);
filter = null;
}
}
} else if (statsOptions.getTypeName() != null) {
filter = null;
if (statsOptions.getFieldName() != null) {
if (statisticType != null && !(statisticType instanceof FieldStatisticType)) {
throw new ParameterException("Only field statistic types can be specified when listing statistics for a specific field.");
}
headers = Lists.newArrayList("Statistic", "Tag", "Bin", "Value");
transformer = new ValueToRow();
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> stats = statsStore.getFieldStatistics(adapter, statisticType, statsOptions.getFieldName(), statsOptions.getTag())) {
stats.forEachRemaining(statsToList::add);
}
} else {
if (statisticType != null && statisticType instanceof IndexStatisticType) {
throw new ParameterException("Only data type and field statistic types can be specified when listing statistics for a specific data type.");
}
headers = Lists.newArrayList("Statistic", "Tag", "Field", "Bin", "Value");
transformer = new ValueToFieldRow();
if (statisticType == null || statisticType instanceof DataTypeStatisticType) {
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> stats = statsStore.getDataTypeStatistics(adapter, statisticType, statsOptions.getTag())) {
stats.forEachRemaining(statsToList::add);
}
}
if (statisticType == null || statisticType instanceof FieldStatisticType) {
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> stats = statsStore.getFieldStatistics(adapter, statisticType, null, statsOptions.getTag())) {
stats.forEachRemaining(statsToList::add);
}
}
}
} else if (statsOptions.getFieldName() != null) {
throw new ParameterException("A type name must be supplied with a field name.");
} else {
filter = null;
headers = Lists.newArrayList("Index/Adapter", "Statistic", "Tag", "Field", "Bin", "Value");
transformer = new ValueToAllRow();
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> stats = statsStore.getAllStatistics(statisticType)) {
stats.forEachRemaining(stat -> {
if (statsOptions.getTag() == null || stat.getTag().equals(statsOptions.getTag())) {
statsToList.add(stat);
}
});
}
}
Collections.sort(statsToList, new StatComparator());
try (StatisticsValueIterator values = new StatisticsValueIterator(statsStore, statsToList.iterator(), null, authorizations)) {
Iterator<List<Object>> rows = Iterators.transform(filter == null ? values : Iterators.filter(values, v -> filter.test(v)), transformer::transform);
if (limit != null) {
rows = Iterators.limit(rows, limit);
}
if (rows.hasNext()) {
if (csv) {
StringBuilder sb = new StringBuilder();
sb.append(Arrays.toString(headers.toArray()));
rows.forEachRemaining(row -> sb.append(Arrays.toString(row.toArray())));
retValue = sb.toString();
console.println(retValue);
} else {
console.println("Matching statistics:");
ConsoleTablePrinter printer = new ConsoleTablePrinter(0, limit != null ? limit : 30, console);
printer.print(headers, rows);
}
} else {
console.println("No matching statistics were found.");
}
}
return true;
}
use of org.locationtech.geowave.core.cli.utils.ConsoleTablePrinter in project geowave by locationtech.
the class DescribeStoreCommand method execute.
@Override
public void execute(OperationParams params) throws Exception {
Map<String, String> configMap = computeResults(params);
List<List<Object>> rows = new ArrayList<List<Object>>(configMap.size());
Iterator<Map.Entry<String, String>> entryIter = configMap.entrySet().iterator();
while (entryIter.hasNext()) {
Map.Entry<String, String> entry = entryIter.next();
List<Object> values = new ArrayList<Object>(2);
values.add(entry.getKey());
values.add(entry.getValue());
rows.add(values);
}
Collections.sort(rows, new FirstElementListComparator());
new ConsoleTablePrinter(params.getConsole()).print(Arrays.asList("Config Parameter", "Value"), rows);
}
use of org.locationtech.geowave.core.cli.utils.ConsoleTablePrinter in project geowave by locationtech.
the class ConsoleQueryOutputFormat method output.
@Override
public void output(final ResultSet results) {
// The column headers for display
List<String> headers = new ArrayList<String>(results.columnCount());
for (int i = 0; i < results.columnCount(); i++) {
headers.add(results.columnName(i));
}
ConsoleTablePrinter printer = new ConsoleTablePrinter(MIN_COLUMN_SIZE, RESULTS_PER_PAGE, console);
printer.print(headers, getRows(results, headers.size()));
// If more results exist, we will paginate
while (results.hasNext()) {
System.out.println("Press <Enter> for more results...");
try {
System.in.read();
} catch (final IOException ignore) {
break;
}
printer.print(headers, getRows(results, headers.size()));
}
}
Aggregations