use of org.locationtech.geowave.core.store.entities.GeoWaveMetadata in project geowave by locationtech.
the class DataStoreUtils method safeMetadataDelete.
public static void safeMetadataDelete(final MetadataDeleter deleter, final DataStoreOperations operations, final MetadataType metadataType, final MetadataQuery query) {
// we need to respect visibilities although this may be much slower
final MetadataReader reader = operations.createMetadataReader(metadataType);
try (final CloseableIterator<GeoWaveMetadata> it = reader.query(query)) {
while (it.hasNext()) {
final GeoWaveMetadata entry = it.next();
deleter.delete(new MetadataQuery(entry.getPrimaryId(), entry.getSecondaryId(), query.getAuthorizations()));
}
}
}
use of org.locationtech.geowave.core.store.entities.GeoWaveMetadata in project geowave by locationtech.
the class StatisticValueReader method next.
@Override
public V next() {
V currentValue = next;
byte[] currentPrimaryId = nextPrimaryId;
next = null;
nextPrimaryId = null;
while (metadataIter.hasNext()) {
final GeoWaveMetadata row = metadataIter.next();
final V entry = statistic.createEmpty();
entry.fromBinary(PersistenceUtils.stripClassId(row.getValue()));
if (currentValue == null) {
currentValue = entry;
currentPrimaryId = row.getPrimaryId();
} else {
if (Arrays.equals(currentPrimaryId, row.getPrimaryId())) {
currentValue.merge(entry);
} else {
next = entry;
nextPrimaryId = row.getPrimaryId();
break;
}
}
}
if (currentValue != null && statistic.getBinningStrategy() != null) {
currentValue.setBin(getBinFromValueId(statistic.getId(), currentPrimaryId));
}
return currentValue;
}
use of org.locationtech.geowave.core.store.entities.GeoWaveMetadata in project geowave by locationtech.
the class CassandraMetadataReader method query.
@Override
public CloseableIterator<GeoWaveMetadata> query(final MetadataQuery query) {
final String tableName = operations.getMetadataTableName(metadataType);
final String[] selectedColumns = metadataType.isStatValues() ? ArrayUtils.add(getSelectedColumns(query), CassandraMetadataWriter.VISIBILITY_KEY) : getSelectedColumns(query);
Predicate<Row> clientFilter = null;
if (query.isPrefix()) {
if (query.hasPrimaryId()) {
clientFilter = new PrimaryIDPrefixFilter(query.getPrimaryId());
}
}
final Iterator<Row> rows;
if (!query.hasPrimaryIdRanges()) {
Select select = operations.getSelect(tableName, selectedColumns);
if (query.hasPrimaryId() && query.isExact()) {
select = select.whereColumn(CassandraMetadataWriter.PRIMARY_ID_KEY).isEqualTo(QueryBuilder.literal(ByteBuffer.wrap(query.getPrimaryId())));
if (query.hasSecondaryId()) {
select = select.whereColumn(CassandraMetadataWriter.SECONDARY_ID_KEY).isEqualTo(QueryBuilder.literal(ByteBuffer.wrap(query.getSecondaryId())));
}
} else if (query.hasSecondaryId()) {
select = select.allowFiltering().whereColumn(CassandraMetadataWriter.SECONDARY_ID_KEY).isEqualTo(QueryBuilder.literal(ByteBuffer.wrap(query.getSecondaryId())));
}
final ResultSet rs = operations.getSession().execute(select.build());
rows = rs.iterator();
} else {
rows = Iterators.concat(Arrays.stream(query.getPrimaryIdRanges()).map((r) -> {
// TODO this is not as efficient as prepared bound statements if there are many
// ranges, but will work for now
Select select = operations.getSelect(tableName, selectedColumns);
if (r.getStart() != null) {
select = select.allowFiltering().whereColumn(CassandraMetadataWriter.PRIMARY_ID_KEY).isGreaterThanOrEqualTo(QueryBuilder.literal(ByteBuffer.wrap(r.getStart())));
}
if (r.getEnd() != null) {
select = select.allowFiltering().whereColumn(CassandraMetadataWriter.PRIMARY_ID_KEY).isLessThan(QueryBuilder.literal(ByteBuffer.wrap(r.getEndAsNextPrefix())));
}
final ResultSet rs = operations.getSession().execute(select.build());
return rs.iterator();
}).iterator());
}
final CloseableIterator<GeoWaveMetadata> retVal = new CloseableIterator.Wrapper<>(Iterators.transform(clientFilter != null ? Iterators.filter(rows, clientFilter) : rows, result -> new GeoWaveMetadata((query.hasPrimaryId() && query.isExact()) ? query.getPrimaryId() : result.get(CassandraMetadataWriter.PRIMARY_ID_KEY, ByteBuffer.class).array(), useSecondaryId(query) ? query.getSecondaryId() : result.get(CassandraMetadataWriter.SECONDARY_ID_KEY, ByteBuffer.class).array(), getVisibility(query, result), result.get(CassandraMetadataWriter.VALUE_KEY, ByteBuffer.class).array())));
return query.getAuthorizations() != null ? MetadataIterators.clientVisibilityFilter(retVal, query.getAuthorizations()) : retVal;
}
use of org.locationtech.geowave.core.store.entities.GeoWaveMetadata in project geowave by locationtech.
the class GeoWaveStabilityIT method copyBadData.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void copyBadData(final boolean badMetadata) throws Exception {
final DataStoreOperations badStoreOperations = badDataStore.createDataStoreOperations();
final DataStoreOperations storeOperations = dataStore.createDataStoreOperations();
final PersistentAdapterStore adapterStore = dataStore.createAdapterStore();
final InternalAdapterStore internalAdapterStore = dataStore.createInternalAdapterStore();
final AdapterIndexMappingStore indexMappingStore = dataStore.createAdapterIndexMappingStore();
final IndexStore indexStore = dataStore.createIndexStore();
for (final MetadataType metadataType : MetadataType.values()) {
try (MetadataWriter writer = badStoreOperations.createMetadataWriter(metadataType)) {
final MetadataReader reader = storeOperations.createMetadataReader(metadataType);
try (CloseableIterator<GeoWaveMetadata> it = reader.query(new MetadataQuery(null, null))) {
while (it.hasNext()) {
if (badMetadata) {
writer.write(new BadGeoWaveMetadata(it.next()));
} else {
writer.write(it.next());
}
}
}
} catch (final Exception e) {
LOGGER.error("Unable to write metadata on copy", e);
}
}
final InternalDataAdapter<?>[] adapters = adapterStore.getAdapters();
for (final InternalDataAdapter<?> adapter : adapters) {
for (final AdapterToIndexMapping indexMapping : indexMappingStore.getIndicesForAdapter(adapter.getAdapterId())) {
final boolean rowMerging = BaseDataStoreUtils.isRowMerging(adapter);
final Index index = indexMapping.getIndex(indexStore);
final ReaderParamsBuilder bldr = new ReaderParamsBuilder(index, adapterStore, indexMappingStore, internalAdapterStore, GeoWaveRowIteratorTransformer.NO_OP_TRANSFORMER);
bldr.adapterIds(new short[] { adapter.getAdapterId() });
bldr.isClientsideRowMerging(rowMerging);
try (RowReader<GeoWaveRow> reader = storeOperations.createReader(bldr.build())) {
try (RowWriter writer = badStoreOperations.createWriter(index, adapter)) {
while (reader.hasNext()) {
if (!badMetadata) {
writer.write(new BadGeoWaveRow(reader.next()));
} else {
writer.write(reader.next());
}
}
}
} catch (final Exception e) {
LOGGER.error("Unable to write metadata on copy", e);
}
}
}
try {
badDataStore.createDataStatisticsStore().mergeStats();
} catch (final Exception e) {
LOGGER.info("Caught exception while merging bad stats.");
}
}
use of org.locationtech.geowave.core.store.entities.GeoWaveMetadata in project geowave by locationtech.
the class AbstractGeoWavePersistence method internalGetObjects.
protected CloseableIterator<T> internalGetObjects(final MetadataQuery query) {
try {
if (!operations.metadataExists(getType())) {
return new CloseableIterator.Empty<>();
}
} catch (final IOException e1) {
LOGGER.error("Unable to check for existence of metadata to get objects", e1);
return new CloseableIterator.Empty<>();
}
final MetadataReader reader = operations.createMetadataReader(getType());
final CloseableIterator<GeoWaveMetadata> it = reader.query(query);
return new NativeIteratorWrapper(it, query.getAuthorizations());
}
Aggregations