Search in sources :

Example 1 with StatisticValue

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

the class IndexImpl method getDefaultStatistics.

@Override
public List<Statistic<? extends StatisticValue<?>>> getDefaultStatistics() {
    List<Statistic<? extends StatisticValue<?>>> statistics = Lists.newArrayListWithCapacity(6);
    IndexMetaDataSetStatistic metadata = new IndexMetaDataSetStatistic(getName(), indexStrategy.createMetaData());
    metadata.setBinningStrategy(new DataTypeBinningStrategy());
    metadata.setInternal();
    statistics.add(metadata);
    DuplicateEntryCountStatistic duplicateCounts = new DuplicateEntryCountStatistic(getName());
    duplicateCounts.setBinningStrategy(new DataTypeBinningStrategy());
    duplicateCounts.setInternal();
    statistics.add(duplicateCounts);
    PartitionsStatistic partitions = new PartitionsStatistic(getName());
    partitions.setBinningStrategy(new DataTypeBinningStrategy());
    partitions.setInternal();
    statistics.add(partitions);
    DifferingVisibilityCountStatistic differingFieldVisibility = new DifferingVisibilityCountStatistic(getName());
    differingFieldVisibility.setBinningStrategy(new DataTypeBinningStrategy());
    differingFieldVisibility.setInternal();
    statistics.add(differingFieldVisibility);
    FieldVisibilityCountStatistic fieldVisibilityCount = new FieldVisibilityCountStatistic(getName());
    fieldVisibilityCount.setBinningStrategy(new DataTypeBinningStrategy());
    fieldVisibilityCount.setInternal();
    statistics.add(fieldVisibilityCount);
    RowRangeHistogramStatistic rowRangeHistogram = new RowRangeHistogramStatistic(getName());
    rowRangeHistogram.setBinningStrategy(new CompositeBinningStrategy(new DataTypeBinningStrategy(), new PartitionBinningStrategy()));
    rowRangeHistogram.setInternal();
    statistics.add(rowRangeHistogram);
    return statistics;
}
Also used : DuplicateEntryCountStatistic(org.locationtech.geowave.core.store.statistics.index.DuplicateEntryCountStatistic) RowRangeHistogramStatistic(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic) DuplicateEntryCountStatistic(org.locationtech.geowave.core.store.statistics.index.DuplicateEntryCountStatistic) PartitionsStatistic(org.locationtech.geowave.core.store.statistics.index.PartitionsStatistic) IndexMetaDataSetStatistic(org.locationtech.geowave.core.store.statistics.index.IndexMetaDataSetStatistic) Statistic(org.locationtech.geowave.core.store.api.Statistic) FieldVisibilityCountStatistic(org.locationtech.geowave.core.store.statistics.index.FieldVisibilityCountStatistic) DifferingVisibilityCountStatistic(org.locationtech.geowave.core.store.statistics.index.DifferingVisibilityCountStatistic) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) RowRangeHistogramStatistic(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic) IndexMetaDataSetStatistic(org.locationtech.geowave.core.store.statistics.index.IndexMetaDataSetStatistic) DataTypeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.DataTypeBinningStrategy) DifferingVisibilityCountStatistic(org.locationtech.geowave.core.store.statistics.index.DifferingVisibilityCountStatistic) CompositeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.CompositeBinningStrategy) PartitionBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.PartitionBinningStrategy) PartitionsStatistic(org.locationtech.geowave.core.store.statistics.index.PartitionsStatistic) FieldVisibilityCountStatistic(org.locationtech.geowave.core.store.statistics.index.FieldVisibilityCountStatistic)

Example 2 with StatisticValue

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

the class AbstractGeoWaveBasicVectorIT method testStats.

@SuppressWarnings("unchecked")
protected void testStats(final URL[] inputFiles, final boolean multithreaded, final CoordinateReferenceSystem crs, final Index... indices) {
    // In the multithreaded case, only test min/max and count. Stats will be
    // ingested/ in a different order and will not match.
    final LocalFileIngestPlugin<SimpleFeature> localFileIngest = new GeoToolsVectorDataStoreIngestPlugin(Filter.INCLUDE);
    final Map<String, StatisticsCache> statsCache = new HashMap<>();
    final String[] indexNames = Arrays.stream(indices).map(i -> i.getName()).toArray(i -> new String[i]);
    for (final URL inputFile : inputFiles) {
        LOGGER.warn("Calculating stats from file '" + inputFile.getPath() + "' - this may take several minutes...");
        try (final CloseableIterator<GeoWaveData<SimpleFeature>> dataIterator = localFileIngest.toGeoWaveData(inputFile, indexNames)) {
            final TransientAdapterStore adapterCache = new MemoryAdapterStore(localFileIngest.getDataAdapters());
            while (dataIterator.hasNext()) {
                final GeoWaveData<SimpleFeature> data = dataIterator.next();
                final DataTypeAdapter<SimpleFeature> adapter = data.getAdapter(adapterCache);
                // it should be a statistical data adapter
                if (adapter instanceof DefaultStatisticsProvider) {
                    StatisticsCache cachedValues = statsCache.get(adapter.getTypeName());
                    if (cachedValues == null) {
                        cachedValues = new StatisticsCache(adapter, crs);
                        statsCache.put(adapter.getTypeName(), cachedValues);
                    }
                    cachedValues.entryIngested(data.getValue());
                }
            }
        }
    }
    final DataStatisticsStore statsStore = getDataStorePluginOptions().createDataStatisticsStore();
    final PersistentAdapterStore adapterStore = getDataStorePluginOptions().createAdapterStore();
    final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
    for (final InternalDataAdapter<?> internalDataAdapter : adapters) {
        final FeatureDataAdapter adapter = (FeatureDataAdapter) internalDataAdapter.getAdapter();
        final StatisticsCache cachedValue = statsCache.get(adapter.getTypeName());
        Assert.assertNotNull(cachedValue);
        final Set<Entry<Statistic<?>, Map<ByteArray, StatisticValue<?>>>> expectedStats = cachedValue.statsCache.entrySet();
        int statsCount = 0;
        try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> statsIterator = statsStore.getDataTypeStatistics(adapter, null, null)) {
            while (statsIterator.hasNext()) {
                statsIterator.next();
                statsCount++;
            }
        }
        try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> statsIterator = statsStore.getFieldStatistics(adapter, null, null, null)) {
            while (statsIterator.hasNext()) {
                statsIterator.next();
                statsCount++;
            }
        }
        Assert.assertEquals("The number of stats for data adapter '" + adapter.getTypeName() + "' do not match count expected", expectedStats.size(), statsCount);
        for (final Entry<Statistic<?>, Map<ByteArray, StatisticValue<?>>> expectedStat : expectedStats) {
            for (final Entry<ByteArray, StatisticValue<?>> expectedValues : expectedStat.getValue().entrySet()) {
                StatisticValue<Object> actual;
                if (expectedValues.getKey().equals(StatisticValue.NO_BIN)) {
                    actual = statsStore.getStatisticValue((Statistic<StatisticValue<Object>>) expectedStat.getKey());
                } else {
                    actual = statsStore.getStatisticValue((Statistic<StatisticValue<Object>>) expectedStat.getKey(), expectedValues.getKey());
                }
                assertEquals(expectedValues.getValue().getValue(), actual.getValue());
            }
        }
        // finally check the one stat that is more manually calculated -
        // the bounding box
        StatisticQuery<BoundingBoxValue, Envelope> query = StatisticQueryBuilder.newBuilder(BoundingBoxStatistic.STATS_TYPE).fieldName(adapter.getFeatureType().getGeometryDescriptor().getLocalName()).typeName(adapter.getTypeName()).build();
        BoundingBoxValue bboxStat = getDataStorePluginOptions().createDataStore().aggregateStatistics(query);
        validateBBox(bboxStat.getValue(), cachedValue);
        // now make sure it works without giving field name because there is only one geometry field
        // anyways
        query = StatisticQueryBuilder.newBuilder(BoundingBoxStatistic.STATS_TYPE).typeName(adapter.getTypeName()).build();
        bboxStat = getDataStorePluginOptions().createDataStore().aggregateStatistics(query);
        validateBBox(bboxStat.getValue(), cachedValue);
        final StatisticId<BoundingBoxValue> bboxStatId = FieldStatistic.generateStatisticId(adapter.getTypeName(), BoundingBoxStatistic.STATS_TYPE, adapter.getFeatureType().getGeometryDescriptor().getLocalName(), Statistic.INTERNAL_TAG);
        Assert.assertTrue("Unable to remove individual stat", statsStore.removeStatistic(statsStore.getStatisticById(bboxStatId)));
        Assert.assertNull("Individual stat was not successfully removed", statsStore.getStatisticById(bboxStatId));
    }
}
Also used : FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) Arrays(java.util.Arrays) GeoWaveData(org.locationtech.geowave.core.store.ingest.GeoWaveData) URL(java.net.URL) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) CommonIndexAggregation(org.locationtech.geowave.core.store.query.aggregate.CommonIndexAggregation) LoggerFactory(org.slf4j.LoggerFactory) Aggregation(org.locationtech.geowave.core.store.api.Aggregation) MathUtils(org.apache.commons.math.util.MathUtils) TestUtils(org.locationtech.geowave.test.TestUtils) StatisticId(org.locationtech.geowave.core.store.statistics.StatisticId) ByteBuffer(java.nio.ByteBuffer) TimeDescriptors(org.locationtech.geowave.core.geotime.util.TimeDescriptors) TransientAdapterStore(org.locationtech.geowave.core.store.adapter.TransientAdapterStore) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) Pair(org.apache.commons.lang3.tuple.Pair) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Map(java.util.Map) Statistic(org.locationtech.geowave.core.store.api.Statistic) Maps(jersey.repackaged.com.google.common.collect.Maps) Persistable(org.locationtech.geowave.core.index.persist.Persistable) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic) StatisticQuery(org.locationtech.geowave.core.store.api.StatisticQuery) Set(java.util.Set) ManualOperationParams(org.locationtech.geowave.core.cli.parser.ManualOperationParams) DimensionalityType(org.locationtech.geowave.test.TestUtils.DimensionalityType) ExpectedResults(org.locationtech.geowave.test.TestUtils.ExpectedResults) ConfigOptions(org.locationtech.geowave.core.cli.operations.config.options.ConfigOptions) List(java.util.List) VectorLocalExportOptions(org.locationtech.geowave.adapter.vector.export.VectorLocalExportOptions) Entry(java.util.Map.Entry) DataIdQuery(org.locationtech.geowave.core.store.query.constraints.DataIdQuery) Geometry(org.locationtech.jts.geom.Geometry) BoundingBoxValue(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic.BoundingBoxValue) DefaultStatisticsProvider(org.locationtech.geowave.core.store.statistics.DefaultStatisticsProvider) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ByteArray(org.locationtech.geowave.core.index.ByteArray) AggregationQuery(org.locationtech.geowave.core.store.api.AggregationQuery) BeforeClass(org.junit.BeforeClass) AddStoreCommand(org.locationtech.geowave.core.store.cli.store.AddStoreCommand) AggregationQueryBuilder(org.locationtech.geowave.core.store.api.AggregationQueryBuilder) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CommonIndexedPersistenceEncoding(org.locationtech.geowave.core.store.data.CommonIndexedPersistenceEncoding) HashSet(java.util.HashSet) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) LocalFileIngestPlugin(org.locationtech.geowave.core.store.ingest.LocalFileIngestPlugin) Calendar(java.util.Calendar) Lists(com.google.common.collect.Lists) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) StatisticQueryBuilder(org.locationtech.geowave.core.store.api.StatisticQueryBuilder) QueryBuilder(org.locationtech.geowave.core.store.api.QueryBuilder) Index(org.locationtech.geowave.core.store.api.Index) StatisticsIngestCallback(org.locationtech.geowave.core.store.statistics.StatisticsIngestCallback) BoundingBoxStatistic(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic) GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) GeotoolsFeatureDataAdapter(org.locationtech.geowave.core.geotime.store.GeotoolsFeatureDataAdapter) Logger(org.slf4j.Logger) DataStore(org.locationtech.geowave.core.store.api.DataStore) OptimalCQLQuery(org.locationtech.geowave.core.geotime.store.query.OptimalCQLQuery) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) IngestCallback(org.locationtech.geowave.core.store.callback.IngestCallback) QueryConstraints(org.locationtech.geowave.core.store.query.constraints.QueryConstraints) VectorLocalExportCommand(org.locationtech.geowave.adapter.vector.export.VectorLocalExportCommand) File(java.io.File) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) DataStorePluginOptions(org.locationtech.geowave.core.store.cli.store.DataStorePluginOptions) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) InternalGeotoolsFeatureDataAdapter(org.locationtech.geowave.core.geotime.store.InternalGeotoolsFeatureDataAdapter) MemoryAdapterStore(org.locationtech.geowave.core.store.memory.MemoryAdapterStore) Filter(org.opengis.filter.Filter) ZipUtils(org.locationtech.geowave.adapter.raster.util.ZipUtils) Assert(org.junit.Assert) GeoToolsVectorDataStoreIngestPlugin(org.locationtech.geowave.format.geotools.vector.GeoToolsVectorDataStoreIngestPlugin) Envelope(org.locationtech.jts.geom.Envelope) Assert.assertEquals(org.junit.Assert.assertEquals) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) HashMap(java.util.HashMap) GeoToolsVectorDataStoreIngestPlugin(org.locationtech.geowave.format.geotools.vector.GeoToolsVectorDataStoreIngestPlugin) DefaultStatisticsProvider(org.locationtech.geowave.core.store.statistics.DefaultStatisticsProvider) BoundingBoxValue(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic.BoundingBoxValue) Envelope(org.locationtech.jts.geom.Envelope) URL(java.net.URL) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) Entry(java.util.Map.Entry) Statistic(org.locationtech.geowave.core.store.api.Statistic) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic) BoundingBoxStatistic(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic) InternalDataAdapter(org.locationtech.geowave.core.store.adapter.InternalDataAdapter) ByteArray(org.locationtech.geowave.core.index.ByteArray) TransientAdapterStore(org.locationtech.geowave.core.store.adapter.TransientAdapterStore) MemoryAdapterStore(org.locationtech.geowave.core.store.memory.MemoryAdapterStore) SimpleFeature(org.opengis.feature.simple.SimpleFeature) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) GeoWaveData(org.locationtech.geowave.core.store.ingest.GeoWaveData) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) GeotoolsFeatureDataAdapter(org.locationtech.geowave.core.geotime.store.GeotoolsFeatureDataAdapter) InternalGeotoolsFeatureDataAdapter(org.locationtech.geowave.core.geotime.store.InternalGeotoolsFeatureDataAdapter) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with StatisticValue

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

the class DataStatisticsStoreImpl method removeStatisticValues.

@SuppressWarnings("unchecked")
@Override
public boolean removeStatisticValues(final Statistic<? extends StatisticValue<?>> statistic) {
    if (statistic.getBinningStrategy() == null) {
        return removeStatisticValue(statistic);
    }
    // TODO: The performance of this operation could be improved if primary ID prefix queries were
    // allowed during delete.
    boolean deleted = false;
    final List<ByteArray> binsToRemove = Lists.newLinkedList();
    try (CloseableIterator<StatisticValue<Object>> valueIter = getStatisticValues((Statistic<StatisticValue<Object>>) statistic)) {
        while (valueIter.hasNext()) {
            final ByteArray bin = valueIter.next().getBin();
            binsToRemove.add(bin);
        }
    }
    for (final ByteArray bin : binsToRemove) {
        deleted = deleted || removeStatisticValue(statistic, bin);
    }
    return deleted;
}
Also used : StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) ByteArray(org.locationtech.geowave.core.index.ByteArray)

Example 4 with StatisticValue

use of org.locationtech.geowave.core.store.api.StatisticValue 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;
}
Also used : StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) DataTypeAdapter(org.locationtech.geowave.core.store.api.DataTypeAdapter) Index(org.locationtech.geowave.core.store.api.Index) DataStorePluginOptions(org.locationtech.geowave.core.store.cli.store.DataStorePluginOptions) 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) DataStore(org.locationtech.geowave.core.store.api.DataStore) ParameterException(com.beust.jcommander.ParameterException) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) ConsoleTablePrinter(org.locationtech.geowave.core.cli.utils.ConsoleTablePrinter)

Example 5 with StatisticValue

use of org.locationtech.geowave.core.store.api.StatisticValue 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;
}
Also used : StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) Index(org.locationtech.geowave.core.store.api.Index) IndexStatisticType(org.locationtech.geowave.core.store.statistics.index.IndexStatisticType) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) 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) ParameterException(com.beust.jcommander.ParameterException) ArrayList(java.util.ArrayList) List(java.util.List) StatisticsValueIterator(org.locationtech.geowave.core.store.statistics.StatisticsValueIterator) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) DataTypeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.DataTypeBinningStrategy) CompositeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.CompositeBinningStrategy) FieldStatisticType(org.locationtech.geowave.core.store.statistics.field.FieldStatisticType) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) DataTypeStatisticType(org.locationtech.geowave.core.store.statistics.adapter.DataTypeStatisticType) ConsoleTablePrinter(org.locationtech.geowave.core.cli.utils.ConsoleTablePrinter)

Aggregations

StatisticValue (org.locationtech.geowave.core.store.api.StatisticValue)11 Statistic (org.locationtech.geowave.core.store.api.Statistic)8 Index (org.locationtech.geowave.core.store.api.Index)7 ParameterException (com.beust.jcommander.ParameterException)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 DataStore (org.locationtech.geowave.core.store.api.DataStore)5 FieldStatistic (org.locationtech.geowave.core.store.api.FieldStatistic)5 DataStatisticsStore (org.locationtech.geowave.core.store.statistics.DataStatisticsStore)5 DataTypeStatistic (org.locationtech.geowave.core.store.api.DataTypeStatistic)4 IndexStatistic (org.locationtech.geowave.core.store.api.IndexStatistic)4 IndexStore (org.locationtech.geowave.core.store.index.IndexStore)4 Map (java.util.Map)3 ByteArray (org.locationtech.geowave.core.index.ByteArray)3 CloseableIterator (org.locationtech.geowave.core.store.CloseableIterator)3 DataTypeAdapter (org.locationtech.geowave.core.store.api.DataTypeAdapter)3 CompositeBinningStrategy (org.locationtech.geowave.core.store.statistics.binning.CompositeBinningStrategy)3 DataTypeBinningStrategy (org.locationtech.geowave.core.store.statistics.binning.DataTypeBinningStrategy)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2