use of org.locationtech.geowave.core.store.query.filter.expression.FieldValue in project geowave by locationtech.
the class BinarySpatialPredicate 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 (!constraintClass.isAssignableFrom(Double.class)) {
return FilterConstraints.empty();
}
final Map<Integer, DimensionConstraints<Double>> dimensionRanges = Maps.newHashMap();
FilterGeometry literal = null;
String fieldName = null;
CoordinateReferenceSystem literalCRS = GeometryUtils.getDefaultCRS();
if ((expression1 instanceof FieldValue) && indexedFields.contains(((FieldValue<?>) expression1).getFieldName()) && expression2.isLiteral()) {
literal = expression2.evaluateValue(null, null);
if (expression2 instanceof SpatialExpression) {
literalCRS = expression2.getCRS(adapter);
}
fieldName = ((FieldValue<?>) expression1).getFieldName();
} else if ((expression2 instanceof FieldValue) && indexedFields.contains(((FieldValue<?>) expression2).getFieldName()) && expression1.isLiteral()) {
literal = expression1.evaluateValue(null, null);
if (expression1 instanceof SpatialExpression) {
literalCRS = expression1.getCRS(adapter);
}
fieldName = ((FieldValue<?>) expression2).getFieldName();
}
if ((literal != null) && (fieldName != null)) {
final CoordinateReferenceSystem indexCRS = GeometryUtils.getIndexCrs(index);
Geometry literalGeometry = literal.getGeometry();
if ((indexCRS != null) && !indexCRS.equals(literalCRS)) {
try {
literalGeometry = GeometryUtils.crsTransform(literalGeometry, CRS.findMathTransform(literalCRS, indexCRS));
} catch (final FactoryException e) {
throw new RuntimeException("Unable to transform spatial literal to the index CRS.");
}
}
final Envelope envelope = literalGeometry.getEnvelopeInternal();
if (!envelope.isNull()) {
dimensionRanges.put(0, DimensionConstraints.of(Lists.newArrayList(FilterRange.of(envelope.getMinX(), envelope.getMaxX(), true, true, isExact()))));
dimensionRanges.put(1, DimensionConstraints.of(Lists.newArrayList(FilterRange.of(envelope.getMinY(), envelope.getMaxY(), true, true, isExact()))));
}
}
if (dimensionRanges.isEmpty()) {
return FilterConstraints.empty();
}
return FilterConstraints.of(adapter, indexMapping, index, fieldName, (IndexFieldConstraints<V>) NumericFieldConstraints.of(dimensionRanges));
}
use of org.locationtech.geowave.core.store.query.filter.expression.FieldValue in project geowave by locationtech.
the class TemporalBetween 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 ((valueExpr instanceof FieldValue) && indexedFields.contains(((FieldValue<?>) valueExpr).getFieldName()) && lowerBoundExpr.isLiteral() && upperBoundExpr.isLiteral() && constraintClass.isAssignableFrom(Double.class)) {
final Interval lowerBound = lowerBoundExpr.evaluateValue(null, null);
final Interval upperBound = upperBoundExpr.evaluateValue(null, null);
if ((lowerBound != null) && (upperBound != null)) {
return FilterConstraints.of(adapter, indexMapping, index, ((FieldValue<?>) valueExpr).getFieldName(), (IndexFieldConstraints<V>) NumericFieldConstraints.of((double) lowerBound.getStart().toEpochMilli(), (double) TimeUtils.getIntervalEnd(upperBound).toEpochMilli(), true, false, index.getIndexStrategy() instanceof SimpleNumericIndexStrategy));
}
}
return FilterConstraints.empty();
}
use of org.locationtech.geowave.core.store.query.filter.expression.FieldValue 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();
}
use of org.locationtech.geowave.core.store.query.filter.expression.FieldValue in project geowave by locationtech.
the class BinarySpatialPredicate method prepare.
@Override
public void prepare(final DataTypeAdapter<?> adapter, final AdapterToIndexMapping indexMapping, final Index index) {
CoordinateReferenceSystem expression1Crs = expression1.getCRS(adapter);
CoordinateReferenceSystem expression2Crs = expression2.getCRS(adapter);
if (expression1.isLiteral() && !(expression1 instanceof SpatialLiteral)) {
expression1 = SpatialLiteral.of(expression1.evaluateValue(null), expression1Crs);
}
if (expression2.isLiteral() && !(expression2 instanceof SpatialLiteral)) {
expression2 = SpatialLiteral.of(expression2.evaluateValue(null), expression2Crs);
}
if ((expression1 instanceof FieldValue) && isFieldMappedToIndex(((FieldValue<?>) expression1).getFieldName(), indexMapping)) {
expression1Crs = GeometryUtils.getIndexCrs(index);
}
if ((expression2 instanceof FieldValue) && isFieldMappedToIndex(((FieldValue<?>) expression2).getFieldName(), indexMapping)) {
expression2Crs = GeometryUtils.getIndexCrs(index);
}
if (expression1.isLiteral()) {
((SpatialLiteral) expression1).prepare(expression2Crs);
} else if (expression2.isLiteral()) {
((SpatialLiteral) expression2).prepare(expression1Crs);
}
}
Aggregations