Search in sources :

Example 1 with SinglePartitionQueryRanges

use of org.locationtech.geowave.core.index.SinglePartitionQueryRanges in project geowave by locationtech.

the class TextIndexUtils method getForwardQueryRanges.

public static QueryRanges getForwardQueryRanges(final String term, final boolean caseSensitive) {
    final byte[] forwardTermBytes = StringUtils.stringToBinary(caseSensitive ? term : term.toLowerCase());
    final List<SinglePartitionQueryRanges> retVal = new ArrayList<>(1);
    retVal.add(new SinglePartitionQueryRanges(caseSensitive ? FORWARD_INDEX_CASE_SENSITIVE_PARTITION_KEY : FORWARD_INDEX_CASE_INSENSITIVE_PARTITION_KEY, Collections.singletonList(new ByteArrayRange(forwardTermBytes, forwardTermBytes))));
    return new QueryRanges(retVal);
}
Also used : SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) QueryRanges(org.locationtech.geowave.core.index.QueryRanges) SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) ArrayList(java.util.ArrayList) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange)

Example 2 with SinglePartitionQueryRanges

use of org.locationtech.geowave.core.index.SinglePartitionQueryRanges in project geowave by locationtech.

the class TextIndexUtils method getReverseQueryRanges.

public static QueryRanges getReverseQueryRanges(final String startTerm, final String endTerm, final boolean startInclusive, final boolean endInclusive, final boolean caseSensitive) {
    byte[] startBytes = StringUtils.stringToBinary(new StringBuilder(caseSensitive ? startTerm : endTerm.toLowerCase()).reverse().toString());
    if (!startInclusive) {
        startBytes = ByteArrayUtils.getNextPrefix(startBytes);
    }
    final byte[] endBytes = StringUtils.stringToBinary(new StringBuilder(caseSensitive ? endTerm : endTerm.toLowerCase()).reverse().toString());
    if (!endInclusive) {
        startBytes = ByteArrayUtils.getPreviousPrefix(startBytes);
    }
    final List<SinglePartitionQueryRanges> retVal = new ArrayList<>(1);
    retVal.add(new SinglePartitionQueryRanges(caseSensitive ? REVERSE_INDEX_CASE_SENSITIVE_PARTITION_KEY : REVERSE_INDEX_CASE_INSENSITIVE_PARTITION_KEY, Collections.singletonList(new ByteArrayRange(startBytes, endBytes))));
    return new QueryRanges(retVal);
}
Also used : SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) QueryRanges(org.locationtech.geowave.core.index.QueryRanges) SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) ArrayList(java.util.ArrayList) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange)

Example 3 with SinglePartitionQueryRanges

use of org.locationtech.geowave.core.index.SinglePartitionQueryRanges in project geowave by locationtech.

the class CassandraReader method initScanner.

protected void initScanner() {
    final Collection<SinglePartitionQueryRanges> ranges = readerParams.getQueryRanges().getPartitionQueryRanges();
    if ((ranges != null) && !ranges.isEmpty()) {
        iterator = operations.getBatchedRangeRead(readerParams.getIndex().getName(), readerParams.getAdapterIds(), ranges, DataStoreUtils.isMergingIteratorRequired(readerParams, visibilityEnabled), rowTransformer, new ClientVisibilityFilter(Sets.newHashSet(readerParams.getAdditionalAuthorizations()))).results();
    } else {
        // TODO figure out the query select by adapter IDs here
        final Select select = operations.getSelect(readerParams.getIndex().getName());
        CloseableIterator<CassandraRow> results = operations.executeQuery(select.build());
        if ((readerParams.getAdapterIds() != null) && (readerParams.getAdapterIds().length > 0)) {
            // TODO because we aren't filtering server-side by adapter ID,
            // we will need to filter here on the client
            results = new CloseableIteratorWrapper<>(results, Iterators.filter(results, input -> ArrayUtils.contains(readerParams.getAdapterIds(), input.getAdapterId())));
        }
        iterator = wrapResults(results, readerParams);
    }
}
Also used : SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) Select(com.datastax.oss.driver.api.querybuilder.select.Select) CassandraRow(org.locationtech.geowave.datastore.cassandra.CassandraRow) ClientVisibilityFilter(org.locationtech.geowave.core.store.query.filter.ClientVisibilityFilter)

Example 4 with SinglePartitionQueryRanges

use of org.locationtech.geowave.core.index.SinglePartitionQueryRanges in project geowave by locationtech.

the class BatchedRangeRead method results.

public CloseableIterator<T> results() {
    final List<BoundStatement> statements = new ArrayList<>();
    for (final SinglePartitionQueryRanges r : ranges) {
        final byte[] partitionKey = CassandraUtils.getCassandraSafePartitionKey(r.getPartitionKey());
        for (final ByteArrayRange range : r.getSortKeyRanges()) {
            final BoundStatementBuilder boundRead = preparedRead.boundStatementBuilder();
            final byte[] start = range.getStart() != null ? range.getStart() : new byte[0];
            final byte[] end = range.getEnd() != null ? range.getEndAsNextPrefix() : new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
            statements.add(boundRead.set(CassandraField.GW_SORT_KEY.getLowerBoundBindMarkerName(), ByteBuffer.wrap(start), ByteBuffer.class).set(CassandraField.GW_SORT_KEY.getUpperBoundBindMarkerName(), ByteBuffer.wrap(end), ByteBuffer.class).set(CassandraField.GW_PARTITION_ID_KEY.getBindMarkerName(), ByteBuffer.wrap(partitionKey), ByteBuffer.class).set(CassandraField.GW_ADAPTER_ID_KEY.getBindMarkerName(), Arrays.asList(ArrayUtils.toObject(adapterIds)), TypeCodecs.listOf(TypeCodecs.SMALLINT)).build());
        }
    }
    return executeQueryAsync(statements.toArray(new BoundStatement[] {}));
}
Also used : BoundStatementBuilder(com.datastax.oss.driver.api.core.cql.BoundStatementBuilder) ArrayList(java.util.ArrayList) SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement) ByteBuffer(java.nio.ByteBuffer) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange)

Example 5 with SinglePartitionQueryRanges

use of org.locationtech.geowave.core.index.SinglePartitionQueryRanges in project geowave by locationtech.

the class FileSystemReader method createIterator.

private CloseableIterator<T> createIterator(final FileSystemClient client, final RangeReaderParams<T> readerParams, final GeoWaveRowIteratorTransformer<T> rowTransformer, final Collection<SinglePartitionQueryRanges> ranges, final Set<String> authorizations, final boolean async) {
    final Iterator<CloseableIterator> it = Arrays.stream(ArrayUtils.toObject(readerParams.getAdapterIds())).map(adapterId -> new FileSystemQueryExecution(client, adapterId, readerParams.getInternalAdapterStore().getTypeName(adapterId), readerParams.getIndex().getName(), client.getFormat(), rowTransformer, ranges, new ClientVisibilityFilter(authorizations), DataStoreUtils.isMergingIteratorRequired(readerParams, client.isVisibilityEnabled()), async, FileSystemUtils.isGroupByRowAndIsSortByTime(readerParams, adapterId), FileSystemUtils.isSortByKeyRequired(readerParams)).results()).iterator();
    final CloseableIterator<T>[] itArray = Iterators.toArray(it, CloseableIterator.class);
    return new CloseableIteratorWrapper<>(new Closeable() {

        AtomicBoolean closed = new AtomicBoolean(false);

        @Override
        public void close() throws IOException {
            if (!closed.getAndSet(true)) {
                Arrays.stream(itArray).forEach(it -> it.close());
            }
        }
    }, Iterators.concat(itArray));
}
Also used : Arrays(java.util.Arrays) RecordReaderParams(org.locationtech.geowave.mapreduce.splits.RecordReaderParams) SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) GeoWaveRowIteratorTransformer(org.locationtech.geowave.core.store.entities.GeoWaveRowIteratorTransformer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayUtils(org.apache.commons.lang3.ArrayUtils) IndexFormatter(org.locationtech.geowave.datastore.filesystem.FileSystemDataFormatter.IndexFormatter) Iterators(com.google.common.collect.Iterators) ArrayList(java.util.ArrayList) Pair(org.apache.commons.lang3.tuple.Pair) CloseableIteratorWrapper(org.locationtech.geowave.core.store.CloseableIteratorWrapper) ReaderParams(org.locationtech.geowave.core.store.operations.ReaderParams) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange) ClientVisibilityFilter(org.locationtech.geowave.core.store.query.filter.ClientVisibilityFilter) FileSystemDataIndexTable(org.locationtech.geowave.datastore.filesystem.util.FileSystemDataIndexTable) DataFormatterCache(org.locationtech.geowave.datastore.filesystem.util.DataFormatterCache) DataStoreUtils(org.locationtech.geowave.core.store.util.DataStoreUtils) GeoWaveRow(org.locationtech.geowave.core.store.entities.GeoWaveRow) Iterator(java.util.Iterator) GeoWaveRowMergingIterator(org.locationtech.geowave.core.store.entities.GeoWaveRowMergingIterator) DataIndexReaderParams(org.locationtech.geowave.core.store.operations.DataIndexReaderParams) RowReader(org.locationtech.geowave.core.store.operations.RowReader) Collection(java.util.Collection) Set(java.util.Set) FileSystemUtils(org.locationtech.geowave.datastore.filesystem.util.FileSystemUtils) IOException(java.io.IOException) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) RangeReaderParams(org.locationtech.geowave.core.store.operations.RangeReaderParams) List(java.util.List) Stream(java.util.stream.Stream) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) Closeable(java.io.Closeable) GeoWaveRowRange(org.locationtech.geowave.mapreduce.splits.GeoWaveRowRange) Collections(java.util.Collections) FileSystemClient(org.locationtech.geowave.datastore.filesystem.util.FileSystemClient) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) Closeable(java.io.Closeable) IOException(java.io.IOException) CloseableIteratorWrapper(org.locationtech.geowave.core.store.CloseableIteratorWrapper) ClientVisibilityFilter(org.locationtech.geowave.core.store.query.filter.ClientVisibilityFilter)

Aggregations

SinglePartitionQueryRanges (org.locationtech.geowave.core.index.SinglePartitionQueryRanges)23 ByteArrayRange (org.locationtech.geowave.core.index.ByteArrayRange)19 ArrayList (java.util.ArrayList)13 GeoWaveRowRange (org.locationtech.geowave.mapreduce.splits.GeoWaveRowRange)11 ClientVisibilityFilter (org.locationtech.geowave.core.store.query.filter.ClientVisibilityFilter)9 QueryRanges (org.locationtech.geowave.core.index.QueryRanges)7 ReaderParams (org.locationtech.geowave.core.store.operations.ReaderParams)7 RecordReaderParams (org.locationtech.geowave.mapreduce.splits.RecordReaderParams)7 Iterators (com.google.common.collect.Iterators)6 Sets (com.google.common.collect.Sets)6 Streams (com.google.common.collect.Streams)6 Closeable (java.io.Closeable)6 IOException (java.io.IOException)6 Arrays (java.util.Arrays)6 Collection (java.util.Collection)6 Collections (java.util.Collections)6 Iterator (java.util.Iterator)6 Set (java.util.Set)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Stream (java.util.stream.Stream)6