Search in sources :

Example 1 with FieldStatistic

use of org.locationtech.geowave.core.store.api.FieldStatistic 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);
}
Also used : IndexStatistic(org.locationtech.geowave.core.store.api.IndexStatistic) Statistic(org.locationtech.geowave.core.store.api.Statistic) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic) DataTypeStatistic(org.locationtech.geowave.core.store.api.DataTypeStatistic) IndexStatistic(org.locationtech.geowave.core.store.api.IndexStatistic) DataTypeStatistic(org.locationtech.geowave.core.store.api.DataTypeStatistic) ConsoleTablePrinter(org.locationtech.geowave.core.cli.utils.ConsoleTablePrinter) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic)

Example 2 with FieldStatistic

use of org.locationtech.geowave.core.store.api.FieldStatistic 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;
}
Also used : StatisticType(org.locationtech.geowave.core.store.statistics.StatisticType) DataTypeStatisticType(org.locationtech.geowave.core.store.statistics.adapter.DataTypeStatisticType) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic) FieldStatisticType(org.locationtech.geowave.core.store.statistics.field.FieldStatisticType) ParameterException(com.beust.jcommander.ParameterException) DataStore(org.locationtech.geowave.core.store.api.DataStore) Parameter(com.beust.jcommander.Parameter) DataTypeStatistic(org.locationtech.geowave.core.store.api.DataTypeStatistic) IndexStatisticType(org.locationtech.geowave.core.store.statistics.index.IndexStatisticType) IndexStatistic(org.locationtech.geowave.core.store.api.IndexStatistic) Lists(com.clearspring.analytics.util.Lists) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) List(java.util.List) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) StatisticsRegistry(org.locationtech.geowave.core.store.statistics.StatisticsRegistry) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) Statistic(org.locationtech.geowave.core.store.api.Statistic) Index(org.locationtech.geowave.core.store.api.Index) FieldDescriptor(org.locationtech.geowave.core.store.adapter.FieldDescriptor) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) IndexStatistic(org.locationtech.geowave.core.store.api.IndexStatistic) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) Index(org.locationtech.geowave.core.store.api.Index) IndexStatisticType(org.locationtech.geowave.core.store.statistics.index.IndexStatisticType) FieldDescriptor(org.locationtech.geowave.core.store.adapter.FieldDescriptor) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic) DataTypeStatistic(org.locationtech.geowave.core.store.api.DataTypeStatistic) IndexStatistic(org.locationtech.geowave.core.store.api.IndexStatistic) Statistic(org.locationtech.geowave.core.store.api.Statistic) StatisticType(org.locationtech.geowave.core.store.statistics.StatisticType) DataTypeStatisticType(org.locationtech.geowave.core.store.statistics.adapter.DataTypeStatisticType) FieldStatisticType(org.locationtech.geowave.core.store.statistics.field.FieldStatisticType) IndexStatisticType(org.locationtech.geowave.core.store.statistics.index.IndexStatisticType) DataTypeStatistic(org.locationtech.geowave.core.store.api.DataTypeStatistic) ParameterException(com.beust.jcommander.ParameterException) FieldStatisticType(org.locationtech.geowave.core.store.statistics.field.FieldStatisticType) DataTypeStatisticType(org.locationtech.geowave.core.store.statistics.adapter.DataTypeStatisticType) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic)

Example 3 with FieldStatistic

use of org.locationtech.geowave.core.store.api.FieldStatistic in project geowave by locationtech.

the class BaseDataStore method groupAndValidateStats.

private Pair<Map<Index, List<IndexStatistic<?>>>, Map<InternalDataAdapter<?>, List<Statistic<? extends StatisticValue<?>>>>> groupAndValidateStats(final Statistic<? extends StatisticValue<?>>[] statistics, final boolean allowExisting) {
    final Map<Index, List<IndexStatistic<?>>> indexStatsToAdd = Maps.newHashMap();
    final Map<InternalDataAdapter<?>, List<Statistic<? extends StatisticValue<?>>>> otherStatsToAdd = Maps.newHashMap();
    for (final Statistic<? extends StatisticValue<?>> statistic : statistics) {
        if (!allowExisting && statisticsStore.exists(statistic)) {
            throw new IllegalArgumentException("The statistic already exists.  If adding it is still desirable, use a 'tag' to make the statistic unique.");
        }
        if (statistic instanceof IndexStatistic) {
            final IndexStatistic<?> indexStat = (IndexStatistic<?>) statistic;
            if (indexStat.getIndexName() == null) {
                throw new IllegalArgumentException("No index specified.");
            }
            final Index index = indexStore.getIndex(indexStat.getIndexName());
            if (index == null) {
                throw new IllegalArgumentException("No index named " + indexStat.getIndexName() + ".");
            }
            if (!indexStatsToAdd.containsKey(index)) {
                indexStatsToAdd.put(index, Lists.newArrayList());
            }
            indexStatsToAdd.get(index).add(indexStat);
        } else if (statistic instanceof DataTypeStatistic) {
            final DataTypeStatistic<?> adapterStat = (DataTypeStatistic<?>) statistic;
            if (adapterStat.getTypeName() == null) {
                throw new IllegalArgumentException("No type specified.");
            }
            final InternalDataAdapter<?> adapter = getInternalAdapter(adapterStat.getTypeName());
            if (adapter == null) {
                throw new IllegalArgumentException("No type named " + adapterStat.getTypeName() + ".");
            }
            if (!otherStatsToAdd.containsKey(adapter)) {
                otherStatsToAdd.put(adapter, Lists.newArrayList());
            }
            otherStatsToAdd.get(adapter).add(adapterStat);
        } else if (statistic instanceof FieldStatistic) {
            final FieldStatistic<?> fieldStat = (FieldStatistic<?>) statistic;
            if (fieldStat.getTypeName() == null) {
                throw new IllegalArgumentException("No type specified.");
            }
            final InternalDataAdapter<?> adapter = getInternalAdapter(fieldStat.getTypeName());
            if (adapter == null) {
                throw new IllegalArgumentException("No type named " + fieldStat.getTypeName() + ".");
            }
            if (fieldStat.getFieldName() == null) {
                throw new IllegalArgumentException("No field specified.");
            }
            boolean foundMatch = false;
            final FieldDescriptor<?>[] fields = adapter.getFieldDescriptors();
            for (int i = 0; i < fields.length; i++) {
                if (fieldStat.getFieldName().equals(fields[i].fieldName())) {
                    foundMatch = true;
                    break;
                }
            }
            if (!foundMatch) {
                throw new IllegalArgumentException("No field named " + fieldStat.getFieldName() + " was found on the type " + fieldStat.getTypeName() + ".");
            }
            if (!otherStatsToAdd.containsKey(adapter)) {
                otherStatsToAdd.put(adapter, Lists.newArrayList());
            }
            otherStatsToAdd.get(adapter).add(fieldStat);
        } else {
            throw new IllegalArgumentException("Unrecognized statistic type.");
        }
    }
    return Pair.of(indexStatsToAdd, otherStatsToAdd);
}
Also used : IndexStatistic(org.locationtech.geowave.core.store.api.IndexStatistic) Index(org.locationtech.geowave.core.store.api.Index) FieldDescriptor(org.locationtech.geowave.core.store.adapter.FieldDescriptor) DataTypeStatistic(org.locationtech.geowave.core.store.api.DataTypeStatistic) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) IngestCallbackList(org.locationtech.geowave.core.store.callback.IngestCallbackList) DeleteCallbackList(org.locationtech.geowave.core.store.callback.DeleteCallbackList) ArrayList(java.util.ArrayList) List(java.util.List) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic)

Example 4 with FieldStatistic

use of org.locationtech.geowave.core.store.api.FieldStatistic in project geowave by locationtech.

the class GeoWaveGTPluginUtils method accepts.

protected static boolean accepts(final DataStatisticsStore statisticsStore, final DataTypeAdapter<?> adapter, final org.opengis.feature.FeatureVisitor visitor, final org.opengis.util.ProgressListener progress, final SimpleFeatureType featureType) throws IOException {
    if ((visitor instanceof MinVisitor)) {
        final ExtractAttributesFilter filter = new ExtractAttributesFilter();
        final MinVisitor minVisitor = (MinVisitor) visitor;
        final Collection<String> attrs = (Collection<String>) minVisitor.getExpression().accept(filter, null);
        int acceptedCount = 0;
        final Map<String, List<FieldStatistic<?>>> adapterFieldStatistics = getFieldStats(statisticsStore, adapter);
        for (final String attr : attrs) {
            if (!adapterFieldStatistics.containsKey(attr)) {
                continue;
            }
            for (final FieldStatistic<?> stat : adapterFieldStatistics.get(attr)) {
                if ((stat instanceof TimeRangeStatistic) && (stat.getBinningStrategy() == null)) {
                    final TimeRangeValue statValue = statisticsStore.getStatisticValue((TimeRangeStatistic) stat);
                    if (statValue != null) {
                        minVisitor.setValue(convertToType(attr, new Date(statValue.getMin()), featureType));
                        acceptedCount++;
                    }
                } else if (stat instanceof NumericRangeStatistic) {
                    try (CloseableIterator<NumericRangeValue> values = statisticsStore.getStatisticValues((NumericRangeStatistic) stat)) {
                        NumericRangeValue statValue = ((NumericRangeStatistic) stat).createEmpty();
                        while (values.hasNext()) {
                            statValue.merge(values.next());
                        }
                        if (statValue.isSet()) {
                            minVisitor.setValue(convertToType(attr, statValue.getMin(), featureType));
                            acceptedCount++;
                        }
                    }
                }
            }
        }
        if (acceptedCount > 0) {
            if (progress != null) {
                progress.complete();
            }
            return true;
        }
    } else if ((visitor instanceof MaxVisitor)) {
        final ExtractAttributesFilter filter = new ExtractAttributesFilter();
        final MaxVisitor maxVisitor = (MaxVisitor) visitor;
        final Collection<String> attrs = (Collection<String>) maxVisitor.getExpression().accept(filter, null);
        int acceptedCount = 0;
        final Map<String, List<FieldStatistic<?>>> adapterFieldStatistics = getFieldStats(statisticsStore, adapter);
        for (final String attr : attrs) {
            for (final FieldStatistic<?> stat : adapterFieldStatistics.get(attr)) {
                if ((stat instanceof TimeRangeStatistic) && (stat.getBinningStrategy() == null)) {
                    final TimeRangeValue statValue = statisticsStore.getStatisticValue((TimeRangeStatistic) stat);
                    if (statValue != null) {
                        maxVisitor.setValue(convertToType(attr, new Date(statValue.getMax()), featureType));
                        acceptedCount++;
                    }
                } else if (stat instanceof NumericRangeStatistic) {
                    try (CloseableIterator<NumericRangeValue> values = statisticsStore.getStatisticValues((NumericRangeStatistic) stat)) {
                        NumericRangeValue statValue = ((NumericRangeStatistic) stat).createEmpty();
                        while (values.hasNext()) {
                            statValue.merge(values.next());
                        }
                        if (statValue.isSet()) {
                            maxVisitor.setValue(convertToType(attr, statValue.getMax(), featureType));
                            acceptedCount++;
                        }
                    }
                }
            }
        }
        if (acceptedCount > 0) {
            if (progress != null) {
                progress.complete();
            }
            return true;
        }
    }
    return false;
}
Also used : CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) NumericRangeStatistic(org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic) MinVisitor(org.geotools.feature.visitor.MinVisitor) ExtractAttributesFilter(org.locationtech.geowave.core.geotime.util.ExtractAttributesFilter) Date(java.util.Date) MaxVisitor(org.geotools.feature.visitor.MaxVisitor) Collection(java.util.Collection) List(java.util.List) NumericRangeValue(org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic.NumericRangeValue) TimeRangeStatistic(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic) TimeRangeValue(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue) Map(java.util.Map) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic)

Aggregations

FieldStatistic (org.locationtech.geowave.core.store.api.FieldStatistic)4 List (java.util.List)3 DataTypeStatistic (org.locationtech.geowave.core.store.api.DataTypeStatistic)3 IndexStatistic (org.locationtech.geowave.core.store.api.IndexStatistic)3 CloseableIterator (org.locationtech.geowave.core.store.CloseableIterator)2 FieldDescriptor (org.locationtech.geowave.core.store.adapter.FieldDescriptor)2 Index (org.locationtech.geowave.core.store.api.Index)2 Statistic (org.locationtech.geowave.core.store.api.Statistic)2 Parameter (com.beust.jcommander.Parameter)1 ParameterException (com.beust.jcommander.ParameterException)1 Lists (com.clearspring.analytics.util.Lists)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Map (java.util.Map)1 MaxVisitor (org.geotools.feature.visitor.MaxVisitor)1 MinVisitor (org.geotools.feature.visitor.MinVisitor)1 ConsoleTablePrinter (org.locationtech.geowave.core.cli.utils.ConsoleTablePrinter)1 TimeRangeStatistic (org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic)1 TimeRangeValue (org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue)1