use of org.locationtech.geowave.core.store.operations.MetadataQuery 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.operations.MetadataQuery 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.operations.MetadataQuery 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.operations.MetadataQuery in project geowave by locationtech.
the class DataStatisticsStoreImpl method createStatisticValueReader.
private <V extends StatisticValue<R>, R> StatisticValueReader<V, R> createStatisticValueReader(final Statistic<V> statistic, final ByteArray bin, final boolean exact, final String... authorizations) {
final byte[] primaryId;
if ((bin == null) && !exact) {
primaryId = StatisticValue.getValueId(statistic.getId(), new byte[0]);
} else {
primaryId = StatisticValue.getValueId(statistic.getId(), bin);
}
final MetadataQuery query = new MetadataQuery(primaryId, statistic.getId().getGroupId().getBytes(), !exact, authorizations);
return new StatisticValueReader<>(operations.createMetadataReader(MetadataType.STATISTIC_VALUES).query(query), statistic);
}
use of org.locationtech.geowave.core.store.operations.MetadataQuery in project geowave by locationtech.
the class InternalAdapterStoreImpl method getAdapterIds.
@Override
public short[] getAdapterIds() {
final MetadataReader reader = getReader(false);
if (reader == null) {
return new short[0];
}
final CloseableIterator<GeoWaveMetadata> results = reader.query(new MetadataQuery(EXTERNAL_TO_INTERNAL_ID));
try (CloseableIterator<Short> it = new CloseableIteratorWrapper<>(results, Iterators.transform(results, input -> ByteArrayUtils.byteArrayToShort(input.getValue())))) {
return ArrayUtils.toPrimitive(Iterators.toArray(it, Short.class));
}
}
Aggregations