Search in sources :

Example 11 with QueryRanges

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);
}
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 12 with QueryRanges

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);
}
Also used : SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) QueryRanges(org.locationtech.geowave.core.index.QueryRanges) BinnedNumericDataset(org.locationtech.geowave.core.index.numeric.BinnedNumericDataset) SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) ArrayList(java.util.ArrayList) SpaceFillingCurve(org.locationtech.geowave.core.index.sfc.SpaceFillingCurve)

Example 13 with 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);
    }
}
Also used : SubStrategy(org.locationtech.geowave.core.index.HierarchicalNumericIndexStrategy.SubStrategy) SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) QueryRanges(org.locationtech.geowave.core.index.QueryRanges) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) HierarchicalNumericIndexStrategy(org.locationtech.geowave.core.index.HierarchicalNumericIndexStrategy) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) CustomIndex(org.locationtech.geowave.core.store.index.CustomIndex) InternalCustomConstraints(org.locationtech.geowave.core.store.query.constraints.CustomQueryConstraints.InternalCustomConstraints) HierarchicalNumericIndexStrategy(org.locationtech.geowave.core.index.HierarchicalNumericIndexStrategy) NumericIndexStrategy(org.locationtech.geowave.core.index.NumericIndexStrategy)

Example 14 with QueryRanges

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()));
}
Also used : SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) QueryRanges(org.locationtech.geowave.core.index.QueryRanges) RecordReaderParams(org.locationtech.geowave.mapreduce.splits.RecordReaderParams) ReaderParams(org.locationtech.geowave.core.store.operations.ReaderParams) SinglePartitionQueryRanges(org.locationtech.geowave.core.index.SinglePartitionQueryRanges) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange)

Example 15 with QueryRanges

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)));
}
Also used : MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) QueryRanges(org.locationtech.geowave.core.index.QueryRanges) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange) Test(org.junit.Test)

Aggregations

QueryRanges (org.locationtech.geowave.core.index.QueryRanges)15 ByteArrayRange (org.locationtech.geowave.core.index.ByteArrayRange)9 SinglePartitionQueryRanges (org.locationtech.geowave.core.index.SinglePartitionQueryRanges)8 ArrayList (java.util.ArrayList)6 MultiDimensionalNumericData (org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData)4 Index (org.locationtech.geowave.core.store.api.Index)3 Test (org.junit.Test)2 NumericIndexStrategy (org.locationtech.geowave.core.index.NumericIndexStrategy)2 BinnedNumericDataset (org.locationtech.geowave.core.index.numeric.BinnedNumericDataset)2 RowRangeHistogramStatistic (org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic)2 Sets (com.beust.jcommander.internal.Sets)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Closeable (java.io.Closeable)1 ByteBuffer (java.nio.ByteBuffer)1 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1