use of org.locationtech.geowave.adapter.vector.plugin.transaction.StatisticsCache in project geowave by locationtech.
the class WFSTransactionTest method testInsertIsolation.
@Test
public void testInsertIsolation() throws IOException, CQLException {
final Transaction transaction1 = new DefaultTransaction();
final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1);
assertFalse(writer.hasNext());
final SimpleFeature newFeature = writer.next();
newFeature.setAttribute("pop", Long.valueOf(100));
newFeature.setAttribute("pid", UUID.randomUUID().toString());
newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25)));
writer.write();
writer.close();
FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, transaction1);
assertTrue(reader.hasNext());
final SimpleFeature priorFeature = reader.next();
assertEquals(newFeature.getAttribute("pid"), priorFeature.getAttribute("pid"));
reader.close();
// uncommitted at this point, so this next transaction should not see
// it.
final Transaction transaction2 = new DefaultTransaction();
reader = dataStore.getFeatureReader(query, transaction2);
assertFalse(reader.hasNext());
reader.close();
transaction1.commit();
reader = dataStore.getFeatureReader(query, transaction1);
assertTrue(reader.hasNext());
reader.next();
assertFalse(reader.hasNext());
reader.close();
transaction1.close();
// since this implementation does not support serializable, transaction2
// can see the changes even though
// it started after transaction1 and before the commit.
reader = dataStore.getFeatureReader(query, transaction2);
assertTrue(reader.hasNext());
reader.next();
assertFalse(reader.hasNext());
reader.close();
transaction2.commit();
transaction2.close();
// stats check
final Transaction transaction3 = new DefaultTransaction();
reader = ((GeoWaveFeatureSource) ((GeoWaveGTDataStore) dataStore).getFeatureSource("geostuff", transaction3)).getReaderInternal(query);
final StatisticsCache transStats = ((GeoWaveFeatureReader) reader).getTransaction().getDataStatistics();
assertNotNull(transStats.getFieldStatistic(NumericRangeStatistic.STATS_TYPE, "pop"));
transaction3.close();
}
use of org.locationtech.geowave.adapter.vector.plugin.transaction.StatisticsCache in project geowave by locationtech.
the class GeoWaveFeatureReader method issueQuery.
public CloseableIterator<SimpleFeature> issueQuery(final Geometry jtsBounds, final TemporalConstraintsSet timeBounds, final QueryIssuer issuer) {
final List<CloseableIterator<SimpleFeature>> results = new ArrayList<>();
boolean spatialOnly = false;
if (this.query.getHints().containsKey(SubsampleProcess.SUBSAMPLE_ENABLED) && (Boolean) this.query.getHints().get(SubsampleProcess.SUBSAMPLE_ENABLED)) {
spatialOnly = true;
}
if (!spatialOnly && getGeoWaveFilter() != null) {
results.add(issuer.query(null, null, spatialOnly));
} else {
final BasicQueryByClass query = getQuery(jtsBounds, timeBounds);
final StatisticsCache statsCache = getComponents().getGTstore().getIndexQueryStrategy().requiresStats() ? transaction.getDataStatistics() : null;
try (CloseableIterator<Index> indexIt = getComponents().getIndices(statsCache, query, spatialOnly)) {
while (indexIt.hasNext()) {
final Index index = indexIt.next();
final CloseableIterator<SimpleFeature> it = issuer.query(index, query, spatialOnly);
if (it != null) {
results.add(it);
}
}
}
}
if (results.isEmpty()) {
return getNoData();
}
return interweaveTransaction(issuer.getLimit(), issuer.getFilter(), new CloseableIteratorWrapper<>(new Closeable() {
@Override
public void close() throws IOException {
for (final CloseableIterator<SimpleFeature> result : results) {
result.close();
}
}
}, Iterators.concat(results.iterator())));
}
use of org.locationtech.geowave.adapter.vector.plugin.transaction.StatisticsCache in project geowave by locationtech.
the class GeoWaveFeatureSource method getBoundsInternal.
@Override
protected ReferencedEnvelope getBoundsInternal(final Query query) throws IOException {
double minx = -90.0, maxx = 90.0, miny = -180.0, maxy = 180.0;
BoundingBoxValue bboxStats = null;
if (query.getFilter().equals(Filter.INCLUDE)) {
final StatisticsCache statsCache = new GeoWaveEmptyTransaction(components).getDataStatistics();
bboxStats = statsCache.getFieldStatistic(BoundingBoxStatistic.STATS_TYPE, getFeatureType().getGeometryDescriptor().getLocalName());
}
CoordinateReferenceSystem bboxCRS = DefaultGeographicCRS.WGS84;
if (bboxStats != null) {
minx = bboxStats.getMinX();
maxx = bboxStats.getMaxX();
miny = bboxStats.getMinY();
maxy = bboxStats.getMaxY();
BoundingBoxStatistic statistic = (BoundingBoxStatistic) bboxStats.getStatistic();
if (statistic.getDestinationCrs() != null) {
bboxCRS = statistic.getDestinationCrs();
} else {
bboxCRS = components.getAdapter().getFeatureType().getCoordinateReferenceSystem();
}
} else {
final FeatureReader<SimpleFeatureType, SimpleFeature> reader = new GeoWaveFeatureReader(query, new GeoWaveEmptyTransaction(components), components);
if (reader.hasNext()) {
bboxCRS = components.getCRS();
BoundingBox featureBounds = reader.next().getBounds();
minx = featureBounds.getMinX();
maxx = featureBounds.getMaxX();
miny = featureBounds.getMinY();
maxy = featureBounds.getMaxY();
while (reader.hasNext()) {
featureBounds = reader.next().getBounds();
minx = Math.min(featureBounds.getMinX(), minx);
maxx = Math.max(featureBounds.getMaxX(), maxx);
miny = Math.min(featureBounds.getMinY(), miny);
maxy = Math.max(featureBounds.getMaxY(), maxy);
}
}
reader.close();
}
ReferencedEnvelope retVal = new ReferencedEnvelope(minx, maxx, miny, maxy, bboxCRS);
if (!bboxCRS.equals(components.getCRS())) {
try {
retVal = retVal.transform(components.getCRS(), true);
} catch (FactoryException | TransformException e) {
LOGGER.warn("Unable to transform bounding box for feature source.");
}
}
return retVal;
}
Aggregations