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);
}
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);
}
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);
}
}
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[] {}));
}
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));
}
Aggregations