Search in sources :

Example 1 with StatisticsCache

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();
}
Also used : Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(org.locationtech.jts.geom.Coordinate) StatisticsCache(org.locationtech.geowave.adapter.vector.plugin.transaction.StatisticsCache) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeature(org.opengis.feature.simple.SimpleFeature) BaseDataStoreTest(org.locationtech.geowave.adapter.vector.BaseDataStoreTest) Test(org.junit.Test)

Example 2 with StatisticsCache

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())));
}
Also used : CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) Index(org.locationtech.geowave.core.store.api.Index) StatisticsCache(org.locationtech.geowave.adapter.vector.plugin.transaction.StatisticsCache) SimpleFeature(org.opengis.feature.simple.SimpleFeature) BasicQueryByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass)

Example 3 with StatisticsCache

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;
}
Also used : BoundingBoxStatistic(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) BoundingBoxValue(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic.BoundingBoxValue) StatisticsCache(org.locationtech.geowave.adapter.vector.plugin.transaction.StatisticsCache) SimpleFeature(org.opengis.feature.simple.SimpleFeature) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) GeoWaveEmptyTransaction(org.locationtech.geowave.adapter.vector.plugin.transaction.GeoWaveEmptyTransaction) BoundingBox(org.opengis.geometry.BoundingBox) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Aggregations

StatisticsCache (org.locationtech.geowave.adapter.vector.plugin.transaction.StatisticsCache)3 SimpleFeature (org.opengis.feature.simple.SimpleFeature)3 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 Closeable (java.io.Closeable)1 ArrayList (java.util.ArrayList)1 DefaultTransaction (org.geotools.data.DefaultTransaction)1 Transaction (org.geotools.data.Transaction)1 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1 Test (org.junit.Test)1 BaseDataStoreTest (org.locationtech.geowave.adapter.vector.BaseDataStoreTest)1 GeoWaveEmptyTransaction (org.locationtech.geowave.adapter.vector.plugin.transaction.GeoWaveEmptyTransaction)1 BoundingBoxStatistic (org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic)1 BoundingBoxValue (org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic.BoundingBoxValue)1 CloseableIterator (org.locationtech.geowave.core.store.CloseableIterator)1 Index (org.locationtech.geowave.core.store.api.Index)1 BasicQueryByClass (org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 BoundingBox (org.opengis.geometry.BoundingBox)1 FactoryException (org.opengis.referencing.FactoryException)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1