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();
}
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;
}
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);
}
}
Aggregations