use of org.locationtech.geowave.core.store.api.IndexStatistic in project geowave by locationtech.
the class DataStatisticsStoreImpl method removeStatistics.
@Override
public boolean removeStatistics(final DataTypeAdapter<?> type, final Index... adapterIndices) {
boolean removed = deleteObjects(DataTypeStatistic.generateGroupId(type.getTypeName()));
removed = deleteObjects(null, DataTypeStatistic.generateGroupId(type.getTypeName()), operations, MetadataType.STATISTIC_VALUES, this) || removed;
removed = deleteObjects(FieldStatistic.generateGroupId(type.getTypeName())) || removed;
removed = deleteObjects(null, FieldStatistic.generateGroupId(type.getTypeName()), operations, MetadataType.STATISTIC_VALUES, this) || removed;
for (final Index index : adapterIndices) {
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> statsIter = getIndexStatistics(index, null, null)) {
while (statsIter.hasNext()) {
final IndexStatistic<?> next = (IndexStatistic<?>) statsIter.next();
removeTypeSpecificStatisticValues(next, type.getTypeName());
}
}
}
return removed;
}
use of org.locationtech.geowave.core.store.api.IndexStatistic 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.store.api.IndexStatistic in project geowave by locationtech.
the class StatsCommandLineOptions method resolveMatchingStatistics.
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<Statistic<? extends StatisticValue<?>>> resolveMatchingStatistics(final DataStore dataStore, final DataStatisticsStore statsStore, final IndexStore indexStore) {
final List<Statistic<? extends StatisticValue<?>>> matching = Lists.newArrayList();
if ((indexName != null) && ((typeName != null) || (fieldName != null))) {
throw new ParameterException("Unable to process index statistics for a single type. Specify either an index name or a type name.");
}
StatisticType statisticType = null;
if (statType != null) {
statisticType = StatisticsRegistry.instance().getStatisticType(statType);
if (statisticType == null) {
throw new ParameterException("Unrecognized statistic type: " + statType);
}
}
if (statisticType != null) {
if (statisticType instanceof IndexStatisticType) {
if (indexName == null) {
throw new ParameterException("An index name must be supplied when specifying an index statistic type.");
}
final Index index = indexStore.getIndex(indexName);
if (index == null) {
throw new ParameterException("Unable to find an index named: " + indexName);
}
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> stats = statsStore.getIndexStatistics(index, statisticType, tag)) {
stats.forEachRemaining(stat -> matching.add(stat));
}
} else if (statisticType instanceof DataTypeStatisticType) {
if (typeName == null) {
throw new ParameterException("A type name must be supplied when specifying a data type statistic type.");
}
final DataTypeAdapter<?> adapter = dataStore.getType(typeName);
if (adapter == null) {
throw new ParameterException("Unable to find an type named: " + typeName);
}
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> stats = statsStore.getDataTypeStatistics(adapter, statisticType, tag)) {
stats.forEachRemaining(stat -> matching.add(stat));
}
} else if (statisticType instanceof FieldStatisticType) {
if (typeName == null) {
throw new ParameterException("A type name must be supplied when specifying a field statistic type.");
}
final DataTypeAdapter<?> adapter = dataStore.getType(typeName);
if (adapter == null) {
throw new ParameterException("Unable to find an type named: " + typeName);
}
if (fieldName == null) {
throw new ParameterException("A field name must be supplied when specifying a field statistic type.");
}
boolean fieldFound = false;
final FieldDescriptor[] fields = adapter.getFieldDescriptors();
for (int i = 0; i < fields.length; i++) {
if (fields[i].fieldName().equals(fieldName)) {
fieldFound = true;
break;
}
}
if (!fieldFound) {
throw new ParameterException("Unable to find a field named '" + fieldName + "' on type '" + typeName + "'.");
}
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> stats = statsStore.getFieldStatistics(adapter, statisticType, fieldName, tag)) {
stats.forEachRemaining(stat -> matching.add(stat));
}
}
} else {
try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> stats = statsStore.getAllStatistics(null)) {
stats.forEachRemaining(stat -> {
// This could all be optimized to one giant check, but it's split for readability
if ((tag != null) && !tag.equals(stat.getTag())) {
return;
}
if ((indexName != null) && (!(stat instanceof IndexStatistic) || !indexName.equals(((IndexStatistic) stat).getIndexName()))) {
return;
}
if (typeName != null) {
if (stat instanceof IndexStatistic) {
return;
}
if ((stat instanceof DataTypeStatistic) && !typeName.equals(((DataTypeStatistic) stat).getTypeName())) {
return;
}
if ((stat instanceof FieldStatistic) && !typeName.equals(((FieldStatistic) stat).getTypeName())) {
return;
}
}
if ((fieldName != null) && (!(stat instanceof FieldStatistic) || !fieldName.equals(((FieldStatistic) stat).getFieldName()))) {
return;
}
matching.add(stat);
});
}
}
return matching;
}
use of org.locationtech.geowave.core.store.api.IndexStatistic in project geowave by locationtech.
the class BaseDataStore method getIndexStatistic.
@SuppressWarnings("unchecked")
@Override
public <V extends StatisticValue<R>, R> IndexStatistic<V> getIndexStatistic(final StatisticType<V> statisticType, final String indexName, final String tag) {
if (!(statisticType instanceof IndexStatisticType)) {
throw new IllegalArgumentException("Statistic type must be an index statistic.");
}
final Index index = getIndex(indexName);
if (index == null) {
throw new IllegalArgumentException(indexName + " doesn't exist");
}
IndexStatistic<V> retVal = null;
if (tag == null) {
retVal = internalGetIndexStatistic((IndexStatisticType<V>) statisticType, index, Statistic.DEFAULT_TAG);
if (retVal == null) {
retVal = internalGetIndexStatistic((IndexStatisticType<V>) statisticType, index, Statistic.INTERNAL_TAG);
}
if (retVal == null) {
try (CloseableIterator<IndexStatistic<V>> iter = (CloseableIterator<IndexStatistic<V>>) statisticsStore.getIndexStatistics(index, statisticType, null)) {
if (iter.hasNext()) {
retVal = iter.next();
if (iter.hasNext()) {
throw new IllegalArgumentException("Multiple statistics with different tags were found. A tag must be specified.");
}
}
}
}
} else {
retVal = internalGetIndexStatistic((IndexStatisticType<V>) statisticType, index, tag);
}
return retVal;
}
use of org.locationtech.geowave.core.store.api.IndexStatistic in project geowave by locationtech.
the class BaseDataStore method getIndexStatistics.
@Override
public IndexStatistic<?>[] getIndexStatistics(final String indexName) {
final Index index = getIndex(indexName);
if (index == null) {
throw new IllegalArgumentException(indexName + " doesn't exist");
}
final List<IndexStatistic<?>> retVal = new ArrayList<>();
try (CloseableIterator<? extends IndexStatistic<?>> it = statisticsStore.getIndexStatistics(index, null, null)) {
while (it.hasNext()) {
retVal.add(it.next());
}
}
return retVal.toArray(new IndexStatistic<?>[retVal.size()]);
}
Aggregations