use of org.locationtech.geowave.core.store.base.BaseDataStore in project geowave by locationtech.
the class BaseDataStoreFactory method createStore.
@Override
public DataStore createStore(final StoreFactoryOptions factoryOptions) {
final DataStoreOperations operations = helper.createOperations(factoryOptions);
final DataStoreOptions options = factoryOptions.getStoreOptions();
return new BaseDataStore(new IndexStoreImpl(operations, options), new AdapterStoreImpl(operations, options), new DataStatisticsStoreImpl(operations, options), new AdapterIndexMappingStoreImpl(operations, options), operations, options, new InternalAdapterStoreImpl(operations), new PropertyStoreImpl(operations, options));
}
use of org.locationtech.geowave.core.store.base.BaseDataStore in project geowave by locationtech.
the class SpatialTemporalQueryIT method testTimeRangeDuplicateDeletion.
@Test
public void testTimeRangeDuplicateDeletion() throws IOException {
// create an internal data adapter wrapper for use in methods below
final short typeId = ((BaseDataStore) dataStore).getAdapterId(timeRangeAdapter.getTypeName());
// setup the vector query builder
final VectorQueryBuilder bldr = VectorQueryBuilder.newBuilder();
bldr.indexName(YEAR_INDEX.getName());
bldr.setTypeNames(new String[] { timeRangeAdapter.getTypeName() });
// Create the query over the range (1970-1974)
currentGeotoolsIndex = YEAR_INDEX;
final Calendar cal = getInitialYearCalendar();
cal.set(Calendar.YEAR, DUPLICATE_DELETION_YEAR_MIN);
Date startOfQuery = cal.getTime();
cal.set(Calendar.YEAR, DUPLICATE_DELETION_YEAR_MAX);
Date endOfQuery = cal.getTime();
final ExplicitSpatialTemporalQuery fullRangeQuery = new ExplicitSpatialTemporalQuery(startOfQuery, endOfQuery, new GeometryFactory().toGeometry(new Envelope(-1, 1, -1, 1)));
// Create query for selecting items that should still exist
// after the deletion query is performed
// (i.e. we didn't actually delete something we weren't supposed to)
cal.set(Calendar.YEAR, MULTI_YEAR_MIN);
startOfQuery = cal.getTime();
cal.set(Calendar.YEAR, MULTI_YEAR_MAX);
endOfQuery = cal.getTime();
final ExplicitSpatialTemporalQuery sanityQuery = new ExplicitSpatialTemporalQuery(startOfQuery, endOfQuery, new GeometryFactory().toGeometry(new Envelope(-1, 1, -1, 1)));
// Create deletion query to remove a single entry (1970-1971). Even
// though we are requesting to delete within a single year, this should
// remove all duplicates
cal.set(Calendar.YEAR, DUPLICATE_DELETION_YEAR_MIN);
startOfQuery = cal.getTime();
cal.set(Calendar.YEAR, DUPLICATE_DELETION_YEAR_MIN + 1);
endOfQuery = cal.getTime();
final ExplicitSpatialTemporalQuery deletionQuery = new ExplicitSpatialTemporalQuery(startOfQuery, endOfQuery, new GeometryFactory().toGeometry(new Envelope(-1, 1, -1, 1)));
// Sanity count number of entries that have nothing to do with
// the deletion query (after the deletion we will query again and see
// if count == sanity_count, we also want to make sure we don't delete
// any of the 'untouched' duplicates for the entries as well.
long sanity_count = 0;
long sanity_duplicates = 0;
DuplicateCountCallback<SimpleFeature> dupeCounter = new DuplicateCountCallback<>();
try (CloseableIterator<?> dataIt = ((BaseDataStore) dataStore).query(bldr.constraints(sanityQuery).build(), dupeCounter)) {
while (dataIt.hasNext()) {
sanity_count++;
dataIt.next();
}
dataIt.close();
}
sanity_duplicates = dupeCounter.getDuplicateCount();
// there should be four entries with duplicates 1980-1987, 1987-1995,
// 1980-1995, 1970-1974
final long numExpectedEntries = 4;
// there should be four duplicates for the range 1970-1974 (one for each
// year after 1970)
final long numExpectedDuplicates = (DUPLICATE_DELETION_YEAR_MAX - DUPLICATE_DELETION_YEAR_MIN);
final PersistentAdapterStore adapterStore = dataStoreOptions.createAdapterStore();
// check and count the number of entries with duplicates
DuplicateEntryCountValue dupeEntryCount = InternalStatisticsHelper.getDuplicateCounts(YEAR_INDEX, Collections.singletonList(typeId), adapterStore, ((BaseDataStore) dataStore).getStatisticsStore());
Assert.assertEquals(numExpectedEntries, dupeEntryCount.getValue().longValue());
// check and count the duplicates for 1970-1974
dupeCounter = new DuplicateCountCallback<>();
try (CloseableIterator<?> dataIt = ((BaseDataStore) dataStore).query(bldr.constraints(fullRangeQuery).build(), dupeCounter)) {
while (dataIt.hasNext()) {
dataIt.next();
}
dataIt.close();
}
Assert.assertEquals(numExpectedDuplicates, dupeCounter.getDuplicateCount());
// perform the delete for a single year (1970-1971)
dataStore.delete(bldr.constraints(deletionQuery).build());
// if the delete works there should be no more duplicates for this
// entry...
dupeCounter = new DuplicateCountCallback<>();
try (CloseableIterator<?> dataIt = ((BaseDataStore) dataStore).query(bldr.constraints(fullRangeQuery).build(), dupeCounter)) {
while (dataIt.hasNext()) {
dataIt.next();
}
dataIt.close();
}
Assert.assertEquals(0, dupeCounter.getDuplicateCount());
// ..and it should not count the entry as having any duplicates i.e. the
// number of entries with duplicates should match the sanity query count
// 3(1980-1987, 1987-1995, 1980-1990)
dupeEntryCount = InternalStatisticsHelper.getDuplicateCounts(YEAR_INDEX, Collections.singletonList(typeId), adapterStore, ((BaseDataStore) dataStore).getStatisticsStore());
// if delete works, it should not count the entry as having any
// duplicates and the number of entries with duplicates should match the
// sanity query count 3(1980-1987, 1987-1995, 1980-1990)
Assert.assertEquals(sanity_count, dupeEntryCount.getValue().longValue());
// finally check we didn't accidentally delete any duplicates of the
// sanity query range
dupeCounter = new DuplicateCountCallback<>();
try (CloseableIterator<?> dataIt = ((BaseDataStore) dataStore).query(bldr.constraints(sanityQuery).build(), dupeCounter)) {
while (dataIt.hasNext()) {
dataIt.next();
}
}
Assert.assertEquals(sanity_duplicates, dupeCounter.getDuplicateCount());
}
use of org.locationtech.geowave.core.store.base.BaseDataStore in project geowave by locationtech.
the class DataIndexOnlyIT method testDataIndexOnlyOnCustomType.
@Test
public void testDataIndexOnlyOnCustomType() throws Exception {
final DataStore dataStore = dataIdxOnlyDataStoreOptions.createDataStore();
final LatLonTimeAdapter adapter = new LatLonTimeAdapter();
dataStore.addType(adapter);
try (Writer<LatLonTime> writer = dataStore.createWriter(adapter.getTypeName())) {
for (int i = 0; i < 10; i++) {
writer.write(new LatLonTime(i, 100 * i, 0.25f * i, -0.5f * i));
}
}
final Set<Integer> expectedIntIds = IntStream.rangeClosed(0, 9).boxed().collect(Collectors.toSet());
try (CloseableIterator<LatLonTime> it = (CloseableIterator) dataStore.query(QueryBuilder.newBuilder().build())) {
while (it.hasNext()) {
Assert.assertTrue(expectedIntIds.remove(it.next().getId()));
}
}
Assert.assertTrue(expectedIntIds.isEmpty());
try {
List<Integer> expectedReversedIntIds = IntStream.rangeClosed(0, 2).boxed().collect(Collectors.toList());
ListIterator<Integer> expectedReversedIntIdsIterator = expectedReversedIntIds.listIterator(expectedReversedIntIds.size());
try (CloseableIterator<LatLonTime> it = (CloseableIterator) dataStore.query(QueryBuilder.newBuilder().constraints(QueryBuilder.newBuilder().constraintsFactory().dataIdsByRangeReverse(null, Lexicoders.LONG.toByteArray(200L))).build())) {
while (it.hasNext()) {
Assert.assertEquals(Integer.valueOf(expectedReversedIntIdsIterator.previous()), Integer.valueOf(it.next().getId()));
}
Assert.assertTrue(!expectedReversedIntIdsIterator.hasPrevious());
}
expectedReversedIntIds = IntStream.rangeClosed(7, 9).boxed().collect(Collectors.toList());
expectedReversedIntIdsIterator = expectedReversedIntIds.listIterator(expectedReversedIntIds.size());
try (CloseableIterator<LatLonTime> it = (CloseableIterator) dataStore.query(QueryBuilder.newBuilder().constraints(QueryBuilder.newBuilder().constraintsFactory().dataIdsByRangeReverse(Lexicoders.LONG.toByteArray(650L), null)).build())) {
while (it.hasNext()) {
Assert.assertEquals(Integer.valueOf(expectedReversedIntIdsIterator.previous()), Integer.valueOf(it.next().getId()));
}
Assert.assertTrue(!expectedReversedIntIdsIterator.hasPrevious());
}
expectedReversedIntIds = IntStream.rangeClosed(4, 8).boxed().collect(Collectors.toList());
expectedReversedIntIdsIterator = expectedReversedIntIds.listIterator(expectedReversedIntIds.size());
try (CloseableIterator<LatLonTime> it = (CloseableIterator) dataStore.query(QueryBuilder.newBuilder().constraints(QueryBuilder.newBuilder().constraintsFactory().dataIdsByRangeReverse(Lexicoders.LONG.toByteArray(400L), Lexicoders.LONG.toByteArray(800L))).build())) {
while (it.hasNext()) {
Assert.assertEquals(Integer.valueOf(expectedReversedIntIdsIterator.previous()), Integer.valueOf(it.next().getId()));
}
Assert.assertTrue(!expectedReversedIntIdsIterator.hasPrevious());
}
} catch (final UnsupportedOperationException e) {
if (((BaseDataStore) dataStore).isReverseIterationSupported()) {
Assert.fail(e.getMessage());
}
}
TestUtils.deleteAll(dataIdxOnlyDataStoreOptions);
}
Aggregations