Search in sources :

Example 1 with DeferredReadCommonIndexedPersistenceEncoding

use of org.locationtech.geowave.core.store.data.DeferredReadCommonIndexedPersistenceEncoding in project geowave by locationtech.

the class MemoryDataStoreOperations method createReader.

@Override
public <T> RowReader<T> createReader(final ReaderParams<T> readerParams) {
    final SortedSet<MemoryStoreEntry> internalData = storeData.get(readerParams.getIndex().getName());
    int counter = 0;
    List<MemoryStoreEntry> retVal = new ArrayList<>();
    final Collection<SinglePartitionQueryRanges> partitionRanges = readerParams.getQueryRanges().getPartitionQueryRanges();
    if ((partitionRanges == null) || partitionRanges.isEmpty()) {
        retVal.addAll(internalData);
        // remove unauthorized
        final Iterator<MemoryStoreEntry> it = retVal.iterator();
        while (it.hasNext()) {
            if (!isAuthorized(it.next(), readerParams.getAdditionalAuthorizations())) {
                it.remove();
            }
        }
        if ((readerParams.getLimit() != null) && (readerParams.getLimit() > 0) && (retVal.size() > readerParams.getLimit())) {
            retVal = retVal.subList(0, readerParams.getLimit());
        }
    } else {
        for (final SinglePartitionQueryRanges p : partitionRanges) {
            for (final ByteArrayRange r : p.getSortKeyRanges()) {
                final SortedSet<MemoryStoreEntry> set;
                if (r.isSingleValue()) {
                    set = Sets.newTreeSet(internalData.subSet(new MemoryStoreEntry(p.getPartitionKey(), r.getStart()), new MemoryStoreEntry(p.getPartitionKey(), ByteArrayUtils.getNextPrefix(r.getStart()))));
                } else {
                    set = Sets.newTreeSet(internalData.tailSet(new MemoryStoreEntry(p.getPartitionKey(), r.getStart())).headSet(new MemoryStoreEntry(p.getPartitionKey(), r.getEndAsNextPrefix())));
                }
                // remove unauthorized
                final Iterator<MemoryStoreEntry> it = set.iterator();
                while (it.hasNext()) {
                    final MemoryStoreEntry entry = it.next();
                    if (!isAuthorized(entry, readerParams.getAdditionalAuthorizations())) {
                        it.remove();
                    } else if (!ArrayUtils.contains(readerParams.getAdapterIds(), entry.row.getAdapterId())) {
                        it.remove();
                    }
                }
                if ((readerParams.getLimit() != null) && (readerParams.getLimit() > 0) && ((counter + set.size()) > readerParams.getLimit())) {
                    final List<MemoryStoreEntry> subset = new ArrayList<>(set);
                    retVal.addAll(subset.subList(0, readerParams.getLimit() - counter));
                    break;
                } else {
                    retVal.addAll(set);
                    counter += set.size();
                    if ((readerParams.getLimit() != null) && (readerParams.getLimit() > 0) && (counter >= readerParams.getLimit())) {
                        break;
                    }
                }
            }
        }
    }
    return new MyIndexReader<>(Iterators.filter(retVal.iterator(), new Predicate<MemoryStoreEntry>() {

        @Override
        public boolean apply(final MemoryStoreEntry input) {
            if ((readerParams.getFilter() != null) && options.isServerSideLibraryEnabled()) {
                final PersistentDataset<Object> commonData = new MultiFieldPersistentDataset<>();
                final List<FlattenedUnreadData> unreadData = new ArrayList<>();
                final List<String> commonIndexFieldNames = DataStoreUtils.getUniqueDimensionFields(readerParams.getIndex().getIndexModel());
                for (final GeoWaveValue v : input.getRow().getFieldValues()) {
                    unreadData.add(DataStoreUtils.aggregateFieldData(input.getRow(), v, commonData, readerParams.getIndex().getIndexModel(), commonIndexFieldNames));
                }
                return readerParams.getFilter().accept(readerParams.getIndex().getIndexModel(), new DeferredReadCommonIndexedPersistenceEncoding(input.getRow().getAdapterId(), input.getRow().getDataId(), input.getRow().getPartitionKey(), input.getRow().getSortKey(), input.getRow().getNumberOfDuplicates(), commonData, unreadData.isEmpty() ? null : new UnreadFieldDataList(unreadData)));
            }
            return true;
        }
    }), readerParams.getRowTransformer());
}
Also used : DeferredReadCommonIndexedPersistenceEncoding(org.locationtech.geowave.core.store.data.DeferredReadCommonIndexedPersistenceEncoding) UnreadFieldDataList(org.locationtech.geowave.core.store.data.UnreadFieldDataList) ArrayList(java.util.ArrayList) SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) GeoWaveValue(org.locationtech.geowave.core.store.entities.GeoWaveValue) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange) Predicate(com.google.common.base.Predicate) MultiFieldPersistentDataset(org.locationtech.geowave.core.store.data.MultiFieldPersistentDataset) FlattenedUnreadData(org.locationtech.geowave.core.store.flatten.FlattenedUnreadData)

Aggregations

Predicate (com.google.common.base.Predicate)1 ArrayList (java.util.ArrayList)1 ByteArrayRange (org.locationtech.geowave.core.index.ByteArrayRange)1 SinglePartitionQueryRanges (org.locationtech.geowave.core.index.SinglePartitionQueryRanges)1 DeferredReadCommonIndexedPersistenceEncoding (org.locationtech.geowave.core.store.data.DeferredReadCommonIndexedPersistenceEncoding)1 MultiFieldPersistentDataset (org.locationtech.geowave.core.store.data.MultiFieldPersistentDataset)1 UnreadFieldDataList (org.locationtech.geowave.core.store.data.UnreadFieldDataList)1 GeoWaveValue (org.locationtech.geowave.core.store.entities.GeoWaveValue)1 FlattenedUnreadData (org.locationtech.geowave.core.store.flatten.FlattenedUnreadData)1