Search in sources :

Example 1 with StatisticUpdateCallback

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

the class BaseDataStore method calcStats.

@SuppressWarnings("unchecked")
private void calcStats(final Map<Index, List<IndexStatistic<?>>> indexStatsToAdd, final Map<InternalDataAdapter<?>, List<Statistic<? extends StatisticValue<?>>>> otherStatsToAdd) {
    for (final Entry<Index, List<IndexStatistic<?>>> indexStats : indexStatsToAdd.entrySet()) {
        final Index index = indexStats.getKey();
        final ArrayList<Short> indexAdapters = new ArrayList<>();
        final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
        for (final InternalDataAdapter<?> dataAdapter : adapters) {
            final AdapterToIndexMapping[] adapterIndexMap = indexMappingStore.getIndicesForAdapter(dataAdapter.getAdapterId());
            for (int i = 0; i < adapterIndexMap.length; i++) {
                if (adapterIndexMap[i].getIndexName().equals(index.getName())) {
                    indexAdapters.add(adapterIndexMap[i].getAdapterId());
                    break;
                }
            }
        }
        // Scan all adapters used on the index
        for (int i = 0; i < indexAdapters.size(); i++) {
            final short adapterId = indexAdapters.get(i);
            final InternalDataAdapter<?> adapter = adapterStore.getAdapter(adapterId);
            final Query<Object> query = QueryBuilder.newBuilder().addTypeName(adapter.getTypeName()).indexName(index.getName()).build();
            final List<Statistic<? extends StatisticValue<?>>> statsToUpdate = Lists.newArrayList(indexStats.getValue());
            if (otherStatsToAdd.containsKey(adapter)) {
                statsToUpdate.addAll(otherStatsToAdd.get(adapter));
                // Adapter-specific stats only need to be computed once, so remove them once they've
                // been processed
                otherStatsToAdd.remove(adapter);
            }
            final AdapterToIndexMapping indexMapping = indexMappingStore.getMapping(adapterId, index.getName());
            try (StatisticUpdateCallback<?> updateCallback = new StatisticUpdateCallback<>(statsToUpdate, statisticsStore, index, indexMapping, adapter)) {
                try (CloseableIterator<?> entryIt = this.query(query, (ScanCallback<Object, GeoWaveRow>) updateCallback)) {
                    while (entryIt.hasNext()) {
                        entryIt.next();
                    }
                }
            }
        }
    }
    for (final Entry<InternalDataAdapter<?>, List<Statistic<? extends StatisticValue<?>>>> otherStats : otherStatsToAdd.entrySet()) {
        final InternalDataAdapter<?> adapter = otherStats.getKey();
        final String typeName = adapter.getTypeName();
        final Index[] indices = getIndices(typeName);
        if (indices.length == 0) {
            // If there are no indices, then there is nothing to calculate.
            return;
        }
        final Query<Object> query = QueryBuilder.newBuilder().addTypeName(typeName).indexName(indices[0].getName()).build();
        final AdapterToIndexMapping indexMapping = indexMappingStore.getMapping(adapter.getAdapterId(), indices[0].getName());
        try (StatisticUpdateCallback<?> updateCallback = new StatisticUpdateCallback<>(otherStats.getValue(), statisticsStore, indices[0], indexMapping, adapter)) {
            try (CloseableIterator<?> entryIt = this.query(query, (ScanCallback<Object, GeoWaveRow>) updateCallback)) {
                while (entryIt.hasNext()) {
                    entryIt.next();
                }
            }
        }
    }
}
Also used : GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) ArrayList(java.util.ArrayList) AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) Index(org.locationtech.geowave.core.store.api.Index) DataTypeStatistic(org.locationtech.geowave.core.store.api.DataTypeStatistic) Statistic(org.locationtech.geowave.core.store.api.Statistic) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic) IndexStatistic(org.locationtech.geowave.core.store.api.IndexStatistic) StatisticUpdateCallback(org.locationtech.geowave.core.store.statistics.StatisticUpdateCallback) 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)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 AdapterToIndexMapping (org.locationtech.geowave.core.store.AdapterToIndexMapping)1 InternalDataAdapter (org.locationtech.geowave.core.store.adapter.InternalDataAdapter)1 DataTypeStatistic (org.locationtech.geowave.core.store.api.DataTypeStatistic)1 FieldStatistic (org.locationtech.geowave.core.store.api.FieldStatistic)1 Index (org.locationtech.geowave.core.store.api.Index)1 IndexStatistic (org.locationtech.geowave.core.store.api.IndexStatistic)1 Statistic (org.locationtech.geowave.core.store.api.Statistic)1 StatisticValue (org.locationtech.geowave.core.store.api.StatisticValue)1 DeleteCallbackList (org.locationtech.geowave.core.store.callback.DeleteCallbackList)1 IngestCallbackList (org.locationtech.geowave.core.store.callback.IngestCallbackList)1 GeoWaveRow (org.locationtech.geowave.core.store.entities.GeoWaveRow)1 StatisticUpdateCallback (org.locationtech.geowave.core.store.statistics.StatisticUpdateCallback)1