use of org.locationtech.geowave.core.index.QueryRanges in project geowave by locationtech.
the class TextIndexUtils method getNGramQueryRanges.
public static QueryRanges getNGramQueryRanges(final String initialTerm, final int nGramCharacters, final boolean isForwardIndexed, final boolean caseSensitive) {
final String term = caseSensitive ? initialTerm : initialTerm.toLowerCase();
final boolean shouldTruncateNGram = term.length() > nGramCharacters;
final byte[] nGramTermBytes = StringUtils.stringToBinary(shouldTruncateNGram ? term.substring(0, nGramCharacters) : term);
final List<SinglePartitionQueryRanges> retVal = new ArrayList<>(1 + (isForwardIndexed ? 1 : 0));
final SinglePartitionQueryRanges ngramRange = new SinglePartitionQueryRanges(caseSensitive ? NGRAM_INDEX_CASE_SENSITIVE_PARTITION_KEY : NGRAM_INDEX_CASE_INSENSITIVE_PARTITION_KEY, Collections.singletonList(new ByteArrayRange(nGramTermBytes, nGramTermBytes)));
retVal.add(ngramRange);
if (isForwardIndexed) {
final byte[] forwardTermBytes = shouldTruncateNGram ? StringUtils.stringToBinary(term) : nGramTermBytes;
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.QueryRanges in project geowave by locationtech.
the class TieredSFCIndexStrategy method getQueryRanges.
@Override
public QueryRanges getQueryRanges(final MultiDimensionalNumericData indexedRange, final int maxRangeDecomposition, final IndexMetaData... hints) {
// TODO don't just pass max ranges along to the SFC, take tiering and
// binning into account to limit the number of ranges correctly
final List<SinglePartitionQueryRanges> queryRanges = new ArrayList<>();
final List<BinnedNumericDataset> binnedQueries = BinnedNumericDataset.applyBins(indexedRange, baseDefinitions);
final TierIndexMetaData metaData = ((hints.length > 0) && (hints[0] != null) && (hints[0] instanceof TierIndexMetaData)) ? (TierIndexMetaData) hints[0] : null;
for (int sfcIndex = orderedSfcs.length - 1; sfcIndex >= 0; sfcIndex--) {
if ((metaData != null) && (metaData.tierCounts[sfcIndex] == 0)) {
continue;
}
final SpaceFillingCurve sfc = orderedSfcs[sfcIndex];
final Byte tier = orderedSfcIndexToTierId.get(sfcIndex);
queryRanges.addAll(BinnedSFCUtils.getQueryRanges(binnedQueries, sfc, // for
maxRangeDecomposition, // dividing by the tiers
tier));
}
return new QueryRanges(queryRanges);
}
use of org.locationtech.geowave.core.index.QueryRanges in project geowave by locationtech.
the class DataStoreUtils method constraintsToQueryRanges.
public static QueryRanges constraintsToQueryRanges(final List<MultiDimensionalNumericData> constraints, final Index index, final double[] targetResolutionPerDimensionForHierarchicalIndex, final int maxRanges, final IndexMetaData... hints) {
if ((index instanceof CustomIndex) && (constraints != null) && (constraints.size() == 1) && (constraints.get(0) instanceof InternalCustomConstraints)) {
return ((CustomIndex) index).getQueryRanges(((InternalCustomConstraints) constraints.get(0)).getCustomConstraints());
}
NumericIndexStrategy indexStrategy = index.getIndexStrategy();
SubStrategy targetIndexStrategy = null;
if ((targetResolutionPerDimensionForHierarchicalIndex != null) && (targetResolutionPerDimensionForHierarchicalIndex.length == indexStrategy.getOrderedDimensionDefinitions().length)) {
// determine the correct tier to query for the given resolution
final HierarchicalNumericIndexStrategy strategy = CompoundHierarchicalIndexStrategyWrapper.findHierarchicalStrategy(indexStrategy);
if (strategy != null) {
final TreeMap<Double, SubStrategy> sortedStrategies = new TreeMap<>();
for (final SubStrategy subStrategy : strategy.getSubStrategies()) {
final double[] idRangePerDimension = subStrategy.getIndexStrategy().getHighestPrecisionIdRangePerDimension();
double rangeSum = 0;
for (final double range : idRangePerDimension) {
rangeSum += range;
}
// sort by the sum of the range in each dimension
sortedStrategies.put(rangeSum, subStrategy);
}
for (final SubStrategy subStrategy : sortedStrategies.descendingMap().values()) {
final double[] highestPrecisionIdRangePerDimension = subStrategy.getIndexStrategy().getHighestPrecisionIdRangePerDimension();
// if the id range is less than or equal to the target
// resolution in each dimension, use this substrategy
boolean withinTargetResolution = true;
for (int d = 0; d < highestPrecisionIdRangePerDimension.length; d++) {
if (highestPrecisionIdRangePerDimension[d] > targetResolutionPerDimensionForHierarchicalIndex[d]) {
withinTargetResolution = false;
break;
}
}
if (withinTargetResolution) {
targetIndexStrategy = subStrategy;
break;
}
}
if (targetIndexStrategy == null) {
// if there is not a substrategy that is within the target
// resolution, use the first substrategy (the lowest range
// per dimension, which is the highest precision)
targetIndexStrategy = sortedStrategies.firstEntry().getValue();
}
indexStrategy = targetIndexStrategy.getIndexStrategy();
}
}
if ((constraints == null) || constraints.isEmpty()) {
if (targetIndexStrategy != null) {
// at least use the prefix of a substrategy if chosen
return new QueryRanges(new byte[][] { targetIndexStrategy.getPrefix() });
}
// implies in negative and
return new QueryRanges();
// positive infinity
} else {
final List<QueryRanges> ranges = new ArrayList<>(constraints.size());
for (final MultiDimensionalNumericData nd : constraints) {
ranges.add(indexStrategy.getQueryRanges(nd, maxRanges, hints));
}
return ranges.size() > 1 ? new QueryRanges(ranges) : ranges.get(0);
}
}
use of org.locationtech.geowave.core.index.QueryRanges in project geowave by locationtech.
the class MapReduceMemoryOperations method createReader.
@Override
public RowReader<GeoWaveRow> createReader(final RecordReaderParams readerParams) {
final byte[] partitionKey = readerParams.getRowRange().getPartitionKey() == null ? new byte[0] : readerParams.getRowRange().getPartitionKey();
final ByteArrayRange sortRange = new ByteArrayRange(readerParams.getRowRange().getStartSortKey() == null ? new byte[0] : readerParams.getRowRange().getStartSortKey(), readerParams.getRowRange().getEndSortKey() == null ? new byte[0] : readerParams.getRowRange().getEndSortKey());
return createReader(new ReaderParams(readerParams.getIndex(), readerParams.getAdapterStore(), readerParams.getAdapterIndexMappingStore(), readerParams.getInternalAdapterStore(), readerParams.getAdapterIds(), readerParams.getMaxResolutionSubsamplingPerDimension(), readerParams.getAggregation(), readerParams.getFieldSubsets(), readerParams.isMixedVisibility(), false, false, false, new QueryRanges(Collections.singleton(new SinglePartitionQueryRanges(partitionKey, Collections.singleton(sortRange)))), null, readerParams.getLimit(), readerParams.getMaxRangeDecomposition(), null, null, GeoWaveRowIteratorTransformer.NO_OP_TRANSFORMER, readerParams.getAdditionalAuthorizations()));
}
use of org.locationtech.geowave.core.index.QueryRanges in project geowave by locationtech.
the class SimpleNumericIndexStrategyTest method testGetQueryRangesPoint.
@Test
public void testGetQueryRangesPoint() {
final MultiDimensionalNumericData indexedRange = getIndexedRange(10l);
final QueryRanges ranges = strategy.getQueryRanges(indexedRange);
Assert.assertEquals(ranges.getCompositeQueryRanges().size(), 1);
final ByteArrayRange range = ranges.getCompositeQueryRanges().get(0);
final byte[] start = range.getStart();
final byte[] end = range.getEnd();
Assert.assertTrue(Arrays.equals(start, end));
Assert.assertEquals(10L, castToLong(strategy.getLexicoder().fromByteArray(start)));
}
Aggregations