use of org.locationtech.geowave.core.store.index.BasicIndexModel 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));
}
use of org.locationtech.geowave.core.store.index.BasicIndexModel 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);
}
use of org.locationtech.geowave.core.store.index.BasicIndexModel 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));
}
use of org.locationtech.geowave.core.store.index.BasicIndexModel in project geowave by locationtech.
the class BasicQueryByClassTest method testDisjointCasesWithPersistence.
@Test
public void testDisjointCasesWithPersistence() {
final List<MultiDimensionalNumericData> expectedResults = new ArrayList<>();
expectedResults.add(new BasicNumericDataset(new NumericData[] { new ConstrainedIndexValue(0.3, 0.7), new ConstrainedIndexValue(0.1, 2.3) }));
expectedResults.add(new BasicNumericDataset(new NumericData[] { new ConstrainedIndexValue(0.3, 0.7), new ConstrainedIndexValue(3.4, 3.7) }));
final ConstraintSet cs1 = new ConstraintSet();
cs1.addConstraint(ExampleDimensionOne.class, new ConstraintData(new ConstrainedIndexValue(0.3, 0.5), true));
cs1.addConstraint(ExampleDimensionOne.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));
cs2a.addConstraint(ExampleDimensionTwo.class, new ConstraintData(new ConstrainedIndexValue(2.1, 2.3), true));
final ConstraintSet cs2b = new ConstraintSet();
cs2b.addConstraint(ExampleDimensionTwo.class, new ConstraintData(new ConstrainedIndexValue(3.4, 3.7), true));
final ConstraintsByClass constraints = new ConstraintsByClass(Arrays.asList(cs2a, cs2b)).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);
final Index index = new CustomNameIndex(new ExampleNumericIndexStrategy(), new BasicIndexModel(new NumericDimensionField[] { new ExampleDimensionOne(), new ExampleDimensionTwo() }), "22");
assertEquals(expectedResults, query.getIndexConstraints(index));
final List<QueryFilter> filters = query.createFilters(index);
assertEquals(1, filters.size());
final Map<String, ConstrainedIndexValue> fieldIdToValueMap = new HashMap<>();
fieldIdToValueMap.put("one", new ConstrainedIndexValue(0.4, 0.4));
fieldIdToValueMap.put("two", new ConstrainedIndexValue(0.5, 0.5));
final CommonIndexModel model = null;
assertTrue(filters.get(0).accept(model, new CommonIndexedPersistenceEncoding((short) 1, StringUtils.stringToBinary("data"), StringUtils.stringToBinary("partition"), StringUtils.stringToBinary("sort"), // duplicate count
1, new MultiFieldPersistentDataset(fieldIdToValueMap), null)));
fieldIdToValueMap.put("one", new ConstrainedIndexValue(0.1, 0.1));
assertFalse(filters.get(0).accept(model, new CommonIndexedPersistenceEncoding((short) 1, StringUtils.stringToBinary("data"), StringUtils.stringToBinary("partition"), StringUtils.stringToBinary("sort"), // duplicate count
1, new MultiFieldPersistentDataset(fieldIdToValueMap), null)));
fieldIdToValueMap.put("one", new ConstrainedIndexValue(0.4, 0.4));
fieldIdToValueMap.put("two", new ConstrainedIndexValue(5.0, 5.0));
assertFalse(filters.get(0).accept(model, new CommonIndexedPersistenceEncoding((short) 1, StringUtils.stringToBinary("data"), StringUtils.stringToBinary("partition"), StringUtils.stringToBinary("sort"), // duplicate count
1, new MultiFieldPersistentDataset(fieldIdToValueMap), null)));
/**
* Tests the 'OR' Case
*/
fieldIdToValueMap.put("two", new ConstrainedIndexValue(3.5, 3.5));
assertTrue(filters.get(0).accept(model, new CommonIndexedPersistenceEncoding((short) 1, StringUtils.stringToBinary("data"), StringUtils.stringToBinary("partition"), StringUtils.stringToBinary("sort"), // duplicate count
1, new MultiFieldPersistentDataset(fieldIdToValueMap), null)));
}
use of org.locationtech.geowave.core.store.index.BasicIndexModel in project geowave by locationtech.
the class MigrationCommand method migrate0to1.
public void migrate0to1(final DataStorePluginOptions options, final DataStoreOperations operations, final Console console) {
console.println("Migration 1.x -> 2.x");
final DataStore dataStore = options.createDataStore();
console.println(" Migrating data type adapters...");
final PersistentAdapterStore adapterStore = options.createAdapterStore();
final List<Short> adapterIDs = Lists.newArrayList();
int migratedAdapters = 0;
final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
for (final InternalDataAdapter<?> adapter : adapters) {
adapterIDs.add(adapter.getAdapterId());
if (adapter instanceof LegacyInternalDataAdapterWrapper) {
adapterStore.removeAdapter(adapter.getAdapterId());
// Write updated adapter
adapterStore.addAdapter(((LegacyInternalDataAdapterWrapper<?>) adapter).getUpdatedAdapter());
migratedAdapters++;
} else if (adapter.getAdapter() instanceof LegacyFeatureDataAdapter) {
final FeatureDataAdapter updatedAdapter = ((LegacyFeatureDataAdapter) adapter.getAdapter()).getUpdatedAdapter();
final VisibilityHandler visibilityHandler = ((LegacyFeatureDataAdapter) adapter.getAdapter()).getVisibilityHandler();
// Write updated adapter
adapterStore.removeAdapter(adapter.getAdapterId());
adapterStore.addAdapter(updatedAdapter.asInternalAdapter(adapter.getAdapterId(), visibilityHandler));
migratedAdapters++;
}
}
if (migratedAdapters > 0) {
console.println(" Migrated " + migratedAdapters + " data type adapters.");
} else {
console.println(" No data type adapters needed to be migrated.");
}
console.println(" Migrating indices...");
final IndexStore indexStore = options.createIndexStore();
int migratedIndices = 0;
try (CloseableIterator<Index> indices = indexStore.getIndices()) {
while (indices.hasNext()) {
final Index index = indices.next();
final CommonIndexModel indexModel = index.getIndexModel();
// if the index model uses any spatial fields, update and re-write
if ((indexModel != null) && (indexModel instanceof BasicIndexModel)) {
final NumericDimensionField<?>[] oldFields = indexModel.getDimensions();
final NumericDimensionField<?>[] updatedFields = new NumericDimensionField<?>[oldFields.length];
boolean updated = false;
for (int i = 0; i < oldFields.length; i++) {
if (oldFields[i] instanceof LegacySpatialField) {
updatedFields[i] = ((LegacySpatialField<?>) oldFields[i]).getUpdatedField(index);
updated = true;
} else {
updatedFields[i] = oldFields[i];
}
}
if (updated) {
((BasicIndexModel) indexModel).init(updatedFields);
indexStore.removeIndex(index.getName());
indexStore.addIndex(index);
migratedIndices++;
}
}
}
}
if (migratedIndices > 0) {
console.println(" Migrated " + migratedIndices + " indices.");
} else {
console.println(" No indices needed to be migrated.");
}
console.println(" Migrating index mappings...");
// Rewrite adapter to index mappings
final LegacyAdapterIndexMappingStore legacyIndexMappings = new LegacyAdapterIndexMappingStore(operations, options.getFactoryOptions().getStoreOptions());
final AdapterIndexMappingStore indexMappings = options.createAdapterIndexMappingStore();
console.println(" Writing new mappings...");
int indexMappingCount = 0;
for (final Short adapterId : adapterIDs) {
final LegacyAdapterToIndexMapping mapping = legacyIndexMappings.getIndicesForAdapter(adapterId);
final InternalDataAdapter<?> adapter = adapterStore.getAdapter(adapterId);
for (final String indexName : mapping.getIndexNames()) {
indexMappings.addAdapterIndexMapping(BaseDataStoreUtils.mapAdapterToIndex(adapter, indexStore.getIndex(indexName)));
indexMappingCount++;
}
}
if (indexMappingCount > 0) {
console.println(" Migrated " + indexMappingCount + " index mappings.");
console.println(" Deleting legacy index mappings...");
try (MetadataDeleter deleter = operations.createMetadataDeleter(MetadataType.LEGACY_INDEX_MAPPINGS)) {
deleter.delete(new MetadataQuery(null));
} catch (final Exception e) {
LOGGER.warn("Error deleting legacy index mappings", e);
}
} else {
console.println(" No index mappings to migrate.");
}
// Update statistics
console.println(" Migrating statistics...");
final List<Statistic<?>> defaultStatistics = new ArrayList<>();
for (final Index index : dataStore.getIndices()) {
if (index instanceof DefaultStatisticsProvider) {
defaultStatistics.addAll(((DefaultStatisticsProvider) index).getDefaultStatistics());
}
}
for (final DataTypeAdapter<?> adapter : dataStore.getTypes()) {
final DefaultStatisticsProvider defaultStatProvider = BaseDataStoreUtils.getDefaultStatisticsProvider(adapter);
if (defaultStatProvider != null) {
defaultStatistics.addAll(defaultStatProvider.getDefaultStatistics());
}
}
console.println(" Calculating updated statistics...");
dataStore.addStatistic(defaultStatistics.toArray(new Statistic[defaultStatistics.size()]));
console.println(" Deleting legacy statistics...");
try (MetadataDeleter deleter = operations.createMetadataDeleter(MetadataType.LEGACY_STATISTICS)) {
deleter.delete(new MetadataQuery(null));
} catch (final Exception e) {
LOGGER.warn("Error deleting legacy statistics", e);
}
}
Aggregations