Search in sources :

Example 1 with SpatialTemporalOptions

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

the class ExpressionQueryIT method testIndexSelection.

@Test
public void testIndexSelection() {
    final DataStore ds = dataStore.createDataStore();
    final DataTypeAdapter<SimpleFeature> adapter = createDataAdapter();
    final Index spatialIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
    final Index spatialTemporalIndex = SpatialTemporalDimensionalityTypeProvider.createIndexFromOptions(new SpatialTemporalOptions());
    final Index temporalIndex = TemporalDimensionalityTypeProvider.createIndexFromOptions(new TemporalOptions());
    ds.addType(adapter, spatialIndex, spatialTemporalIndex, temporalIndex);
    final Index altIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, ALTERNATE_GEOMETRY_FIELD));
    final Index integerIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, INTEGER_FIELD));
    final Index commentIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, COMMENT_FIELD));
    final Index idIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, ID_FIELD));
    final Index latitudeIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, LATITUDE_FIELD));
    final Index longitudeIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, LONGITUDE_FIELD));
    ds.addIndex(TYPE_NAME, altIndex, integerIndex, commentIndex, idIndex, latitudeIndex, longitudeIndex);
    final PersistentAdapterStore adapterStore = dataStore.createAdapterStore();
    final InternalAdapterStore internalAdapterStore = dataStore.createInternalAdapterStore();
    final AdapterIndexMappingStore aimStore = dataStore.createAdapterIndexMappingStore();
    final IndexStore indexStore = dataStore.createIndexStore();
    final DataStatisticsStore statsStore = dataStore.createDataStatisticsStore();
    final InternalDataAdapter<?> internalAdapter = adapterStore.getAdapter(internalAdapterStore.getAdapterId(TYPE_NAME));
    // Ingest data
    ingestData(ds);
    // ///////////////////////////////////////////////////
    // Basic BBOX on Alternate Geometry
    // ///////////////////////////////////////////////////
    Query<SimpleFeature> query = QueryBuilder.newBuilder(SimpleFeature.class).filter(ALT.bbox(-64.5, 0.5, 0.5, 64.5)).build();
    QueryConstraints queryConstraints = assertBestIndex(internalAdapter, altIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    ExplicitFilteredQuery constraints = (ExplicitFilteredQuery) queryConstraints;
    List<QueryFilter> filters = constraints.createFilters(altIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    Filter filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof BBox);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Both bbox and comment are indexed, but comment
    // should result in fewer rows queried so that
    // should be the selected index
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(ALT.bbox(-64.5, -32.5, 32.5, 64.5).and(COMMENT.startsWith("b", true))).build();
    queryConstraints = assertBestIndex(internalAdapter, commentIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    CustomQueryConstraints<?> customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    // Comment predicate was exact so only the bbox filter should need to be performed
    assertTrue(filter instanceof BBox);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        int count = 0;
        while (iterator.hasNext()) {
            final SimpleFeature feature = iterator.next();
            assertEquals("Bravo", feature.getAttribute(COMMENT_FIELD));
            count++;
        }
        // 1/4 of entries match the comment predicate, but only 3/4 of those match the bounding box
        assertEquals(Math.round(TOTAL_FEATURES / 8 * 1.5), count);
    }
    // ///////////////////////////////////////////////////
    // Both bbox and comment are indexed, but bbox should
    // result in fewer rows queried so that should be the
    // selected index
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(ALT.bbox(-64.5, 32.5, -32.5, 64.5).and(COMMENT.startsWith("b", true))).build();
    queryConstraints = assertBestIndex(internalAdapter, altIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(altIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    // bbox is not exact, so it will still be part of the filter
    assertTrue(filter instanceof And);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 16, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Latitude is the most constraining
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(LATITUDE.isGreaterThan(5).and(LATITUDE.isLessThan(10), LONGITUDE.isGreaterThanOrEqualTo(7))).build();
    queryConstraints = assertBestIndex(internalAdapter, latitudeIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(latitudeIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    // since the latitude fields are exact, only the longitude needs to be filtered later
    assertTrue(filter instanceof ComparisonOperator);
    Set<String> referencedFields = Sets.newHashSet();
    filter.addReferencedFields(referencedFields);
    assertEquals(1, referencedFields.size());
    assertTrue(referencedFields.contains(LONGITUDE_FIELD));
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(3, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Longitude is the most constraining
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(LONGITUDE.isGreaterThanOrEqualTo(5).and(LONGITUDE.isLessThan(10).or(LATITUDE.isLessThanOrEqualTo(15)))).build();
    queryConstraints = assertBestIndex(internalAdapter, longitudeIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(longitudeIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    // The second half of the expression cannot be predetermined, so both sides of the Or need to be
    // present
    assertTrue(filter instanceof Or);
    referencedFields = Sets.newHashSet();
    filter.addReferencedFields(referencedFields);
    assertEquals(2, referencedFields.size());
    assertTrue(referencedFields.contains(LATITUDE_FIELD));
    assertTrue(referencedFields.contains(LONGITUDE_FIELD));
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(11, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Longitude is an exact range
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(LONGITUDE.isLessThan(-31.5).or(LONGITUDE.isGreaterThan(31.5))).build();
    queryConstraints = assertBestIndex(internalAdapter, longitudeIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(longitudeIndex);
    // The constraints are exact, so there shouldn't be any additional filtering
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2 + 1, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Default geom only should select spatial index
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.bbox(0.5, 0.5, 10.5, 10.5)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    // BBox isn't exact, so it should still be filtered
    assertTrue(filter instanceof BBox);
    referencedFields = Sets.newHashSet();
    filter.addReferencedFields(referencedFields);
    assertEquals(1, referencedFields.size());
    assertTrue(referencedFields.contains(DEFAULT_GEOMETRY_FIELD));
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(10, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Default geom and time should select spatial-
    // temporal index
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.bbox(0.5, 0.5, 30.5, 30.5).and(TIMESTAMP.isBefore(new Date((long) (66 * ONE_DAY_MILLIS + 1))))).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialTemporalIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(spatialTemporalIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    // BBox isn't exact, and neither is timestamp in a binned temporal index
    assertTrue(filter instanceof And);
    referencedFields = Sets.newHashSet();
    filter.addReferencedFields(referencedFields);
    assertEquals(2, referencedFields.size());
    assertTrue(referencedFields.contains(DEFAULT_GEOMETRY_FIELD));
    assertTrue(referencedFields.contains(TIMESTAMP_FIELD));
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Only timestamp should use temporal index
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(TIMESTAMP.isBefore(new Date((long) (66 * ONE_DAY_MILLIS + 1)))).build();
    queryConstraints = assertBestIndex(internalAdapter, temporalIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(temporalIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    // Timestamp is not exact on temporal index because there could be ranges
    assertTrue(filter instanceof Before);
    referencedFields = Sets.newHashSet();
    filter.addReferencedFields(referencedFields);
    assertEquals(1, referencedFields.size());
    assertTrue(referencedFields.contains(TIMESTAMP_FIELD));
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(67, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Integer is more constraining, half of the ID
    // values end with 0
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(ID.endsWith("0").and(INTEGER.isBetween(10, 20))).build();
    queryConstraints = assertBestIndex(internalAdapter, integerIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(integerIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    // Integer is exact, so only the string predicate should remain
    assertTrue(filter instanceof EndsWith);
    referencedFields = Sets.newHashSet();
    filter.addReferencedFields(referencedFields);
    assertEquals(1, referencedFields.size());
    assertTrue(referencedFields.contains(ID_FIELD));
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(6, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // ID is more constraining
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(ID.endsWith("a0").and(INTEGER.isBetween(0, 40))).build();
    queryConstraints = assertBestIndex(internalAdapter, idIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof CustomQueryConstraints);
    customConstraints = (CustomQueryConstraints<?>) queryConstraints;
    filters = customConstraints.createFilters(commentIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    // ID constraint is exact, so only the integer predicate should remain
    assertTrue(filter instanceof Between);
    referencedFields = Sets.newHashSet();
    filter.addReferencedFields(referencedFields);
    assertEquals(1, referencedFields.size());
    assertTrue(referencedFields.contains(INTEGER_FIELD));
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Alternate geometry is 50% null, so it is more
    // constraining
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.bbox(-30.5, -30.5, 30.5, 30.5).and(ALT.bbox(-30.5, -30.5, 30.5, 30.5))).build();
    queryConstraints = assertBestIndex(internalAdapter, altIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(altIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    // Neither bbox is exact, so they will both be filtered
    assertTrue(filter instanceof And);
    referencedFields = Sets.newHashSet();
    filter.addReferencedFields(referencedFields);
    assertEquals(2, referencedFields.size());
    assertTrue(referencedFields.contains(DEFAULT_GEOMETRY_FIELD));
    assertTrue(referencedFields.contains(ALTERNATE_GEOMETRY_FIELD));
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(30, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Integer is more constraining
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(INTEGER.isLessThan(-60).and(LATITUDE.isLessThan(5))).build();
    queryConstraints = assertBestIndex(internalAdapter, integerIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(integerIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    // Neither bbox is exact, so they will both be filtered
    assertTrue(filter instanceof ComparisonOperator);
    referencedFields = Sets.newHashSet();
    filter.addReferencedFields(referencedFields);
    assertEquals(1, referencedFields.size());
    assertTrue(referencedFields.contains(LATITUDE_FIELD));
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(4, Iterators.size(iterator));
    }
}
Also used : Before(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.Before) ComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.ComparisonOperator) Or(org.locationtech.geowave.core.store.query.filter.expression.Or) Index(org.locationtech.geowave.core.store.api.Index) CustomQueryConstraints(org.locationtech.geowave.core.store.query.constraints.CustomQueryConstraints) QueryConstraints(org.locationtech.geowave.core.store.query.constraints.QueryConstraints) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) LineString(org.locationtech.jts.geom.LineString) SpatialTemporalOptions(org.locationtech.geowave.core.geotime.index.SpatialTemporalOptions) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) DataStore(org.locationtech.geowave.core.store.api.DataStore) ExplicitFilteredQuery(org.locationtech.geowave.core.store.query.constraints.ExplicitFilteredQuery) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) TemporalBetween(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalBetween) Between(org.locationtech.geowave.core.store.query.filter.expression.Between) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Point(org.locationtech.jts.geom.Point) Disjoint(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Disjoint) Date(java.util.Date) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) QueryFilter(org.locationtech.geowave.core.store.query.filter.QueryFilter) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) AttributeIndexOptions(org.locationtech.geowave.core.store.index.AttributeIndexOptions) QueryFilter(org.locationtech.geowave.core.store.query.filter.QueryFilter) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) BBox(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.BBox) And(org.locationtech.geowave.core.store.query.filter.expression.And) SpatialTemporalOptions(org.locationtech.geowave.core.geotime.index.SpatialTemporalOptions) TemporalOptions(org.locationtech.geowave.core.geotime.index.TemporalOptions) CustomQueryConstraints(org.locationtech.geowave.core.store.query.constraints.CustomQueryConstraints) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) EndsWith(org.locationtech.geowave.core.store.query.filter.expression.text.EndsWith) Test(org.junit.Test)

Example 2 with SpatialTemporalOptions

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

the class GeoWaveGeometryPrecisionIT method ingestData.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void ingestData(final Geometry[] geometries, @Nullable final Integer geometryPrecision) {
    dataStore = dataStorePluginOptions.createDataStore();
    final SpatialOptions spatialOptions = new SpatialOptions();
    spatialOptions.setGeometryPrecision(geometryPrecision);
    spatialIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(spatialOptions);
    final SpatialTemporalOptions spatialTemporalOptions = new SpatialTemporalOptions();
    spatialTemporalOptions.setGeometryPrecision(geometryPrecision);
    spatialTemporalIndex = SpatialTemporalDimensionalityTypeProvider.createIndexFromOptions(spatialTemporalOptions);
    final GeotoolsFeatureDataAdapter fda = SimpleIngest.createDataAdapter(featureType);
    final SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
    final List<SimpleFeature> features = new ArrayList<>();
    for (int i = 0; i < geometries.length; i++) {
        builder.set(GEOMETRY_ATTRIBUTE_NAME, geometries[i]);
        builder.set(TIME_ATTRIBUTE_NAME, new Date());
        features.add(builder.buildFeature(String.valueOf(i)));
    }
    dataStore.addType(fda, spatialIndex, spatialTemporalIndex);
    try (Writer writer = dataStore.createWriter(fda.getTypeName())) {
        for (final SimpleFeature feat : features) {
            writer.write(feat);
        }
    }
}
Also used : GeotoolsFeatureDataAdapter(org.locationtech.geowave.core.geotime.store.GeotoolsFeatureDataAdapter) ArrayList(java.util.ArrayList) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) SpatialTemporalOptions(org.locationtech.geowave.core.geotime.index.SpatialTemporalOptions) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Date(java.util.Date) Writer(org.locationtech.geowave.core.store.api.Writer) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 3 with SpatialTemporalOptions

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

the class TestUtils method testLocalIngest.

public static void testLocalIngest(final DataStorePluginOptions dataStore, final DimensionalityType dimensionalityType, final String crsCode, final String ingestFilePath, final String format, final int nthreads, final boolean supportTimeRange) throws Exception {
    // ingest a shapefile (geotools type) directly into GeoWave using the
    // ingest framework's main method and pre-defined commandline arguments
    // Ingest Formats
    final IngestFormatPluginOptions ingestFormatOptions = new IngestFormatPluginOptions();
    ingestFormatOptions.selectPlugin(format);
    // Indexes
    final String[] indexTypes = dimensionalityType.getDimensionalityArg().split(",");
    final List<IndexPluginOptions> indexOptions = new ArrayList<>(indexTypes.length);
    for (final String indexType : indexTypes) {
        final IndexPluginOptions indexOption = new IndexPluginOptions();
        indexOption.selectPlugin(indexType);
        if (crsCode != null) {
            if (indexOption.getDimensionalityOptions() instanceof SpatialOptions) {
                ((SpatialOptions) indexOption.getDimensionalityOptions()).setCrs(crsCode);
            } else if (indexOption.getDimensionalityOptions() instanceof SpatialTemporalOptions) {
                ((SpatialTemporalOptions) indexOption.getDimensionalityOptions()).setCrs(crsCode);
            }
        }
        if (indexOption.getDimensionalityOptions() instanceof TemporalOptions) {
            ((TemporalOptions) indexOption.getDimensionalityOptions()).setNoTimeRanges(!supportTimeRange);
        }
        indexOptions.add(indexOption);
    }
    final File configFile = File.createTempFile("test_stats", null);
    final ManualOperationParams params = new ManualOperationParams();
    params.getContext().put(ConfigOptions.PROPERTIES_FILE_CONTEXT, configFile);
    // Add Store
    final AddStoreCommand addStore = new AddStoreCommand();
    addStore.setParameters("test-store");
    addStore.setPluginOptions(dataStore);
    addStore.execute(params);
    final IndexStore indexStore = dataStore.createIndexStore();
    final org.locationtech.geowave.core.store.api.DataStore geowaveDataStore = dataStore.createDataStore();
    // Add indices
    final StringBuilder indexParam = new StringBuilder();
    for (int i = 0; i < indexOptions.size(); i++) {
        final String indexName = "test-index" + i;
        if (indexStore.getIndex(indexName) == null) {
            indexOptions.get(i).setName(indexName);
            geowaveDataStore.addIndex(indexOptions.get(i).createIndex(geowaveDataStore));
        }
        indexParam.append(indexName + ",");
    }
    // Create the command and execute.
    final LocalToGeoWaveCommand localIngester = new LocalToGeoWaveCommand();
    localIngester.setPluginFormats(ingestFormatOptions);
    localIngester.setParameters(ingestFilePath, "test-store", indexParam.toString());
    localIngester.setThreads(nthreads);
    localIngester.execute(params);
    verifyStats(dataStore);
}
Also used : IngestFormatPluginOptions(org.locationtech.geowave.core.ingest.operations.options.IngestFormatPluginOptions) ArrayList(java.util.ArrayList) AddStoreCommand(org.locationtech.geowave.core.store.cli.store.AddStoreCommand) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) SpatialTemporalOptions(org.locationtech.geowave.core.geotime.index.SpatialTemporalOptions) Point(org.locationtech.jts.geom.Point) ManualOperationParams(org.locationtech.geowave.core.cli.parser.ManualOperationParams) SpatialTemporalOptions(org.locationtech.geowave.core.geotime.index.SpatialTemporalOptions) TemporalOptions(org.locationtech.geowave.core.geotime.index.TemporalOptions) LocalToGeoWaveCommand(org.locationtech.geowave.core.ingest.operations.LocalToGeoWaveCommand) IndexPluginOptions(org.locationtech.geowave.core.store.index.IndexPluginOptions) File(java.io.File) IndexStore(org.locationtech.geowave.core.store.index.IndexStore)

Example 4 with SpatialTemporalOptions

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

the class FeatureDataAdapterTest method testSingleTime.

@Test
public void testSingleTime() {
    schema.getDescriptor("when").getUserData().clear();
    schema.getDescriptor("whennot").getUserData().put("time", Boolean.TRUE);
    final FeatureDataAdapter dataAdapter = new FeatureDataAdapter(schema);
    final Index spatialIndex = SpatialTemporalDimensionalityTypeProvider.createIndexFromOptions(new SpatialTemporalOptions());
    final AdapterToIndexMapping indexMapping = BaseDataStoreUtils.mapAdapterToIndex(dataAdapter.asInternalAdapter((short) -1), spatialIndex);
    final byte[] binary = dataAdapter.toBinary();
    final FeatureDataAdapter dataAdapterCopy = new FeatureDataAdapter();
    dataAdapterCopy.fromBinary(binary);
    assertEquals(dataAdapterCopy.getTypeName(), dataAdapter.getTypeName());
    assertEquals(dataAdapterCopy.getFeatureType(), dataAdapter.getFeatureType());
    assertEquals(Boolean.TRUE, dataAdapterCopy.getFeatureType().getDescriptor("whennot").getUserData().get("time"));
    assertEquals(2, indexMapping.getIndexFieldMappers().size());
    assertNotNull(indexMapping.getMapperForIndexField(TimeField.DEFAULT_FIELD_ID));
    assertEquals(1, indexMapping.getMapperForIndexField(TimeField.DEFAULT_FIELD_ID).adapterFieldCount());
    assertEquals("whennot", indexMapping.getMapperForIndexField(TimeField.DEFAULT_FIELD_ID).getAdapterFields()[0]);
    assertNotNull(indexMapping.getMapperForIndexField(SpatialField.DEFAULT_GEOMETRY_FIELD_NAME));
    assertEquals(1, indexMapping.getMapperForIndexField(SpatialField.DEFAULT_GEOMETRY_FIELD_NAME).adapterFieldCount());
    assertEquals("geometry", indexMapping.getMapperForIndexField(SpatialField.DEFAULT_GEOMETRY_FIELD_NAME).getAdapterFields()[0]);
}
Also used : AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) Index(org.locationtech.geowave.core.store.api.Index) SpatialTemporalOptions(org.locationtech.geowave.core.geotime.index.SpatialTemporalOptions) Test(org.junit.Test)

Example 5 with SpatialTemporalOptions

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

the class FeatureDataAdapterTest method testRange.

@Test
public void testRange() {
    schema.getDescriptor("when").getUserData().clear();
    schema.getDescriptor("whennot").getUserData().clear();
    schema.getDescriptor("when").getUserData().put("start", Boolean.TRUE);
    schema.getDescriptor("whennot").getUserData().put("end", Boolean.TRUE);
    final FeatureDataAdapter dataAdapter = new FeatureDataAdapter(schema);
    final Index spatialIndex = SpatialTemporalDimensionalityTypeProvider.createIndexFromOptions(new SpatialTemporalOptions());
    final AdapterToIndexMapping indexMapping = BaseDataStoreUtils.mapAdapterToIndex(dataAdapter.asInternalAdapter((short) -1), spatialIndex);
    final byte[] binary = dataAdapter.toBinary();
    final FeatureDataAdapter dataAdapterCopy = new FeatureDataAdapter();
    dataAdapterCopy.fromBinary(binary);
    assertEquals(dataAdapterCopy.getTypeName(), dataAdapter.getTypeName());
    assertEquals(dataAdapterCopy.getFeatureType(), dataAdapter.getFeatureType());
    assertEquals(Boolean.TRUE, dataAdapterCopy.getFeatureType().getDescriptor("whennot").getUserData().get("end"));
    assertEquals(Boolean.TRUE, dataAdapterCopy.getFeatureType().getDescriptor("when").getUserData().get("start"));
    assertEquals(2, indexMapping.getIndexFieldMappers().size());
    assertNotNull(indexMapping.getMapperForIndexField(TimeField.DEFAULT_FIELD_ID));
    assertEquals(2, indexMapping.getMapperForIndexField(TimeField.DEFAULT_FIELD_ID).adapterFieldCount());
    assertEquals("when", indexMapping.getMapperForIndexField(TimeField.DEFAULT_FIELD_ID).getAdapterFields()[0]);
    assertEquals("whennot", indexMapping.getMapperForIndexField(TimeField.DEFAULT_FIELD_ID).getAdapterFields()[1]);
    assertNotNull(indexMapping.getMapperForIndexField(SpatialField.DEFAULT_GEOMETRY_FIELD_NAME));
    assertEquals(1, indexMapping.getMapperForIndexField(SpatialField.DEFAULT_GEOMETRY_FIELD_NAME).adapterFieldCount());
    assertEquals("geometry", indexMapping.getMapperForIndexField(SpatialField.DEFAULT_GEOMETRY_FIELD_NAME).getAdapterFields()[0]);
}
Also used : AdapterToIndexMapping(org.locationtech.geowave.core.store.AdapterToIndexMapping) Index(org.locationtech.geowave.core.store.api.Index) SpatialTemporalOptions(org.locationtech.geowave.core.geotime.index.SpatialTemporalOptions) Test(org.junit.Test)

Aggregations

SpatialTemporalOptions (org.locationtech.geowave.core.geotime.index.SpatialTemporalOptions)13 Index (org.locationtech.geowave.core.store.api.Index)9 Test (org.junit.Test)7 SpatialOptions (org.locationtech.geowave.core.geotime.index.SpatialOptions)4 AdapterToIndexMapping (org.locationtech.geowave.core.store.AdapterToIndexMapping)4 Point (org.locationtech.jts.geom.Point)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 QueryFilter (org.locationtech.geowave.core.store.query.filter.QueryFilter)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 TemporalOptions (org.locationtech.geowave.core.geotime.index.TemporalOptions)2 DataStore (org.locationtech.geowave.core.store.api.DataStore)2 CommonIndexedPersistenceEncoding (org.locationtech.geowave.core.store.data.CommonIndexedPersistenceEncoding)2 IndexStore (org.locationtech.geowave.core.store.index.IndexStore)2 Coordinate (org.locationtech.jts.geom.Coordinate)2 File (java.io.File)1 Calendar (java.util.Calendar)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 ManualOperationParams (org.locationtech.geowave.core.cli.parser.ManualOperationParams)1 SpatialTemporalDimensionalityTypeProvider (org.locationtech.geowave.core.geotime.index.SpatialTemporalDimensionalityTypeProvider)1