Search in sources :

Example 1 with ExtractAttributesFilter

use of org.locationtech.geowave.core.geotime.util.ExtractAttributesFilter in project geowave by locationtech.

the class GeoWaveFeatureReader method getSubset.

private String[] getSubset() {
    if (query == null) {
        return new String[0];
    }
    if ((query.getFilter() != null) && !components.getGTstore().getDataStoreOptions().isServerSideLibraryEnabled()) {
        final ExtractAttributesFilter attributesVisitor = new ExtractAttributesFilter();
        final Object obj = query.getFilter().accept(attributesVisitor, null);
        if ((obj != null) && (obj instanceof Collection)) {
            final Set<String> properties = Sets.newHashSet(query.getPropertyNames());
            for (final String prop : (Collection<String>) obj) {
                properties.add(prop);
            }
            return properties.toArray(new String[0]);
        }
    }
    return query.getPropertyNames();
}
Also used : Collection(java.util.Collection) ExtractAttributesFilter(org.locationtech.geowave.core.geotime.util.ExtractAttributesFilter)

Example 2 with ExtractAttributesFilter

use of org.locationtech.geowave.core.geotime.util.ExtractAttributesFilter in project geowave by locationtech.

the class GeoWaveGTPluginUtils method accepts.

protected static boolean accepts(final DataStatisticsStore statisticsStore, final DataTypeAdapter<?> adapter, final org.opengis.feature.FeatureVisitor visitor, final org.opengis.util.ProgressListener progress, final SimpleFeatureType featureType) throws IOException {
    if ((visitor instanceof MinVisitor)) {
        final ExtractAttributesFilter filter = new ExtractAttributesFilter();
        final MinVisitor minVisitor = (MinVisitor) visitor;
        final Collection<String> attrs = (Collection<String>) minVisitor.getExpression().accept(filter, null);
        int acceptedCount = 0;
        final Map<String, List<FieldStatistic<?>>> adapterFieldStatistics = getFieldStats(statisticsStore, adapter);
        for (final String attr : attrs) {
            if (!adapterFieldStatistics.containsKey(attr)) {
                continue;
            }
            for (final FieldStatistic<?> stat : adapterFieldStatistics.get(attr)) {
                if ((stat instanceof TimeRangeStatistic) && (stat.getBinningStrategy() == null)) {
                    final TimeRangeValue statValue = statisticsStore.getStatisticValue((TimeRangeStatistic) stat);
                    if (statValue != null) {
                        minVisitor.setValue(convertToType(attr, new Date(statValue.getMin()), featureType));
                        acceptedCount++;
                    }
                } else if (stat instanceof NumericRangeStatistic) {
                    try (CloseableIterator<NumericRangeValue> values = statisticsStore.getStatisticValues((NumericRangeStatistic) stat)) {
                        NumericRangeValue statValue = ((NumericRangeStatistic) stat).createEmpty();
                        while (values.hasNext()) {
                            statValue.merge(values.next());
                        }
                        if (statValue.isSet()) {
                            minVisitor.setValue(convertToType(attr, statValue.getMin(), featureType));
                            acceptedCount++;
                        }
                    }
                }
            }
        }
        if (acceptedCount > 0) {
            if (progress != null) {
                progress.complete();
            }
            return true;
        }
    } else if ((visitor instanceof MaxVisitor)) {
        final ExtractAttributesFilter filter = new ExtractAttributesFilter();
        final MaxVisitor maxVisitor = (MaxVisitor) visitor;
        final Collection<String> attrs = (Collection<String>) maxVisitor.getExpression().accept(filter, null);
        int acceptedCount = 0;
        final Map<String, List<FieldStatistic<?>>> adapterFieldStatistics = getFieldStats(statisticsStore, adapter);
        for (final String attr : attrs) {
            for (final FieldStatistic<?> stat : adapterFieldStatistics.get(attr)) {
                if ((stat instanceof TimeRangeStatistic) && (stat.getBinningStrategy() == null)) {
                    final TimeRangeValue statValue = statisticsStore.getStatisticValue((TimeRangeStatistic) stat);
                    if (statValue != null) {
                        maxVisitor.setValue(convertToType(attr, new Date(statValue.getMax()), featureType));
                        acceptedCount++;
                    }
                } else if (stat instanceof NumericRangeStatistic) {
                    try (CloseableIterator<NumericRangeValue> values = statisticsStore.getStatisticValues((NumericRangeStatistic) stat)) {
                        NumericRangeValue statValue = ((NumericRangeStatistic) stat).createEmpty();
                        while (values.hasNext()) {
                            statValue.merge(values.next());
                        }
                        if (statValue.isSet()) {
                            maxVisitor.setValue(convertToType(attr, statValue.getMax(), featureType));
                            acceptedCount++;
                        }
                    }
                }
            }
        }
        if (acceptedCount > 0) {
            if (progress != null) {
                progress.complete();
            }
            return true;
        }
    }
    return false;
}
Also used : CloseableIterator(org.locationtech.geowave.core.store.CloseableIterator) NumericRangeStatistic(org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic) MinVisitor(org.geotools.feature.visitor.MinVisitor) ExtractAttributesFilter(org.locationtech.geowave.core.geotime.util.ExtractAttributesFilter) Date(java.util.Date) MaxVisitor(org.geotools.feature.visitor.MaxVisitor) Collection(java.util.Collection) List(java.util.List) NumericRangeValue(org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic.NumericRangeValue) TimeRangeStatistic(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic) TimeRangeValue(org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue) Map(java.util.Map) FieldStatistic(org.locationtech.geowave.core.store.api.FieldStatistic)

Example 3 with ExtractAttributesFilter

use of org.locationtech.geowave.core.geotime.util.ExtractAttributesFilter in project geowave by locationtech.

the class OptimalCQLQuery method createOptimalQuery.

public static QueryConstraints createOptimalQuery(final Filter cqlFilter, final InternalGeotoolsFeatureDataAdapter<?> adapter, final CompareOperation geoCompareOp, final Index index, final AdapterToIndexMapping indexMapping, BasicQueryByClass baseQuery) {
    final ExtractAttributesFilter attributesVisitor = new ExtractAttributesFilter();
    final Object obj = cqlFilter.accept(attributesVisitor, null);
    final Collection<String> attrs;
    if ((obj != null) && (obj instanceof Collection)) {
        attrs = (Collection<String>) obj;
    } else {
        attrs = new ArrayList<>();
    }
    // assume the index can't handle spatial or temporal constraints if its
    // null
    final boolean isSpatial = IndexOptimizationUtils.hasAtLeastSpatial(index);
    final boolean isTemporal = IndexOptimizationUtils.hasTime(index, adapter);
    if (isSpatial) {
        final String geomName = adapter.getFeatureType().getGeometryDescriptor().getLocalName();
        attrs.remove(geomName);
    }
    if (isTemporal) {
        final TimeDescriptors timeDescriptors = adapter.getTimeDescriptors();
        if (timeDescriptors != null) {
            final AttributeDescriptor timeDesc = timeDescriptors.getTime();
            if (timeDesc != null) {
                attrs.remove(timeDesc.getLocalName());
            }
            final AttributeDescriptor startDesc = timeDescriptors.getStartRange();
            if (startDesc != null) {
                attrs.remove(startDesc.getLocalName());
            }
            final AttributeDescriptor endDesc = timeDescriptors.getEndRange();
            if (endDesc != null) {
                attrs.remove(endDesc.getLocalName());
            }
        }
    }
    if (baseQuery == null) {
        final CoordinateReferenceSystem indexCRS = GeometryUtils.getIndexCrs(index);
        // there is only space and time
        final ExtractGeometryFilterVisitorResult geometryAndCompareOp = ExtractGeometryFilterVisitor.getConstraints(cqlFilter, indexCRS, adapter.getFeatureType().getGeometryDescriptor().getLocalName());
        final TemporalConstraintsSet timeConstraintSet = new ExtractTimeFilterVisitor(adapter.getTimeDescriptors()).getConstraints(cqlFilter);
        if (geometryAndCompareOp != null) {
            final Geometry geometry = geometryAndCompareOp.getGeometry();
            final GeoConstraintsWrapper geoConstraints = GeometryUtils.basicGeoConstraintsWrapperFromGeometry(geometry);
            ConstraintsByClass constraints = geoConstraints.getConstraints();
            final CompareOperation extractedCompareOp = geometryAndCompareOp.getCompareOp();
            if ((timeConstraintSet != null) && !timeConstraintSet.isEmpty()) {
                // determine which time constraints are associated with an
                // indexable
                // field
                final TemporalConstraints temporalConstraints = TimeUtils.getTemporalConstraintsForDescriptors(adapter.getTimeDescriptors(), timeConstraintSet);
                // convert to constraints
                final ConstraintsByClass timeConstraints = ExplicitSpatialTemporalQuery.createConstraints(temporalConstraints, false);
                constraints = geoConstraints.getConstraints().merge(timeConstraints);
            }
            // specified, so specify a CRS if necessary
            if (GeometryUtils.getDefaultCRS().equals(indexCRS)) {
                baseQuery = new ExplicitSpatialQuery(constraints, geometry, extractedCompareOp);
            } else {
                baseQuery = new ExplicitSpatialQuery(constraints, geometry, GeometryUtils.getCrsCode(indexCRS), extractedCompareOp, BasicQueryCompareOperation.INTERSECTS);
            }
            // linear constraint from baseQuery
            if (extractedCompareOp == null) {
                baseQuery.setExact(false);
            }
        // }
        } else if ((timeConstraintSet != null) && !timeConstraintSet.isEmpty()) {
            // determine which time constraints are associated with an
            // indexable
            // field
            final TemporalConstraints temporalConstraints = TimeUtils.getTemporalConstraintsForDescriptors(adapter.getTimeDescriptors(), timeConstraintSet);
            baseQuery = new ExplicitTemporalQuery(temporalConstraints);
        }
    }
    // if baseQuery completely represents CQLQuery expression then use that
    if (attrs.isEmpty() && (baseQuery != null) && baseQuery.isExact()) {
        return baseQuery;
    } else {
        // constraints only
        return new ExplicitCQLQuery(baseQuery, cqlFilter, adapter, indexMapping);
    }
}
Also used : TimeDescriptors(org.locationtech.geowave.core.geotime.util.TimeDescriptors) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) ExtractAttributesFilter(org.locationtech.geowave.core.geotime.util.ExtractAttributesFilter) Geometry(org.locationtech.jts.geom.Geometry) ConstraintsByClass(org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass) GeoConstraintsWrapper(org.locationtech.geowave.core.geotime.util.GeometryUtils.GeoConstraintsWrapper) ExtractGeometryFilterVisitorResult(org.locationtech.geowave.core.geotime.util.ExtractGeometryFilterVisitorResult) Collection(java.util.Collection) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ExtractTimeFilterVisitor(org.locationtech.geowave.core.geotime.util.ExtractTimeFilterVisitor) BasicQueryCompareOperation(org.locationtech.geowave.core.store.query.filter.BasicQueryFilter.BasicQueryCompareOperation) CompareOperation(org.locationtech.geowave.core.geotime.store.query.filter.SpatialQueryFilter.CompareOperation)

Aggregations

Collection (java.util.Collection)3 ExtractAttributesFilter (org.locationtech.geowave.core.geotime.util.ExtractAttributesFilter)3 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 MaxVisitor (org.geotools.feature.visitor.MaxVisitor)1 MinVisitor (org.geotools.feature.visitor.MinVisitor)1 CompareOperation (org.locationtech.geowave.core.geotime.store.query.filter.SpatialQueryFilter.CompareOperation)1 TimeRangeStatistic (org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic)1 TimeRangeValue (org.locationtech.geowave.core.geotime.store.statistics.TimeRangeStatistic.TimeRangeValue)1 ExtractGeometryFilterVisitorResult (org.locationtech.geowave.core.geotime.util.ExtractGeometryFilterVisitorResult)1 ExtractTimeFilterVisitor (org.locationtech.geowave.core.geotime.util.ExtractTimeFilterVisitor)1 GeoConstraintsWrapper (org.locationtech.geowave.core.geotime.util.GeometryUtils.GeoConstraintsWrapper)1 TimeDescriptors (org.locationtech.geowave.core.geotime.util.TimeDescriptors)1 CloseableIterator (org.locationtech.geowave.core.store.CloseableIterator)1 FieldStatistic (org.locationtech.geowave.core.store.api.FieldStatistic)1 ConstraintsByClass (org.locationtech.geowave.core.store.query.constraints.BasicQueryByClass.ConstraintsByClass)1 BasicQueryCompareOperation (org.locationtech.geowave.core.store.query.filter.BasicQueryFilter.BasicQueryCompareOperation)1 NumericRangeStatistic (org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic)1 NumericRangeValue (org.locationtech.geowave.core.store.statistics.field.NumericRangeStatistic.NumericRangeValue)1