use of org.locationtech.geowave.core.store.adapter.LazyReadPersistenceEncoding in project geowave by locationtech.
the class BaseDataStoreUtils method getDecodedRow.
/**
* build a persistence encoding object first, pass it through the client filters and if its
* accepted, use the data adapter to decode the persistence model into the native data type
*/
private static <T> Object getDecodedRow(final GeoWaveRow row, final IntermediaryReadEntryInfo<T> decodePackage, final byte[] fieldSubsetBitmask, final QueryFilter[] clientFilters, final ScanCallback<T, GeoWaveRow> scanCallback, final DataIndexRetrieval dataIndexRetrieval) {
final boolean isSecondaryIndex = dataIndexRetrieval != null;
final IndexedAdapterPersistenceEncoding encodedRow;
if (isSecondaryIndex) {
// this implies its a Secondary Index and the actual values must be looked up
if (dataIndexRetrieval instanceof BatchDataIndexRetrieval) {
if (decodePackage.getIndex().getIndexModel().useInSecondaryIndex()) {
encodedRow = new PartialAsyncPersistenceEncoding(decodePackage.getDataAdapter().getAdapterId(), row.getDataId(), row.getPartitionKey(), row.getSortKey(), row.getNumberOfDuplicates(), (BatchDataIndexRetrieval) dataIndexRetrieval, decodePackage.getDataAdapter(), decodePackage.getIndex().getIndexModel(), decodePackage.getIndexMapping(), fieldSubsetBitmask, Suppliers.memoize(() -> dataIndexRetrieval.getData(decodePackage.getDataAdapter().getAdapterId(), row.getDataId())));
} else {
encodedRow = new FullAsyncPersistenceEncoding(decodePackage.getDataAdapter().getAdapterId(), row.getDataId(), row.getPartitionKey(), row.getSortKey(), row.getNumberOfDuplicates(), (BatchDataIndexRetrieval) dataIndexRetrieval);
}
} else {
encodedRow = new LazyReadPersistenceEncoding(decodePackage.getDataAdapter().getAdapterId(), row.getDataId(), row.getPartitionKey(), row.getSortKey(), row.getNumberOfDuplicates(), decodePackage.getDataAdapter(), decodePackage.getIndex().getIndexModel(), decodePackage.getIndexMapping(), fieldSubsetBitmask, Suppliers.memoize(() -> dataIndexRetrieval.getData(decodePackage.getDataAdapter().getAdapterId(), row.getDataId())));
}
} else {
encodedRow = new LazyReadPersistenceEncoding(decodePackage.getDataAdapter().getAdapterId(), row.getDataId(), row.getPartitionKey(), row.getSortKey(), row.getNumberOfDuplicates(), decodePackage.getDataAdapter(), decodePackage.getIndex().getIndexModel(), decodePackage.getIndexMapping(), fieldSubsetBitmask, row.getFieldValues(), false);
}
final BiFunction<IndexedAdapterPersistenceEncoding, Integer, Object> function = ((r, initialFilter) -> {
final int i = clientFilterProgress(clientFilters, decodePackage.getIndex().getIndexModel(), r, initialFilter);
if (i < 0) {
if (!decodePackage.isDecodeRow()) {
return r;
}
final T decodedRow = decodePackage.getDataAdapter().decode(r, decodePackage.getIndexMapping(), isSecondaryIndex ? DataIndexUtils.DATA_ID_INDEX : decodePackage.getIndex());
if (r.isAsync()) {
return i;
}
if ((scanCallback != null)) {
scanCallback.entryScanned(decodedRow, row);
}
return decodedRow;
}
if (r.isAsync()) {
return i;
}
return null;
});
final Object obj = function.apply(encodedRow, 0);
if ((obj instanceof Integer) && encodedRow.isAsync()) {
// the data will not need to be repeated
return (((AsyncPersistenceEncoding) encodedRow).getFieldValuesFuture().thenApply(fv -> new LazyReadPersistenceEncoding(decodePackage.getDataAdapter().getAdapterId(), row.getDataId(), row.getPartitionKey(), row.getSortKey(), row.getNumberOfDuplicates(), decodePackage.getDataAdapter(), decodePackage.getIndex().getIndexModel(), decodePackage.getIndexMapping(), fieldSubsetBitmask, fv, true))).thenApply((r) -> function.apply(r, (Integer) obj));
}
return obj;
}
Aggregations