Search in sources :

Example 1 with CustomNameIndex

use of org.locationtech.geowave.core.store.index.CustomNameIndex in project geowave by locationtech.

the class SpatialDimensionalityTypeProvider method createIndexFromOptions.

public static Index createIndexFromOptions(final SpatialOptions options) {
    NumericDimensionDefinition[] dimensions;
    boolean isDefaultCRS;
    String crsCode = null;
    NumericDimensionField<?>[] fields = null;
    NumericDimensionField<?>[] fields_temporal = null;
    final Integer geometryPrecision = options.getGeometryPrecision();
    if ((options.crs == null) || options.crs.isEmpty() || options.crs.equalsIgnoreCase(GeometryUtils.DEFAULT_CRS_STR)) {
        dimensions = SPATIAL_DIMENSIONS;
        fields = getSpatialFields(geometryPrecision);
        isDefaultCRS = true;
        crsCode = "EPSG:4326";
    } else {
        final CoordinateReferenceSystem crs = GeometryUtils.decodeCRS(options.crs);
        final CoordinateSystem cs = crs.getCoordinateSystem();
        isDefaultCRS = false;
        crsCode = options.crs;
        dimensions = new NumericDimensionDefinition[cs.getDimension()];
        if (options.storeTime) {
            fields_temporal = new NumericDimensionField[dimensions.length + 1];
            for (int d = 0; d < dimensions.length; d++) {
                final CoordinateSystemAxis csa = cs.getAxis(d);
                if (!isUnbounded(csa)) {
                    dimensions[d] = new CustomCRSBoundedSpatialDimension((byte) d, csa.getMinimumValue(), csa.getMaximumValue());
                    fields_temporal[d] = new CustomCRSSpatialField((CustomCRSBoundedSpatialDimension) dimensions[d], geometryPrecision, crs);
                } else {
                    dimensions[d] = new CustomCRSUnboundedSpatialDimension(DEFAULT_UNBOUNDED_CRS_INTERVAL, (byte) d);
                    fields_temporal[d] = new CustomCRSSpatialField((CustomCRSUnboundedSpatialDimension) dimensions[d], geometryPrecision, crs);
                }
            }
            fields_temporal[dimensions.length] = new TimeField(Unit.YEAR);
        } else {
            fields = new NumericDimensionField[dimensions.length];
            for (int d = 0; d < dimensions.length; d++) {
                final CoordinateSystemAxis csa = cs.getAxis(d);
                if (!isUnbounded(csa)) {
                    if (d == 0) {
                        dimensions[d] = new CustomCRSBoundedSpatialDimensionX(csa.getMinimumValue(), csa.getMaximumValue());
                        fields[d] = new CustomCRSSpatialField((CustomCRSBoundedSpatialDimensionX) dimensions[d], geometryPrecision, crs);
                    }
                    if (d == 1) {
                        dimensions[d] = new CustomCRSBoundedSpatialDimensionY(csa.getMinimumValue(), csa.getMaximumValue());
                        fields[d] = new CustomCRSSpatialField((CustomCRSBoundedSpatialDimensionY) dimensions[d], geometryPrecision, crs);
                    }
                } else {
                    if (d == 0) {
                        dimensions[d] = new CustomCRSUnboundedSpatialDimensionX(DEFAULT_UNBOUNDED_CRS_INTERVAL, (byte) d);
                        fields[d] = new CustomCRSSpatialField((CustomCRSUnboundedSpatialDimensionX) dimensions[d], geometryPrecision, crs);
                    }
                    if (d == 1) {
                        dimensions[d] = new CustomCRSUnboundedSpatialDimensionY(DEFAULT_UNBOUNDED_CRS_INTERVAL, (byte) d);
                        fields[d] = new CustomCRSSpatialField((CustomCRSUnboundedSpatialDimensionY) dimensions[d], geometryPrecision, crs);
                    }
                }
            }
        }
    }
    BasicIndexModel indexModel = null;
    if (isDefaultCRS) {
        indexModel = new BasicIndexModel(options.storeTime ? getSpatialTemporalFields(geometryPrecision) : getSpatialFields(geometryPrecision));
    } else {
        indexModel = new CustomCrsIndexModel(options.storeTime ? fields_temporal : fields, crsCode);
    }
    return new CustomNameIndex(XZHierarchicalIndexFactory.createFullIncrementalTieredStrategy(dimensions, new int[] { // flexible enough to handle n-dimensions
    LONGITUDE_BITS, LATITUDE_BITS }, SFCType.HILBERT), indexModel, // TODO append CRS code to ID if its overridden
    isDefaultCRS ? (options.storeTime ? DEFAULT_SPATIAL_ID + "_TIME" : DEFAULT_SPATIAL_ID) : (options.storeTime ? DEFAULT_SPATIAL_ID + "_TIME" : DEFAULT_SPATIAL_ID) + "_" + crsCode.substring(crsCode.indexOf(":") + 1));
}
Also used : NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) NumericDimensionDefinition(org.locationtech.geowave.core.index.dimension.NumericDimensionDefinition) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis) CustomCRSSpatialField(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSSpatialField) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) CustomCrsIndexModel(org.locationtech.geowave.core.geotime.store.dimension.CustomCrsIndexModel) TimeField(org.locationtech.geowave.core.geotime.store.dimension.TimeField) CustomCRSBoundedSpatialDimension(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimension) CustomCRSBoundedSpatialDimensionX(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimensionX) CustomCRSBoundedSpatialDimensionY(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimensionY) BasicIndexModel(org.locationtech.geowave.core.store.index.BasicIndexModel) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) CustomCRSUnboundedSpatialDimensionY(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSUnboundedSpatialDimensionY) CustomCRSUnboundedSpatialDimension(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSUnboundedSpatialDimension) CustomCRSUnboundedSpatialDimensionX(org.locationtech.geowave.core.geotime.store.dimension.CustomCRSUnboundedSpatialDimensionX)

Example 2 with CustomNameIndex

use of org.locationtech.geowave.core.store.index.CustomNameIndex in project geowave by locationtech.

the class TemporalDimensionalityTypeProvider method createIndexFromOptions.

public static Index createIndexFromOptions(final TemporalOptions options) {
    if (!options.noTimeRanges) {
        final NumericDimensionDefinition[] dimensions = TEMPORAL_DIMENSIONS;
        final NumericDimensionField<?>[] fields = TEMPORAL_FIELDS;
        dimensions[dimensions.length - 1] = new TimeDefinition(options.periodicity);
        fields[dimensions.length - 1] = new TimeField(options.periodicity);
        final BasicIndexModel indexModel = new BasicIndexModel(fields);
        final String combinedArrayID = DEFAULT_TEMPORAL_ID_STR + "_" + options.periodicity;
        return new CustomNameIndex(XZHierarchicalIndexFactory.createFullIncrementalTieredStrategy(dimensions, new int[] { 63 }, SFCType.HILBERT, options.maxDuplicates), indexModel, combinedArrayID);
    }
    final BasicIndexModel indexModel = new BasicIndexModel(new NumericDimensionField[] { new BasicNumericDimensionField<>(TimeField.DEFAULT_FIELD_ID, Long.class) });
    return new CustomNameIndex(new SimpleTimeIndexStrategy(), indexModel, DEFAULT_TEMPORAL_ID_STR);
}
Also used : BasicNumericDimensionField(org.locationtech.geowave.core.store.dimension.BasicNumericDimensionField) NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) TimeField(org.locationtech.geowave.core.geotime.store.dimension.TimeField) NumericDimensionDefinition(org.locationtech.geowave.core.index.dimension.NumericDimensionDefinition) BasicIndexModel(org.locationtech.geowave.core.store.index.BasicIndexModel) TimeDefinition(org.locationtech.geowave.core.geotime.index.dimension.TimeDefinition) SimpleTimeDefinition(org.locationtech.geowave.core.geotime.index.dimension.SimpleTimeDefinition) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) SimpleTimeIndexStrategy(org.locationtech.geowave.core.geotime.index.dimension.SimpleTimeIndexStrategy)

Example 3 with CustomNameIndex

use of org.locationtech.geowave.core.store.index.CustomNameIndex in project geowave by locationtech.

the class RocksDBLockfileTest method testLockfile.

private void testLockfile(final int numThreads, final boolean secondaryIndexing) {
    final RocksDBOptions options = new RocksDBOptions();
    options.setDirectory(DEFAULT_DB_DIRECTORY);
    options.getStoreOptions().setSecondaryIndexing(secondaryIndexing);
    final DataStore store = new RocksDBStoreFactoryFamily().getDataStoreFactory().createStore(options);
    store.deleteAll();
    store.addType(BasicDataTypeAdapter.newAdapter(POI_TYPE_NAME, POI.class, "name"));
    Index index = AttributeDimensionalityTypeProvider.createIndexFromOptions(store, new AttributeIndexOptions(POI_TYPE_NAME, "latitude"));
    index = new CustomNameIndex(new CompoundIndexStrategy(new RoundRobinKeyIndexStrategy(32), index.getIndexStrategy()), index.getIndexModel(), index.getName() + "_" + PartitionStrategy.ROUND_ROBIN.name() + "_" + 32);
    final Index latAttributeIndex = new IndexWrapper(index);
    store.addIndex(POI_TYPE_NAME, latAttributeIndex);
    final DataStore store2 = new RocksDBStoreFactoryFamily().getDataStoreFactory().createStore(options);
    IntStream.range(0, numThreads).mapToObj(i -> CompletableFuture.runAsync(() -> {
        double offset = i * numThreads;
        try (Writer<POI> w = store.createWriter(POI_TYPE_NAME)) {
            w.write(new POI("name" + offset, offset, offset));
        }
        try (CloseableIterator<POI> poiIt = store2.query(QueryBuilder.newBuilder(POI.class).build())) {
            if (numThreads == 1) {
                Assert.assertEquals(1, Iterators.size(poiIt));
            } else {
                Assert.assertTrue(Iterators.size(poiIt) >= 1);
            }
        }
        offset++;
        try (Writer<POI> w = store2.createWriter(POI_TYPE_NAME)) {
            w.write(new POI("name" + offset, offset, offset));
        }
        try (CloseableIterator<POI> poiIt = store.query(QueryBuilder.newBuilder(POI.class).build())) {
            if (numThreads == 1) {
                Assert.assertEquals(2, Iterators.size(poiIt));
            } else {
                Assert.assertTrue(Iterators.size(poiIt) >= 2);
            }
        }
        offset++;
        try (Writer<POI> w = store2.createWriter(POI_TYPE_NAME)) {
            w.write(new POI("name" + offset, offset, offset));
            try (CloseableIterator<POI> poiIt = store.query(QueryBuilder.newBuilder(POI.class).build())) {
                if (numThreads == 1) {
                    Assert.assertEquals(2, Iterators.size(poiIt));
                } else {
                    Assert.assertTrue(Iterators.size(poiIt) >= 2);
                }
            }
            w.flush();
            try (CloseableIterator<POI> poiIt = store.query(QueryBuilder.newBuilder(POI.class).build())) {
                if (numThreads == 1) {
                    Assert.assertEquals(3, Iterators.size(poiIt));
                } else {
                    Assert.assertTrue(Iterators.size(poiIt) >= 3);
                }
            }
        }
        try (CloseableIterator<POI> poiIt = store2.query(QueryBuilder.newBuilder(POI.class).build())) {
            if (numThreads == 1) {
                Assert.assertEquals(3, Iterators.size(poiIt));
            } else {
                Assert.assertTrue(Iterators.size(poiIt) >= 3);
            }
        }
    }));
    store.deleteAll();
}
Also used : CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) AttributeIndexOptions(org.locationtech.geowave.core.store.index.AttributeIndexOptions) CompoundIndexStrategy(org.locationtech.geowave.core.index.CompoundIndexStrategy) DataStore(org.locationtech.geowave.core.store.api.DataStore) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) Index(org.locationtech.geowave.core.store.api.Index) RoundRobinKeyIndexStrategy(org.locationtech.geowave.core.index.simple.RoundRobinKeyIndexStrategy) RocksDBOptions(org.locationtech.geowave.datastore.rocksdb.config.RocksDBOptions) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) Writer(org.locationtech.geowave.core.store.api.Writer)

Example 4 with CustomNameIndex

use of org.locationtech.geowave.core.store.index.CustomNameIndex in project geowave by locationtech.

the class GeoWaveAnalyticJobRunner method checkIndex.

protected String checkIndex(final PropertyManagement runTimeProperties, final ParameterEnum indexIdEnum, final String defaultIdxName) throws Exception {
    final String indexName = runTimeProperties.getPropertyAsString(indexIdEnum, defaultIdxName);
    final IndexStore indexStore = getIndexStore(runTimeProperties);
    final DataStore dataStore = getDataStore(runTimeProperties);
    Index index = indexStore.getIndex(indexName);
    if (index == null) {
        final Index defaultSpatialIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
        index = new CustomNameIndex(defaultSpatialIndex.getIndexStrategy(), defaultSpatialIndex.getIndexModel(), indexName);
        dataStore.addIndex(index);
    }
    return indexName;
}
Also used : DataStore(org.locationtech.geowave.core.store.api.DataStore) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) Index(org.locationtech.geowave.core.store.api.Index) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) JobContextIndexStore(org.locationtech.geowave.mapreduce.JobContextIndexStore) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex)

Example 5 with CustomNameIndex

use of org.locationtech.geowave.core.store.index.CustomNameIndex in project geowave by locationtech.

the class BasicQueryByClassTest method testIntersectCasesWithPersistence.

@Test
public void testIntersectCasesWithPersistence() {
    final Index index = new CustomNameIndex(new ExampleNumericIndexStrategy(), new BasicIndexModel(new NumericDimensionField[] { new ExampleDimensionOne(), new ExampleDimensionTwo() }), "22");
    final List<MultiDimensionalNumericData> expectedResults = new ArrayList<>();
    expectedResults.add(new BasicNumericDataset(new NumericData[] { new ConstrainedIndexValue(0.3, 0.5), new ConstrainedIndexValue(0.1, 0.7) }));
    final ConstraintSet cs1 = new ConstraintSet();
    cs1.addConstraint(ExampleDimensionOne.class, new ConstraintData(new ConstrainedIndexValue(0.3, 0.5), true));
    cs1.addConstraint(ExampleDimensionTwo.class, new ConstraintData(new ConstrainedIndexValue(0.4, 0.7), true));
    final ConstraintSet cs2a = new ConstraintSet();
    cs2a.addConstraint(ExampleDimensionTwo.class, new ConstraintData(new ConstrainedIndexValue(0.1, 0.2), true));
    final ConstraintsByClass constraints = new ConstraintsByClass(Arrays.asList(cs2a)).merge(Collections.singletonList(cs1));
    assertEquals(expectedResults, constraints.getIndexConstraints(new IndexImpl(new ExampleNumericIndexStrategy(), null)));
    final byte[] image = new BasicQueryByClass(constraints).toBinary();
    final BasicQueryByClass query = new BasicQueryByClass();
    query.fromBinary(image);
    assertEquals(expectedResults, query.getIndexConstraints(index));
}
Also used : NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) ConstraintData(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) ArrayList(java.util.ArrayList) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) Index(org.locationtech.geowave.core.store.api.Index) ConstraintSet(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet) CustomNameIndex(org.locationtech.geowave.core.store.index.CustomNameIndex) ConstraintsByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass) IndexImpl(org.locationtech.geowave.core.store.index.IndexImpl) BasicIndexModel(org.locationtech.geowave.core.store.index.BasicIndexModel) BasicQueryByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass) Test(org.junit.Test)

Aggregations

CustomNameIndex (org.locationtech.geowave.core.store.index.CustomNameIndex)8 NumericDimensionField (org.locationtech.geowave.core.store.dimension.NumericDimensionField)6 BasicIndexModel (org.locationtech.geowave.core.store.index.BasicIndexModel)6 Index (org.locationtech.geowave.core.store.api.Index)5 TimeField (org.locationtech.geowave.core.geotime.store.dimension.TimeField)3 NumericDimensionDefinition (org.locationtech.geowave.core.index.dimension.NumericDimensionDefinition)3 DataStore (org.locationtech.geowave.core.store.api.DataStore)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 TimeDefinition (org.locationtech.geowave.core.geotime.index.dimension.TimeDefinition)2 CustomCRSBoundedSpatialDimensionX (org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimensionX)2 CustomCRSBoundedSpatialDimensionY (org.locationtech.geowave.core.geotime.store.dimension.CustomCRSBoundedSpatialDimensionY)2 CustomCRSSpatialField (org.locationtech.geowave.core.geotime.store.dimension.CustomCRSSpatialField)2 CustomCRSUnboundedSpatialDimensionX (org.locationtech.geowave.core.geotime.store.dimension.CustomCRSUnboundedSpatialDimensionX)2 CustomCRSUnboundedSpatialDimensionY (org.locationtech.geowave.core.geotime.store.dimension.CustomCRSUnboundedSpatialDimensionY)2 CustomCrsIndexModel (org.locationtech.geowave.core.geotime.store.dimension.CustomCrsIndexModel)2 BasicNumericDataset (org.locationtech.geowave.core.index.numeric.BasicNumericDataset)2 MultiDimensionalNumericData (org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData)2 NumericData (org.locationtech.geowave.core.index.numeric.NumericData)2 BasicNumericDimensionField (org.locationtech.geowave.core.store.dimension.BasicNumericDimensionField)2