Search in sources :

Example 1 with PartitionsStatistic

use of org.locationtech.geowave.core.store.statistics.index.PartitionsStatistic 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 PartitionsStatistic

use of org.locationtech.geowave.core.store.statistics.index.PartitionsStatistic in project geowave by locationtech.

the class DeletePyramidLevelCommand method run.

public void run(final OperationParams params) {
    // Ensure we have all the required arguments
    if (parameters.size() != 1) {
        throw new ParameterException("Requires argument: <store name>");
    }
    final String inputStoreName = parameters.get(0);
    // Attempt to load store.
    inputStoreOptions = CLIUtils.loadStore(inputStoreName, getGeoWaveConfigFile(params), params.getConsole());
    final DataStore store = inputStoreOptions.createDataStore();
    RasterDataAdapter adapter = null;
    for (final DataTypeAdapter<?> type : store.getTypes()) {
        if (isRaster(type) && ((coverageName == null) || coverageName.equals(adapter.getTypeName()))) {
            if (adapter != null) {
                LOGGER.error("Store has multiple coverages.  Must explicitly choose one with --coverage option.");
                return;
            }
            adapter = (RasterDataAdapter) type;
        }
    }
    if (adapter == null) {
        LOGGER.error("Store has no coverages or coverage name not found.");
        return;
    }
    boolean found = false;
    Resolution res = null;
    Index i = null;
    for (final Index index : store.getIndices(adapter.getTypeName())) {
        final HierarchicalNumericIndexStrategy indexStrategy = CompoundHierarchicalIndexStrategyWrapper.findHierarchicalStrategy(index.getIndexStrategy());
        if (indexStrategy != null) {
            for (final SubStrategy s : indexStrategy.getSubStrategies()) {
                if ((s.getPrefix().length == 1) && (s.getPrefix()[0] == level)) {
                    LOGGER.info("Deleting from index " + index.getName());
                    final double[] tileRes = s.getIndexStrategy().getHighestPrecisionIdRangePerDimension();
                    final double[] pixelRes = new double[tileRes.length];
                    for (int d = 0; d < tileRes.length; d++) {
                        pixelRes[d] = tileRes[d] / adapter.getTileSize();
                    }
                    found = true;
                    i = index;
                    res = new Resolution(pixelRes);
                    break;
                }
            }
        }
        if (found) {
            break;
        }
    }
    if (!found) {
        LOGGER.error("Store has no indices supporting pyramids.");
        return;
    }
    final byte[][] predefinedSplits = i.getIndexStrategy().getPredefinedSplits();
    // this should account for hash partitioning if used
    final List<ByteArray> partitions = new ArrayList<>();
    if ((predefinedSplits != null) && (predefinedSplits.length > 0)) {
        for (final byte[] split : predefinedSplits) {
            partitions.add(new ByteArray(ArrayUtils.add(split, level.byteValue())));
        }
    } else {
        partitions.add(new ByteArray(new byte[] { level.byteValue() }));
    }
    // delete the resolution from the overview, delete the partitions, and delete the data
    if (inputStoreOptions.getFactoryOptions().getStoreOptions().isPersistDataStatistics()) {
        final DataStatisticsStore statsStore = inputStoreOptions.createDataStatisticsStore();
        boolean overviewStatsFound = false;
        boolean partitionStatsFound = false;
        try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> it = statsStore.getDataTypeStatistics(adapter, RasterOverviewStatistic.STATS_TYPE, null)) {
            while (it.hasNext()) {
                final Statistic<? extends StatisticValue<?>> next = it.next();
                if ((next instanceof RasterOverviewStatistic) && (next.getBinningStrategy() == null)) {
                    final RasterOverviewStatistic statistic = (RasterOverviewStatistic) next;
                    final RasterOverviewValue value = statsStore.getStatisticValue(statistic);
                    if (!value.removeResolution(res)) {
                        LOGGER.error("Unable to remove resolution for pyramid level " + level);
                        return;
                    }
                    statsStore.setStatisticValue(statistic, value);
                    overviewStatsFound = true;
                }
            }
        }
        if (!overviewStatsFound) {
            LOGGER.error("Unable to find overview stats for coverage " + adapter.getTypeName());
            return;
        }
        try (CloseableIterator<? extends Statistic<? extends StatisticValue<?>>> it = statsStore.getIndexStatistics(i, PartitionsStatistic.STATS_TYPE, null)) {
            while (it.hasNext()) {
                final Statistic<? extends StatisticValue<?>> next = it.next();
                if (next instanceof PartitionsStatistic) {
                    if ((next.getBinningStrategy() != null) && (next.getBinningStrategy() instanceof DataTypeBinningStrategy)) {
                        final PartitionsStatistic statistic = (PartitionsStatistic) next;
                        final PartitionsValue value = statsStore.getStatisticValue((PartitionsStatistic) next, DataTypeBinningStrategy.getBin(adapter));
                        for (final ByteArray p : partitions) {
                            if (!value.getValue().remove(p)) {
                                LOGGER.error("Unable to remove partition " + p.getHexString() + " for pyramid level " + level);
                                return;
                            }
                        }
                        statsStore.setStatisticValue(statistic, value, DataTypeBinningStrategy.getBin(adapter));
                        partitionStatsFound = true;
                    }
                }
            }
        }
        if (!partitionStatsFound) {
            LOGGER.error("Unable to find partition stats for coverage " + adapter.getTypeName() + " and index " + i.getName());
            return;
        }
    }
    for (final ByteArray p : partitions) {
        store.delete(QueryBuilder.newBuilder().constraints(QueryBuilder.newBuilder().constraintsFactory().prefix(p.getBytes(), null)).addTypeName(adapter.getTypeName()).indexName(i.getName()).build());
    }
}
Also used : PartitionsValue(org.locationtech.geowave.core.store.statistics.index.PartitionsStatistic.PartitionsValue) ArrayList(java.util.ArrayList) Index(org.locationtech.geowave.core.store.api.Index) PartitionsStatistic(org.locationtech.geowave.core.store.statistics.index.PartitionsStatistic) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) DataStore(org.locationtech.geowave.core.store.api.DataStore) RasterOverviewValue(org.locationtech.geowave.adapter.raster.stats.RasterOverviewStatistic.RasterOverviewValue) ByteArray(org.locationtech.geowave.core.index.ByteArray) ParameterException(com.beust.jcommander.ParameterException) SubStrategy(org.locationtech.geowave.core.index.HierarchicalNumericIndexStrategy.SubStrategy) HierarchicalNumericIndexStrategy(org.locationtech.geowave.core.index.HierarchicalNumericIndexStrategy) DataTypeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.DataTypeBinningStrategy) RasterDataAdapter(org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter) RasterOverviewStatistic(org.locationtech.geowave.adapter.raster.stats.RasterOverviewStatistic) Resolution(org.locationtech.geowave.adapter.raster.Resolution)

Aggregations

DataTypeBinningStrategy (org.locationtech.geowave.core.store.statistics.binning.DataTypeBinningStrategy)2 PartitionsStatistic (org.locationtech.geowave.core.store.statistics.index.PartitionsStatistic)2 ParameterException (com.beust.jcommander.ParameterException)1 ArrayList (java.util.ArrayList)1 Resolution (org.locationtech.geowave.adapter.raster.Resolution)1 RasterDataAdapter (org.locationtech.geowave.adapter.raster.adapter.RasterDataAdapter)1 RasterOverviewStatistic (org.locationtech.geowave.adapter.raster.stats.RasterOverviewStatistic)1 RasterOverviewValue (org.locationtech.geowave.adapter.raster.stats.RasterOverviewStatistic.RasterOverviewValue)1 ByteArray (org.locationtech.geowave.core.index.ByteArray)1 HierarchicalNumericIndexStrategy (org.locationtech.geowave.core.index.HierarchicalNumericIndexStrategy)1 SubStrategy (org.locationtech.geowave.core.index.HierarchicalNumericIndexStrategy.SubStrategy)1 DataStore (org.locationtech.geowave.core.store.api.DataStore)1 Index (org.locationtech.geowave.core.store.api.Index)1 Statistic (org.locationtech.geowave.core.store.api.Statistic)1 StatisticValue (org.locationtech.geowave.core.store.api.StatisticValue)1 DataStatisticsStore (org.locationtech.geowave.core.store.statistics.DataStatisticsStore)1 CompositeBinningStrategy (org.locationtech.geowave.core.store.statistics.binning.CompositeBinningStrategy)1 PartitionBinningStrategy (org.locationtech.geowave.core.store.statistics.binning.PartitionBinningStrategy)1 DifferingVisibilityCountStatistic (org.locationtech.geowave.core.store.statistics.index.DifferingVisibilityCountStatistic)1 DuplicateEntryCountStatistic (org.locationtech.geowave.core.store.statistics.index.DuplicateEntryCountStatistic)1