Search in sources :

Example 1 with SpatialTemporalIndexBuilder

use of org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder in project geowave by locationtech.

the class GeoWaveCustomIndexIT method testQueries.

private void testQueries(boolean spatialTemporal) {
    final DataStore dataStore = dataStoreOptions.createDataStore();
    final VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder();
    final Calendar cal = Calendar.getInstance();
    cal.set(1996, Calendar.JUNE, 15, 1, 1, 1);
    final Date startQueryTime = cal.getTime();
    cal.set(1996, Calendar.JUNE, 16, 1, 1, 1);
    Assert.assertEquals(513L, (long) dataStore.aggregateStatistics(StatisticQueryBuilder.newBuilder(CountStatistic.STATS_TYPE).build()).getValue());
    final Date endQueryTime = cal.getTime();
    if (spatialTemporal) {
        // if spatial/temporal indexing exists explicitly set the appropriate one
        bldr.indexName(new SpatialIndexBuilder().createIndex().getName());
    }
    try (CloseableIterator<SimpleFeature> it = dataStore.query(bldr.constraints(bldr.constraintsFactory().spatialTemporalConstraints().spatialConstraints(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(0, 2, 0, 2))).build()).build())) {
        Assert.assertEquals(27, Iterators.size(it));
    }
    if (spatialTemporal) {
        // if spatial/temporal indexing exists explicitly set the appropriate one
        bldr.indexName(new SpatialTemporalIndexBuilder().createIndex().getName());
    }
    try (CloseableIterator<SimpleFeature> it = dataStore.query(bldr.constraints(bldr.constraintsFactory().spatialTemporalConstraints().spatialConstraints(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(0, 2, 0, 2))).addTimeRange(startQueryTime, endQueryTime).build()).build())) {
        Assert.assertEquals(9, Iterators.size(it));
    }
    try (CloseableIterator<SimpleFeature> it = dataStore.query(bldr.constraints(bldr.constraintsFactory().customConstraints(new TestEnumConstraints(TestEnum.A))).indexName(TEST_ENUM_INDEX_NAME).build())) {
        Assert.assertEquals(513 / 2, Iterators.size(it));
    }
    try (CloseableIterator<SimpleFeature> it = dataStore.query(bldr.constraints(bldr.constraintsFactory().customConstraints(new TestEnumConstraints(TestEnum.B))).indexName(TEST_ENUM_INDEX_NAME).build())) {
        Assert.assertEquals(513 / 3, Iterators.size(it));
    }
    try (CloseableIterator<SimpleFeature> it = dataStore.query(bldr.constraints(bldr.constraintsFactory().customConstraints(new TestEnumConstraints(TestEnum.C))).indexName(TEST_ENUM_INDEX_NAME).build())) {
        Assert.assertEquals(513 / 5, Iterators.size(it));
    }
}
Also used : VectorQueryBuilder(org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder) SpatialIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder) DataStore(org.locationtech.geowave.core.store.api.DataStore) Calendar(java.util.Calendar) SpatialTemporalIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder) Envelope(org.locationtech.jts.geom.Envelope) Date(java.util.Date) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 2 with SpatialTemporalIndexBuilder

use of org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder in project geowave by locationtech.

the class GeoWaveFeatureReaderTest method setup.

@Before
public void setup() throws SchemaException, CQLException, Exception {
    dataStore = createDataStore();
    type = DataUtilities.createType("GeoWaveFeatureReaderTest", "geometry:Geometry:srid=4326,start:Date,end:Date,pop:java.lang.Long,pid:String");
    ((GeoWaveGTDataStore) dataStore).getDataStore().addIndex(new SpatialIndexBuilder().createIndex());
    ((GeoWaveGTDataStore) dataStore).getDataStore().addIndex(new SpatialTemporalIndexBuilder().createIndex());
    dataStore.createSchema(type);
    ((GeoWaveGTDataStore) dataStore).getDataStore().addIndex(type.getTypeName(), AttributeDimensionalityTypeProvider.createIndexFromOptions(((GeoWaveGTDataStore) dataStore).getDataStore(), new AttributeIndexOptions(type.getTypeName(), "pop")));
    stime = DateUtilities.parseISO("2005-05-15T20:32:56Z");
    mtime = DateUtilities.parseISO("2005-05-20T20:32:56Z");
    etime = DateUtilities.parseISO("2005-05-25T20:32:56Z");
    final Transaction transaction1 = new DefaultTransaction();
    final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1);
    assertFalse(writer.hasNext());
    SimpleFeature newFeature = writer.next();
    newFeature.setAttribute("pop", Long.valueOf(100));
    newFeature.setAttribute("pid", "a" + UUID.randomUUID().toString());
    newFeature.setAttribute("start", stime);
    newFeature.setAttribute("end", mtime);
    newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25)));
    fids.add(newFeature.getID());
    pids.add(newFeature.getAttribute("pid").toString());
    writer.write();
    newFeature = writer.next();
    newFeature.setAttribute("pop", Long.valueOf(101));
    newFeature.setAttribute("pid", "b" + UUID.randomUUID().toString());
    newFeature.setAttribute("start", mtime);
    newFeature.setAttribute("end", etime);
    newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(28.25, 41.25)));
    fids.add(newFeature.getID());
    pids.add(newFeature.getAttribute("pid").toString());
    writer.write();
    writer.close();
    transaction1.commit();
    transaction1.close();
    query = new Query("GeoWaveFeatureReaderTest", ECQL.toFilter("IN ('" + fids.get(0) + "')"), new String[] { "geometry", "pid" });
}
Also used : AttributeIndexOptions(org.locationtech.geowave.core.store.index.AttributeIndexOptions) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Query(org.geotools.data.Query) Coordinate(org.locationtech.jts.geom.Coordinate) SpatialIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder) SpatialTemporalIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Before(org.junit.Before)

Example 3 with SpatialTemporalIndexBuilder

use of org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder in project geowave by locationtech.

the class ChooseBestMatchIndexQueryStrategyTest method testChooseSpatialTemporalWithStats.

@Test
public void testChooseSpatialTemporalWithStats() {
    final Index temporalindex = new SpatialTemporalIndexBuilder().createIndex();
    final Index spatialIndex = new SpatialIndexBuilder().createIndex();
    final RowRangeHistogramStatistic rangeTempStats = new RowRangeHistogramStatistic(temporalindex.getName());
    rangeTempStats.setBinningStrategy(new CompositeBinningStrategy(new DataTypeBinningStrategy(), new PartitionBinningStrategy()));
    rangeTempStats.setInternal();
    final RowRangeHistogramStatistic rangeStats = new RowRangeHistogramStatistic(spatialIndex.getName());
    rangeStats.setBinningStrategy(new CompositeBinningStrategy(new DataTypeBinningStrategy(), new PartitionBinningStrategy()));
    rangeStats.setInternal();
    final Map<StatisticId<?>, Map<ByteArray, StatisticValue<?>>> statsMap = new HashMap<>();
    final ChooseBestMatchIndexQueryStrategy strategy = new ChooseBestMatchIndexQueryStrategy();
    final ConstraintSet cs1 = new ConstraintSet();
    cs1.addConstraint(LatitudeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0.3, 0.5), true));
    cs1.addConstraint(LongitudeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0.4, 0.7), true));
    final ConstraintSet cs2a = new ConstraintSet();
    cs2a.addConstraint(TimeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0.1, 0.2), true));
    final ConstraintsByClass constraints = new ConstraintsByClass(Arrays.asList(cs2a)).merge(Collections.singletonList(cs1));
    final BasicQueryByClass query = new BasicQueryByClass(constraints);
    final NumericIndexStrategy temporalIndexStrategy = new SpatialTemporalIndexBuilder().createIndex().getIndexStrategy();
    final Random r = new Random(SEED);
    for (int i = 0; i < ROWS; i++) {
        final double x = r.nextDouble();
        final double y = r.nextDouble();
        final double t = r.nextDouble();
        final InsertionIds id = temporalIndexStrategy.getInsertionIds(new BasicNumericDataset(new NumericData[] { new NumericValue(x), new NumericValue(y), new NumericValue(t) }));
        for (final SinglePartitionInsertionIds range : id.getPartitionKeys()) {
            Map<ByteArray, StatisticValue<?>> binValues = statsMap.get(rangeTempStats.getId());
            if (binValues == null) {
                binValues = Maps.newHashMap();
                statsMap.put(rangeTempStats.getId(), binValues);
            }
            final ByteArray bin = CompositeBinningStrategy.getBin(DataTypeBinningStrategy.getBin((String) null), PartitionBinningStrategy.getBin(range.getPartitionKey()));
            RowRangeHistogramValue value = (RowRangeHistogramValue) binValues.get(bin);
            if (value == null) {
                value = rangeTempStats.createEmpty();
                value.setBin(bin);
                binValues.put(bin, value);
            }
            ((StatisticsIngestCallback) value).entryIngested(null, null, new GeoWaveRowImpl(new GeoWaveKeyImpl(new byte[] { 1 }, (short) 1, range.getPartitionKey(), range.getSortKeys().get(0), 0), new GeoWaveValue[] {}));
        }
    }
    final Index index = new SpatialIndexBuilder().createIndex();
    final NumericIndexStrategy indexStrategy = index.getIndexStrategy();
    for (int i = 0; i < ROWS; i++) {
        final double x = r.nextDouble();
        final double y = r.nextDouble();
        final double t = r.nextDouble();
        final InsertionIds id = indexStrategy.getInsertionIds(new BasicNumericDataset(new NumericData[] { new NumericValue(x), new NumericValue(y), new NumericValue(t) }));
        for (final SinglePartitionInsertionIds range : id.getPartitionKeys()) {
            Map<ByteArray, StatisticValue<?>> binValues = statsMap.get(rangeStats.getId());
            if (binValues == null) {
                binValues = Maps.newHashMap();
                statsMap.put(rangeStats.getId(), binValues);
            }
            final ByteArray bin = CompositeBinningStrategy.getBin(DataTypeBinningStrategy.getBin((String) null), PartitionBinningStrategy.getBin(range.getPartitionKey()));
            RowRangeHistogramValue value = (RowRangeHistogramValue) binValues.get(bin);
            if (value == null) {
                value = rangeStats.createEmpty();
                value.setBin(bin);
                binValues.put(bin, value);
            }
            ((StatisticsIngestCallback) value).entryIngested(null, null, new GeoWaveRowImpl(new GeoWaveKeyImpl(new byte[] { 1 }, (short) 1, range.getPartitionKey(), range.getSortKeys().get(0), 0), new GeoWaveValue[] {}));
        }
    }
    final Iterator<Index> it = getIndices(new TestDataStatisticsStore(Lists.newArrayList(rangeStats, rangeTempStats), statsMap), query, strategy);
    assertTrue(it.hasNext());
    assertEquals(temporalindex.getName(), it.next().getName());
    assertFalse(it.hasNext());
}
Also used : SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) HashMap(java.util.HashMap) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) StatisticId(org.locationtech.geowave.core.store.statistics.StatisticId) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) NullIndex(org.locationtech.geowave.core.store.index.NullIndex) Index(org.locationtech.geowave.core.store.api.Index) GeoWaveValue(org.locationtech.geowave.core.store.entities.GeoWaveValue) ConstraintsByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass) RowRangeHistogramStatistic(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic) Random(java.util.Random) SpatialIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) ByteArray(org.locationtech.geowave.core.index.ByteArray) StatisticsIngestCallback(org.locationtech.geowave.core.store.statistics.StatisticsIngestCallback) ConstraintData(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData) RowRangeHistogramValue(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic.RowRangeHistogramValue) DataTypeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.DataTypeBinningStrategy) ConstraintSet(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet) GeoWaveRowImpl(org.locationtech.geowave.core.store.entities.GeoWaveRowImpl) CompositeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.CompositeBinningStrategy) GeoWaveKeyImpl(org.locationtech.geowave.core.store.entities.GeoWaveKeyImpl) SpatialTemporalIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder) PartitionBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.PartitionBinningStrategy) NumericValue(org.locationtech.geowave.core.index.numeric.NumericValue) Map(java.util.Map) HashMap(java.util.HashMap) BasicQueryByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass) NumericIndexStrategy(org.locationtech.geowave.core.index.NumericIndexStrategy) Test(org.junit.Test)

Example 4 with SpatialTemporalIndexBuilder

use of org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder in project geowave by locationtech.

the class IngestRunnerTest method createIndices.

private void createIndices(final OperationParams params, final String storeName) {
    final DataStore dataStore = getStorePluginOptions(params, storeName).createDataStore();
    // Create the spatial index
    final SpatialIndexBuilder builder = new SpatialIndexBuilder();
    builder.setName("spatialindex");
    builder.setNumPartitions(1);
    builder.setIncludeTimeInCommonIndexModel(false);
    dataStore.addIndex(builder.createIndex());
    // Create the spatial temporal index
    final SpatialTemporalIndexBuilder st_builder = new SpatialTemporalIndexBuilder();
    st_builder.setName("spatempindex");
    st_builder.setBias(Bias.BALANCED);
    st_builder.setMaxDuplicates(-1);
    st_builder.setNumPartitions(1);
    st_builder.setPartitionStrategy(PartitionStrategy.ROUND_ROBIN);
    st_builder.setPeriodicity(Unit.DAY);
    dataStore.addIndex(st_builder.createIndex());
}
Also used : SpatialIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder) DataStore(org.locationtech.geowave.core.store.api.DataStore) SpatialTemporalIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder)

Example 5 with SpatialTemporalIndexBuilder

use of org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder in project geowave by locationtech.

the class IngestRunnerTest method createIndices.

private void createIndices(final OperationParams params, final String storeName) {
    DataStore dataStore = getStorePluginOptions(params, storeName).createDataStore();
    // Create the spatial index
    final SpatialIndexBuilder builder = new SpatialIndexBuilder();
    builder.setName("spatialindex");
    builder.setNumPartitions(1);
    builder.setIncludeTimeInCommonIndexModel(false);
    dataStore.addIndex(builder.createIndex());
    // Create the spatial temporal index
    final SpatialTemporalIndexBuilder st_builder = new SpatialTemporalIndexBuilder();
    st_builder.setName("spatempindex");
    st_builder.setBias(Bias.BALANCED);
    st_builder.setMaxDuplicates(-1);
    st_builder.setNumPartitions(1);
    st_builder.setPartitionStrategy(PartitionStrategy.ROUND_ROBIN);
    st_builder.setPeriodicity(Unit.DAY);
    dataStore.addIndex(st_builder.createIndex());
}
Also used : SpatialIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder) DataStore(org.locationtech.geowave.core.store.api.DataStore) SpatialTemporalIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder)

Aggregations

SpatialIndexBuilder (org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder)8 SpatialTemporalIndexBuilder (org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder)8 DataStore (org.locationtech.geowave.core.store.api.DataStore)6 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)3 Date (java.util.Date)2 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)2 Test (org.junit.Test)2 VectorQueryBuilder (org.locationtech.geowave.core.geotime.store.query.api.VectorQueryBuilder)2 Index (org.locationtech.geowave.core.store.api.Index)2 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 DefaultTransaction (org.geotools.data.DefaultTransaction)1 Query (org.geotools.data.Query)1 Transaction (org.geotools.data.Transaction)1 AttributeTypeBuilder (org.geotools.feature.AttributeTypeBuilder)1 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)1 Before (org.junit.Before)1