Search in sources :

Example 1 with TimeRangeValue

use of org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue in project geowave by locationtech.

the class QueryIndexHelperTest method testComposeQueryWithTimeRange.

@Test
public void testComposeQueryWithTimeRange() throws ParseException {
    final TestStatisticsCache statsCache = new TestStatisticsCache();
    final TimeRangeStatistic startStats = new TimeRangeStatistic("type", "start");
    final TimeRangeValue startValue = startStats.createEmpty();
    statsCache.putFieldStatistic(TimeRangeStatistic.STATS_TYPE, "start", startValue);
    final TimeRangeStatistic endStats = new TimeRangeStatistic("type", "end");
    final TimeRangeValue endValue = endStats.createEmpty();
    statsCache.putFieldStatistic(TimeRangeStatistic.STATS_TYPE, "end", endValue);
    final Date statsStart1 = DateUtilities.parseISO("2005-05-18T20:32:56Z");
    final Date statsStart2 = DateUtilities.parseISO("2005-05-20T20:32:56Z");
    final Date statsEnd1 = DateUtilities.parseISO("2005-05-21T20:32:56Z");
    final Date statsEnd2 = DateUtilities.parseISO("2005-05-24T20:32:56Z");
    final SimpleFeature firstRangFeature = createFeature(statsStart1, statsEnd1);
    FeatureDataAdapter adapter = new FeatureDataAdapter(firstRangFeature.getFeatureType());
    startValue.entryIngested(adapter, firstRangFeature);
    endValue.entryIngested(adapter, firstRangFeature);
    final SimpleFeature secondRangFeature = createFeature(statsStart2, statsEnd2);
    startValue.entryIngested(adapter, secondRangFeature);
    endValue.entryIngested(adapter, secondRangFeature);
    final Date stime = DateUtilities.parseISO("2005-05-18T20:32:56Z");
    final Date etime = DateUtilities.parseISO("2005-05-19T20:32:56Z");
    final TemporalConstraintsSet constraintsSet = new TemporalConstraintsSet();
    constraintsSet.getConstraintsForRange("start", "end").add(new TemporalRange(stime, etime));
    final BasicQueryByClass query = new BasicQueryByClass(QueryIndexHelper.composeConstraints(statsCache, rangeType, rangeTimeDescriptors, factory.toGeometry(factory.createPoint(new Coordinate(27.25, 41.25)).getEnvelopeInternal()), constraintsSet));
    final List<MultiDimensionalNumericData> nd = query.getIndexConstraints(SPATIAL_TEMPORAL_INDEX);
    assertEquals(stime.getTime(), nd.get(0).getDataPerDimension()[2].getMin().longValue());
    assertEquals(etime.getTime(), nd.get(0).getDataPerDimension()[2].getMax().longValue());
    final BasicQueryByClass query1 = new BasicQueryByClass(QueryIndexHelper.composeConstraints(statsCache, rangeType, rangeTimeDescriptors, factory.toGeometry(factory.createPoint(new Coordinate(27.25, 41.25)).getEnvelopeInternal()), null));
    final List<MultiDimensionalNumericData> nd1 = query1.getIndexConstraints(SPATIAL_TEMPORAL_INDEX);
    assertEquals(statsStart1.getTime(), nd1.get(0).getDataPerDimension()[2].getMin().longValue());
    assertEquals(statsEnd2.getTime(), nd1.get(0).getDataPerDimension()[2].getMax().longValue());
}
Also used : MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) Coordinate(org.locationtech.jts.geom.Coordinate) TemporalConstraintsSet(org.locationtech.geowave.core.geotime.store.query.TemporalConstraintsSet) TemporalRange(org.locationtech.geowave.core.geotime.store.query.TemporalRange) TimeRangeStatistic(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic) TimeRangeValue(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) Date(java.util.Date) SimpleFeature(org.opengis.feature.simple.SimpleFeature) BasicQueryByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass) Test(org.junit.Test)

Example 2 with TimeRangeValue

use of org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue in project geowave by locationtech.

the class QueryIndexHelperTest method testComposeSubsetConstraints.

@Test
public void testComposeSubsetConstraints() throws ParseException {
    final TestStatisticsCache statsCache = new TestStatisticsCache();
    final TimeRangeStatistic startStats = new TimeRangeStatistic("type", "start");
    final TimeRangeValue startValue = startStats.createEmpty();
    statsCache.putFieldStatistic(TimeRangeStatistic.STATS_TYPE, "start", startValue);
    final TimeRangeStatistic endStats = new TimeRangeStatistic("type", "end");
    final TimeRangeValue endValue = endStats.createEmpty();
    statsCache.putFieldStatistic(TimeRangeStatistic.STATS_TYPE, "end", endValue);
    final Date statsStart1 = DateUtilities.parseISO("2005-05-18T20:32:56Z");
    final Date statsStart2 = DateUtilities.parseISO("2005-05-20T20:32:56Z");
    final Date statsEnd1 = DateUtilities.parseISO("2005-05-21T20:32:56Z");
    final Date statsEnd2 = DateUtilities.parseISO("2005-05-24T20:32:56Z");
    final SimpleFeature firstRangFeature = createFeature(statsStart1, statsEnd1);
    FeatureDataAdapter adapter = new FeatureDataAdapter(firstRangFeature.getFeatureType());
    startValue.entryIngested(adapter, firstRangFeature);
    endValue.entryIngested(adapter, firstRangFeature);
    final SimpleFeature secondRangFeature = createFeature(statsStart2, statsEnd2);
    startValue.entryIngested(adapter, secondRangFeature);
    endValue.entryIngested(adapter, secondRangFeature);
    final Date stime = DateUtilities.parseISO("2005-05-18T20:32:56Z");
    final Date etime = DateUtilities.parseISO("2005-05-19T20:32:56Z");
    final TemporalConstraintsSet constraintsSet = new TemporalConstraintsSet();
    constraintsSet.getConstraintsForRange("start", "end").add(new TemporalRange(stime, etime));
    final Constraints constraints = QueryIndexHelper.composeTimeBoundedConstraints(rangeType, rangeTimeDescriptors, constraintsSet);
    final List<MultiDimensionalNumericData> nd = constraints.getIndexConstraints(SPATIAL_TEMPORAL_INDEX);
    assertTrue(nd.isEmpty());
    final BoundingBoxStatistic geoStats = new BoundingBoxStatistic("type", "geometry");
    final BoundingBoxValue geoValue = geoStats.createEmpty();
    statsCache.putFieldStatistic(BoundingBoxStatistic.STATS_TYPE, "geometry", geoValue);
    final SimpleFeature firstFeature = createGeoFeature(factory.createPoint(new Coordinate(22.25, 42.25)));
    geoValue.entryIngested(adapter, firstFeature);
    final SimpleFeature secondFeature = createGeoFeature(factory.createPoint(new Coordinate(27.25, 41.25)));
    geoValue.entryIngested(adapter, secondFeature);
    final Constraints constraints1 = QueryIndexHelper.composeConstraints(statsCache, rangeType, rangeTimeDescriptors, null, constraintsSet);
    final List<MultiDimensionalNumericData> nd1 = constraints1.getIndexConstraints(SPATIAL_TEMPORAL_INDEX);
    assertTrue(nd1.isEmpty());
    /*
     * assertEquals( stime.getTime(), (long) nd1.get( 0).getDataPerDimension()[2].getMin());
     * assertEquals( etime.getTime(), (long) nd1.get( 0).getDataPerDimension()[2].getMax());
     */
    final TemporalConstraintsSet constraintsSet2 = new TemporalConstraintsSet();
    constraintsSet2.getConstraintsForRange("start", "end").add(new TemporalRange(statsStart1, statsEnd2));
    final Constraints constraints2 = QueryIndexHelper.composeTimeBoundedConstraints(rangeType, rangeTimeDescriptors, constraintsSet2);
    final List<MultiDimensionalNumericData> nd2 = constraints2.getIndexConstraints(SPATIAL_TEMPORAL_INDEX);
    assertTrue(nd2.isEmpty());
}
Also used : BoundingBoxStatistic(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic) MultiDimensionalNumericData(org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData) TemporalConstraintsSet(org.locationtech.geowave.core.geotime.store.query.TemporalConstraintsSet) BoundingBoxValue(org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic.BoundingBoxValue) Date(java.util.Date) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Constraints(org.locationtech.geowave.core.store.query.constraints.Constraints) TemporalConstraints(org.locationtech.geowave.core.geotime.store.query.TemporalConstraints) Coordinate(org.locationtech.jts.geom.Coordinate) TemporalRange(org.locationtech.geowave.core.geotime.store.query.TemporalRange) TimeRangeStatistic(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic) TimeRangeValue(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) Test(org.junit.Test)

Example 3 with TimeRangeValue

use of org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue in project geowave by locationtech.

the class QueryIndexHelperTest method testGetTemporalConstraintsForSingleClippedRange.

@Test
public void testGetTemporalConstraintsForSingleClippedRange() throws ParseException {
    final Date stime = DateUtilities.parseISO("2005-05-14T20:32:56Z");
    final Date etime = DateUtilities.parseISO("2005-05-18T20:32:56Z");
    final Date stime1 = DateUtilities.parseISO("2005-05-18T20:32:56Z");
    final Date etime1 = DateUtilities.parseISO("2005-05-19T20:32:56Z");
    final TestStatisticsCache statsCache = new TestStatisticsCache();
    final TimeRangeStatistic whenStats = new TimeRangeStatistic(singleType.getTypeName(), "when");
    final TimeRangeValue whenValue = whenStats.createEmpty();
    statsCache.putFieldStatistic(TimeRangeStatistic.STATS_TYPE, "when", whenValue);
    final TemporalConstraintsSet constraintsSet = new TemporalConstraintsSet();
    constraintsSet.getConstraintsFor("when").add(new TemporalRange(stime, etime));
    final FeatureDataAdapter singleDataAdapter = new FeatureDataAdapter(singleType);
    final SimpleFeature notIntersectSingle1 = createSingleTimeFeature(startTime);
    whenValue.entryIngested(singleDataAdapter, notIntersectSingle1);
    final SimpleFeature notIntersectSingle = createSingleTimeFeature(endTime);
    whenValue.entryIngested(singleDataAdapter, notIntersectSingle);
    final TemporalConstraintsSet resultConstraintsSet = QueryIndexHelper.clipIndexedTemporalConstraints(statsCache, singleTimeDescriptors, constraintsSet);
    final TemporalConstraints constraints = resultConstraintsSet.getConstraintsFor("when");
    assertEquals(1, constraints.getRanges().size());
    assertEquals(startTime, constraints.getStartRange().getStartTime());
    assertEquals(etime, constraints.getStartRange().getEndTime());
    final TemporalConstraintsSet constraintsSet1 = new TemporalConstraintsSet();
    constraintsSet1.getConstraintsFor("when").add(new TemporalRange(stime1, etime1));
    final TemporalConstraintsSet resultConstraintsSet1 = QueryIndexHelper.clipIndexedTemporalConstraints(statsCache, singleTimeDescriptors, constraintsSet1);
    final TemporalConstraints constraints1 = resultConstraintsSet1.getConstraintsFor("when");
    assertEquals(1, constraints1.getRanges().size());
    assertEquals(stime1, constraints1.getStartRange().getStartTime());
    assertEquals(etime1, constraints1.getStartRange().getEndTime());
}
Also used : TemporalConstraintsSet(org.locationtech.geowave.core.geotime.store.query.TemporalConstraintsSet) TemporalRange(org.locationtech.geowave.core.geotime.store.query.TemporalRange) TemporalConstraints(org.locationtech.geowave.core.geotime.store.query.TemporalConstraints) TimeRangeStatistic(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic) TimeRangeValue(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) Date(java.util.Date) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 4 with TimeRangeValue

use of org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue in project geowave by locationtech.

the class TemporalRangeTest method test.

@Test
public void test() throws ParseException, IOException {
    final Calendar gmt = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    final Calendar local = Calendar.getInstance(TimeZone.getTimeZone("EDT"));
    local.setTimeInMillis(gmt.getTimeInMillis());
    final TemporalRange rGmt = new TemporalRange(gmt.getTime(), gmt.getTime());
    final TemporalRange rLocal = new TemporalRange(local.getTime(), local.getTime());
    rGmt.fromBinary(rGmt.toBinary());
    assertEquals(gmt.getTime(), rGmt.getEndTime());
    assertEquals(rLocal.getEndTime(), rGmt.getEndTime());
    assertEquals(rLocal.getEndTime().getTime(), rGmt.getEndTime().getTime());
    final Transaction transaction1 = new DefaultTransaction();
    final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1);
    final SimpleFeature newFeature = writer.next();
    newFeature.setAttribute("pop", Long.valueOf(77));
    newFeature.setAttribute("pid", UUID.randomUUID().toString());
    newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-19T19:32:56-04:00"));
    newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232)));
    FeatureDataAdapter adapter = new FeatureDataAdapter(type);
    final TimeRangeStatistic stats = new TimeRangeStatistic(type.getTypeName(), "when");
    final TimeRangeValue statValue = stats.createEmpty();
    statValue.entryIngested(adapter, newFeature);
    assertEquals(DateUtilities.parseISO("2005-05-19T23:32:56Z"), statValue.asTemporalRange().getStartTime());
    writer.close();
    transaction1.close();
}
Also used : Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(org.locationtech.jts.geom.Coordinate) Calendar(java.util.Calendar) TemporalRange(org.locationtech.geowave.core.geotime.store.query.TemporalRange) FeatureDataAdapter(org.locationtech.geowave.adapter.vector.FeatureDataAdapter) TimeRangeStatistic(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic) TimeRangeValue(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeature(org.opengis.feature.simple.SimpleFeature) BaseDataStoreTest(org.locationtech.geowave.adapter.vector.BaseDataStoreTest) Test(org.junit.Test)

Example 5 with TimeRangeValue

use of org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue in project geowave by locationtech.

the class BinaryTemporalPredicate method getConstraints.

@SuppressWarnings("unchecked")
@Override
public <V extends Comparable<V>> FilterConstraints<V> getConstraints(final Class<V> constraintClass, final DataStatisticsStore statsStore, final DataTypeAdapter<?> adapter, final AdapterToIndexMapping indexMapping, final Index index, final Set<String> indexedFields) {
    if ((expression1 instanceof FieldValue) && indexedFields.contains(((FieldValue<?>) expression1).getFieldName()) && expression2.isLiteral() && constraintClass.isAssignableFrom(Double.class)) {
        final Double minValue;
        final Double maxValue;
        if (index.getIndexStrategy() instanceof SimpleNumericIndexStrategy) {
            minValue = null;
            maxValue = null;
        } else {
            final TimeRangeValue timeRange = InternalStatisticsHelper.getFieldStatistic(statsStore, TimeRangeStatistic.STATS_TYPE, adapter.getTypeName(), ((FieldValue<?>) expression1).getFieldName());
            if (timeRange != null) {
                minValue = (double) timeRange.getMin();
                maxValue = (double) timeRange.getMax();
            } else {
                // We cannot determine the query range for the binned
                return FilterConstraints.empty();
            }
        }
        String fieldName = ((FieldValue<?>) expression1).getFieldName();
        final boolean partOfRange = isPartOfRange(fieldName, indexMapping);
        final Interval literal = expression2.evaluateValue(null, null);
        if (literal != null) {
            return FilterConstraints.of(adapter, indexMapping, index, fieldName, (IndexFieldConstraints<V>) getConstraints(literal, minValue, maxValue, false, !partOfRange && index.getIndexStrategy() instanceof SimpleNumericIndexStrategy));
        }
    } else if ((expression2 instanceof FieldValue) && indexedFields.contains(((FieldValue<?>) expression2).getFieldName()) && expression1.isLiteral() && constraintClass.isAssignableFrom(Double.class)) {
        final Double minValue;
        final Double maxValue;
        if (index.getIndexStrategy() instanceof SimpleNumericIndexStrategy) {
            minValue = null;
            maxValue = null;
        } else {
            final TimeRangeValue timeRange = InternalStatisticsHelper.getFieldStatistic(statsStore, TimeRangeStatistic.STATS_TYPE, adapter.getTypeName(), ((FieldValue<?>) expression2).getFieldName());
            if (timeRange != null) {
                minValue = (double) timeRange.getMin();
                maxValue = (double) timeRange.getMax();
            } else {
                // We cannot determine the query range for the binned
                return FilterConstraints.empty();
            }
        }
        String fieldName = ((FieldValue<?>) expression2).getFieldName();
        final boolean partOfRange = isPartOfRange(fieldName, indexMapping);
        final Interval literal = expression1.evaluateValue(null, null);
        if (literal != null) {
            return FilterConstraints.of(adapter, indexMapping, index, fieldName, (IndexFieldConstraints<V>) getConstraints(literal, minValue, maxValue, true, !partOfRange && index.getIndexStrategy() instanceof SimpleNumericIndexStrategy));
        }
    }
    return FilterConstraints.empty();
}
Also used : SimpleNumericIndexStrategy(org.locationtech.geowave.core.index.simple.SimpleNumericIndexStrategy) IndexFieldConstraints(org.locationtech.geowave.core.store.query.filter.expression.IndexFieldConstraints) FieldValue(org.locationtech.geowave.core.store.query.filter.expression.FieldValue) TimeRangeValue(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue) Interval(org.threeten.extra.Interval)

Aggregations

TimeRangeValue (org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue)9 TimeRangeStatistic (org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic)8 Date (java.util.Date)6 TemporalRange (org.locationtech.geowave.core.geotime.store.query.TemporalRange)6 Test (org.junit.Test)5 FeatureDataAdapter (org.locationtech.geowave.adapter.vector.FeatureDataAdapter)5 SimpleFeature (org.opengis.feature.simple.SimpleFeature)5 TemporalConstraintsSet (org.locationtech.geowave.core.geotime.store.query.TemporalConstraintsSet)4 TemporalConstraints (org.locationtech.geowave.core.geotime.store.query.TemporalConstraints)3 Coordinate (org.locationtech.jts.geom.Coordinate)3 BoundingBoxStatistic (org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic)2 BoundingBoxValue (org.locationtech.geowave.core.geotime.store.statistics.BoundingBoxStatistic.BoundingBoxValue)2 MultiDimensionalNumericData (org.locationtech.geowave.core.index.numeric.MultiDimensionalNumericData)2 DataStatisticsStore (org.locationtech.geowave.core.store.statistics.DataStatisticsStore)2 NumericRangeStatistic (org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic)2 NumericRangeValue (org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic.NumericRangeValue)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 List (java.util.List)1