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();
}
}
}
}
}
Aggregations