Search in sources :

Example 1 with NumericValue

use of org.locationtech.geowave.core.index.numeric.NumericValue in project geowave by locationtech.

the class NumericFieldConstraints method generateNumericData.

private static void generateNumericData(final List<MultiDimensionalIndexData<Double>> results, final int currentDimension, final List<DimensionConstraints<Double>> dimensions, final NumericData[] current) {
    if (currentDimension == dimensions.size()) {
        results.add(new BasicNumericDataset(current));
        return;
    }
    final DimensionConstraints<Double> dimension = dimensions.get(currentDimension);
    final List<FilterRange<Double>> ranges = dimension.getRanges();
    for (int i = 0; i < ranges.size(); i++) {
        final NumericData[] copy = Arrays.copyOf(current, current.length + 1);
        final FilterRange<Double> range = ranges.get(i);
        final Double start = toStartRangeValue(range.getStart());
        final Double end = toEndRangeValue(range.getEnd());
        if (start.equals(end) && range.isStartInclusive() && range.isEndInclusive()) {
            copy[copy.length - 1] = new NumericValue(start);
        } else {
            copy[copy.length - 1] = new NumericRange(toStartRangeValue(range.getStart()), toEndRangeValue(range.getEnd()), range.isStartInclusive(), range.isEndInclusive());
        }
        generateNumericData(results, currentDimension + 1, dimensions, copy);
    }
}
Also used : NumericRange(org.locationtech.geowave.core.index.numeric.NumericRange) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) FilterRange(org.locationtech.geowave.core.store.query.filter.expression.FilterRange) NumericValue(org.locationtech.geowave.core.index.numeric.NumericValue)

Example 2 with NumericValue

use of org.locationtech.geowave.core.index.numeric.NumericValue in project geowave by locationtech.

the class GeometryUtils method basicConstraintsFromPoint.

/**
 * This utility method will convert a JTS envelope to that can be used in a GeoWave query.
 *
 * @return Constraints as a mapping of NumericData objects representing ranges for a latitude
 *         dimension and a longitude dimension
 */
public static ConstraintSet basicConstraintsFromPoint(final double latitudeDegrees, final double longitudeDegrees) {
    // Create a NumericData object using the x axis
    final NumericData latitude = new NumericValue(latitudeDegrees);
    // Create a NumericData object using the y axis
    final NumericData longitude = new NumericValue(longitudeDegrees);
    final Map<Class<? extends NumericDimensionDefinition>, ConstraintData> constraintsPerDimension = new HashMap<>();
    // Create and return a new IndexRange array with an x and y axis
    // range
    constraintsPerDimension.put(LongitudeDefinition.class, new ConstraintData(longitude, false));
    constraintsPerDimension.put(LatitudeDefinition.class, new ConstraintData(latitude, false));
    return new ConstraintSet(constraintsPerDimension);
}
Also used : ConstraintData(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData) HashMap(java.util.HashMap) NumericDimensionDefinition(org.locationtech.geowave.core.index.dimension.NumericDimensionDefinition) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) ConstraintsByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass) NumericValue(org.locationtech.geowave.core.index.numeric.NumericValue) ConstraintSet(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet)

Example 3 with NumericValue

use of org.locationtech.geowave.core.index.numeric.NumericValue in project geowave by locationtech.

the class IndexUtils method clampAtIndexBounds.

public static MultiDimensionalNumericData clampAtIndexBounds(final MultiDimensionalNumericData data, final NumericIndexStrategy indexStrategy) {
    final NumericDimensionDefinition[] dimensions = indexStrategy.getOrderedDimensionDefinitions();
    final NumericData[] dataPerDimension = data.getDataPerDimension();
    boolean clamped = false;
    for (int d = 0; d < dimensions.length; d++) {
        final NumericRange dimensionBounds = dimensions[d].getBounds();
        if (dataPerDimension[d].isRange()) {
            boolean dimensionClamped = false;
            double min, max;
            if (dataPerDimension[d].getMin() < dimensionBounds.getMin()) {
                min = dimensionBounds.getMin();
                dimensionClamped = true;
            } else {
                min = dataPerDimension[d].getMin();
            }
            if (dataPerDimension[d].getMax() > dimensionBounds.getMax()) {
                max = dimensionBounds.getMax();
                dimensionClamped = true;
            } else {
                max = dataPerDimension[d].getMax();
            }
            if (dimensionClamped) {
                dataPerDimension[d] = new NumericRange(min, max);
                clamped = true;
            }
        } else if ((dataPerDimension[d].getMin() < dimensionBounds.getMin()) || (dataPerDimension[d].getMin() > dimensionBounds.getMax())) {
            dataPerDimension[d] = new NumericValue(Math.max(Math.min(dataPerDimension[d].getMin(), dimensionBounds.getMax()), dimensionBounds.getMin()));
            clamped = true;
        }
    }
    if (clamped) {
        return new BasicNumericDataset(dataPerDimension);
    }
    return data;
}
Also used : NumericRange(org.locationtech.geowave.core.index.numeric.NumericRange) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) NumericDimensionDefinition(org.locationtech.geowave.core.index.dimension.NumericDimensionDefinition) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) NumericValue(org.locationtech.geowave.core.index.numeric.NumericValue)

Example 4 with NumericValue

use of org.locationtech.geowave.core.index.numeric.NumericValue in project geowave by locationtech.

the class DistributedQueryFilterTest method test.

@Test
public void test() {
    List<QueryFilter> filters = new ArrayList<>();
    filters.add(new BasicQueryFilter(new BasicNumericDataset(new NumericData[] { new NumericValue(0.4) }), new NumericDimensionField[] { new BasicQueryByClassTest.ExampleDimensionOne() }, BasicQueryCompareOperation.CONTAINS));
    filters.add(new DedupeFilter());
    FilterList list = new FilterList(false, filters);
    list.fromBinary(list.toBinary());
    assertFalse(list.logicalAnd);
    assertEquals(((BasicQueryFilter) list.filters.get(0)).compareOp, BasicQueryCompareOperation.CONTAINS);
    assertEquals(((BasicQueryFilter) list.filters.get(0)).constraints, new BasicNumericDataset(new NumericData[] { new NumericRange(0.4, 0.4) }));
    filters = new ArrayList<>();
    filters.add(new BasicQueryFilter(new BasicNumericDataset(new NumericData[] { new NumericValue(0.5) }), new NumericDimensionField[] { new BasicQueryByClassTest.ExampleDimensionOne() }, BasicQueryCompareOperation.INTERSECTS));
    filters.add(new DedupeFilter());
    list = new FilterList(true, filters);
    list.fromBinary(list.toBinary());
    assertTrue(list.logicalAnd);
    assertEquals(((BasicQueryFilter) list.filters.get(0)).compareOp, BasicQueryCompareOperation.INTERSECTS);
    assertEquals(((BasicQueryFilter) list.filters.get(0)).constraints, new BasicNumericDataset(new NumericData[] { new NumericRange(0.5, 0.5) }));
}
Also used : NumericDimensionField(org.locationtech.geowave.core.store.dimension.NumericDimensionField) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) ArrayList(java.util.ArrayList) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) NumericRange(org.locationtech.geowave.core.index.numeric.NumericRange) NumericValue(org.locationtech.geowave.core.index.numeric.NumericValue) Test(org.junit.Test) BasicQueryByClassTest(org.locationtech.geowave.core.store.query.BasicQueryByClassTest)

Example 5 with NumericValue

use of org.locationtech.geowave.core.index.numeric.NumericValue in project geowave by locationtech.

the class ChooseBestMatchIndexQueryStrategyTest method testChooseSpatialTemporalWithStats.

@Test
public void testChooseSpatialTemporalWithStats() {
    final Index temporalindex = new SpatialTemporalIndexBuilder().createIndex();
    final Index spatialIndex = new SpatialIndexBuilder().createIndex();
    final RowRangeHistogramStatistic rangeTempStats = new RowRangeHistogramStatistic(temporalindex.getName());
    rangeTempStats.setBinningStrategy(new CompositeBinningStrategy(new DataTypeBinningStrategy(), new PartitionBinningStrategy()));
    rangeTempStats.setInternal();
    final RowRangeHistogramStatistic rangeStats = new RowRangeHistogramStatistic(spatialIndex.getName());
    rangeStats.setBinningStrategy(new CompositeBinningStrategy(new DataTypeBinningStrategy(), new PartitionBinningStrategy()));
    rangeStats.setInternal();
    final Map<StatisticId<?>, Map<ByteArray, StatisticValue<?>>> statsMap = new HashMap<>();
    final ChooseBestMatchIndexQueryStrategy strategy = new ChooseBestMatchIndexQueryStrategy();
    final ConstraintSet cs1 = new ConstraintSet();
    cs1.addConstraint(LatitudeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0.3, 0.5), true));
    cs1.addConstraint(LongitudeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0.4, 0.7), true));
    final ConstraintSet cs2a = new ConstraintSet();
    cs2a.addConstraint(TimeDefinition.class, new ConstraintData(new ConstrainedIndexValue(0.1, 0.2), true));
    final ConstraintsByClass constraints = new ConstraintsByClass(Arrays.asList(cs2a)).merge(Collections.singletonList(cs1));
    final BasicQueryByClass query = new BasicQueryByClass(constraints);
    final NumericIndexStrategy temporalIndexStrategy = new SpatialTemporalIndexBuilder().createIndex().getIndexStrategy();
    final Random r = new Random(SEED);
    for (int i = 0; i < ROWS; i++) {
        final double x = r.nextDouble();
        final double y = r.nextDouble();
        final double t = r.nextDouble();
        final InsertionIds id = temporalIndexStrategy.getInsertionIds(new BasicNumericDataset(new NumericData[] { new NumericValue(x), new NumericValue(y), new NumericValue(t) }));
        for (final SinglePartitionInsertionIds range : id.getPartitionKeys()) {
            Map<ByteArray, StatisticValue<?>> binValues = statsMap.get(rangeTempStats.getId());
            if (binValues == null) {
                binValues = Maps.newHashMap();
                statsMap.put(rangeTempStats.getId(), binValues);
            }
            final ByteArray bin = CompositeBinningStrategy.getBin(DataTypeBinningStrategy.getBin((String) null), PartitionBinningStrategy.getBin(range.getPartitionKey()));
            RowRangeHistogramValue value = (RowRangeHistogramValue) binValues.get(bin);
            if (value == null) {
                value = rangeTempStats.createEmpty();
                value.setBin(bin);
                binValues.put(bin, value);
            }
            ((StatisticsIngestCallback) value).entryIngested(null, null, new GeoWaveRowImpl(new GeoWaveKeyImpl(new byte[] { 1 }, (short) 1, range.getPartitionKey(), range.getSortKeys().get(0), 0), new GeoWaveValue[] {}));
        }
    }
    final Index index = new SpatialIndexBuilder().createIndex();
    final NumericIndexStrategy indexStrategy = index.getIndexStrategy();
    for (int i = 0; i < ROWS; i++) {
        final double x = r.nextDouble();
        final double y = r.nextDouble();
        final double t = r.nextDouble();
        final InsertionIds id = indexStrategy.getInsertionIds(new BasicNumericDataset(new NumericData[] { new NumericValue(x), new NumericValue(y), new NumericValue(t) }));
        for (final SinglePartitionInsertionIds range : id.getPartitionKeys()) {
            Map<ByteArray, StatisticValue<?>> binValues = statsMap.get(rangeStats.getId());
            if (binValues == null) {
                binValues = Maps.newHashMap();
                statsMap.put(rangeStats.getId(), binValues);
            }
            final ByteArray bin = CompositeBinningStrategy.getBin(DataTypeBinningStrategy.getBin((String) null), PartitionBinningStrategy.getBin(range.getPartitionKey()));
            RowRangeHistogramValue value = (RowRangeHistogramValue) binValues.get(bin);
            if (value == null) {
                value = rangeStats.createEmpty();
                value.setBin(bin);
                binValues.put(bin, value);
            }
            ((StatisticsIngestCallback) value).entryIngested(null, null, new GeoWaveRowImpl(new GeoWaveKeyImpl(new byte[] { 1 }, (short) 1, range.getPartitionKey(), range.getSortKeys().get(0), 0), new GeoWaveValue[] {}));
        }
    }
    final Iterator<Index> it = getIndices(new TestDataStatisticsStore(Lists.newArrayList(rangeStats, rangeTempStats), statsMap), query, strategy);
    assertTrue(it.hasNext());
    assertEquals(temporalindex.getName(), it.next().getName());
    assertFalse(it.hasNext());
}
Also used : SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) StatisticValue(org.locationtech.geowave.core.store.api.StatisticValue) HashMap(java.util.HashMap) BasicNumericDataset(org.locationtech.geowave.core.index.numeric.BasicNumericDataset) StatisticId(org.locationtech.geowave.core.store.statistics.StatisticId) NumericData(org.locationtech.geowave.core.index.numeric.NumericData) NullIndex(org.locationtech.geowave.core.store.index.NullIndex) Index(org.locationtech.geowave.core.store.api.Index) GeoWaveValue(org.locationtech.geowave.core.store.entities.GeoWaveValue) ConstraintsByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass) RowRangeHistogramStatistic(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic) Random(java.util.Random) SpatialIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder) InsertionIds(org.locationtech.geowave.core.index.InsertionIds) SinglePartitionInsertionIds(org.locationtech.geowave.core.index.SinglePartitionInsertionIds) ByteArray(org.locationtech.geowave.core.index.ByteArray) StatisticsIngestCallback(org.locationtech.geowave.core.store.statistics.StatisticsIngestCallback) ConstraintData(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData) RowRangeHistogramValue(org.locationtech.geowave.core.store.statistics.index.RowRangeHistogramStatistic.RowRangeHistogramValue) DataTypeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.DataTypeBinningStrategy) ConstraintSet(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet) GeoWaveRowImpl(org.locationtech.geowave.core.store.entities.GeoWaveRowImpl) CompositeBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.CompositeBinningStrategy) GeoWaveKeyImpl(org.locationtech.geowave.core.store.entities.GeoWaveKeyImpl) SpatialTemporalIndexBuilder(org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder) PartitionBinningStrategy(org.locationtech.geowave.core.store.statistics.binning.PartitionBinningStrategy) NumericValue(org.locationtech.geowave.core.index.numeric.NumericValue) Map(java.util.Map) HashMap(java.util.HashMap) BasicQueryByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass) NumericIndexStrategy(org.locationtech.geowave.core.index.NumericIndexStrategy) Test(org.junit.Test)

Aggregations

NumericValue (org.locationtech.geowave.core.index.numeric.NumericValue)7 NumericData (org.locationtech.geowave.core.index.numeric.NumericData)6 BasicNumericDataset (org.locationtech.geowave.core.index.numeric.BasicNumericDataset)5 Test (org.junit.Test)4 MultiDimensionalNumericData (org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData)3 NumericRange (org.locationtech.geowave.core.index.numeric.NumericRange)3 HashMap (java.util.HashMap)2 InsertionIds (org.locationtech.geowave.core.index.InsertionIds)2 NumericIndexStrategy (org.locationtech.geowave.core.index.NumericIndexStrategy)2 NumericDimensionDefinition (org.locationtech.geowave.core.index.dimension.NumericDimensionDefinition)2 ConstraintData (org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintData)2 ConstraintSet (org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintSet)2 ConstraintsByClass (org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 Random (java.util.Random)1 SpatialTemporalOptions (org.locationtech.geowave.core.geotime.index.SpatialTemporalOptions)1 SpatialIndexBuilder (org.locationtech.geowave.core.geotime.index.api.SpatialIndexBuilder)1 SpatialTemporalIndexBuilder (org.locationtech.geowave.core.geotime.index.api.SpatialTemporalIndexBuilder)1