Search in sources :

Example 1 with ByteArrayConstraints

use of org.locationtech.geowave.core.store.api.BinConstraints.ByteArrayConstraints in project geowave by locationtech.

the class CompositeBinningStrategy method concat.

private ByteArrayConstraints concat(final List<ByteArrayConstraints> perStrategyConstraints) {
    final ByteArray[][] c = new ByteArray[perStrategyConstraints.size()][];
    boolean allBins = true;
    for (int i = 0; i < perStrategyConstraints.size(); i++) {
        final ByteArrayConstraints constraints = perStrategyConstraints.get(i);
        if (constraints.isAllBins()) {
            if (!allBins) {
                throw new IllegalArgumentException("Cannot use 'all bins' query for one strategy and not the other");
            }
        } else {
            allBins = false;
        }
        if (constraints.isPrefix()) {
            // can only use a prefix if its the last field or the rest of the fields are 'all bins'
            boolean isValid = true;
            for (final int j = i + 1; i < perStrategyConstraints.size(); i++) {
                final ByteArrayConstraints innerConstraints = perStrategyConstraints.get(j);
                if (!innerConstraints.isAllBins()) {
                    isValid = false;
                    break;
                } else {
                    c[i] = new ByteArray[] { new ByteArray() };
                }
            }
            if (isValid) {
                return new ExplicitConstraints(getAllCombinations(c), true);
            } else {
                throw new IllegalArgumentException("Cannot use 'prefix' query for a strategy that is also using exact constraints on a subsequent strategy");
            }
        }
        c[i] = constraints.getBins();
    }
    return new ExplicitConstraints(getAllCombinations(c), false);
}
Also used : ByteArrayConstraints(org.locationtech.geowave.core.store.api.BinConstraints.ByteArrayConstraints) ByteArray(org.locationtech.geowave.core.index.ByteArray) ExplicitConstraints(org.locationtech.geowave.core.store.statistics.query.BinConstraintsImpl.ExplicitConstraints)

Example 2 with ByteArrayConstraints

use of org.locationtech.geowave.core.store.api.BinConstraints.ByteArrayConstraints in project geowave by locationtech.

the class GeohashBinningHelper method getGeometryConstraints.

@Override
public ByteArrayConstraints getGeometryConstraints(final Geometry geometry, final int precision) {
    final GeohashGeometryHandler geometryHandler = new GeohashGeometryHandler(precision);
    GeometryUtils.visitGeometry(geometry, geometryHandler);
    // this can really help with query performance
    if (removePrefixes(geometryHandler.hashes)) {
        return new ExplicitConstraints(geometryHandler.hashes.stream().map(str -> StringUtils.stringToBinary(str)).map(bytes -> new ByteArrayRange(bytes, bytes)).toArray(ByteArrayRange[]::new));
    }
    return new ExplicitConstraints(geometryHandler.hashes.stream().map(ByteArray::new).toArray(ByteArray[]::new));
}
Also used : ByteArray(org.locationtech.geowave.core.index.ByteArray) StringUtils(org.locationtech.geowave.core.index.StringUtils) Coverage(com.github.davidmoten.geo.Coverage) Set(java.util.Set) GeometryHandler(org.locationtech.geowave.core.geotime.util.GeometryUtils.GeometryHandler) Point(org.locationtech.jts.geom.Point) GeometryUtils(org.locationtech.geowave.core.geotime.util.GeometryUtils) Collectors(java.util.stream.Collectors) ByteArrayConstraints(org.locationtech.geowave.core.store.api.BinConstraints.ByteArrayConstraints) ExplicitConstraints(org.locationtech.geowave.core.store.statistics.query.BinConstraintsImpl.ExplicitConstraints) HashSet(java.util.HashSet) LineString(org.locationtech.jts.geom.LineString) HashMultimap(com.google.common.collect.HashMultimap) GeoHash(com.github.davidmoten.geo.GeoHash) LatLong(com.github.davidmoten.geo.LatLong) Entry(java.util.Map.Entry) Polygon(org.locationtech.jts.geom.Polygon) Geometry(org.locationtech.jts.geom.Geometry) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange) Envelope(org.locationtech.jts.geom.Envelope) ByteArray(org.locationtech.geowave.core.index.ByteArray) ExplicitConstraints(org.locationtech.geowave.core.store.statistics.query.BinConstraintsImpl.ExplicitConstraints) ByteArrayRange(org.locationtech.geowave.core.index.ByteArrayRange)

Aggregations

ByteArray (org.locationtech.geowave.core.index.ByteArray)2 ByteArrayConstraints (org.locationtech.geowave.core.store.api.BinConstraints.ByteArrayConstraints)2 ExplicitConstraints (org.locationtech.geowave.core.store.statistics.query.BinConstraintsImpl.ExplicitConstraints)2 Coverage (com.github.davidmoten.geo.Coverage)1 GeoHash (com.github.davidmoten.geo.GeoHash)1 LatLong (com.github.davidmoten.geo.LatLong)1 HashMultimap (com.google.common.collect.HashMultimap)1 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 GeometryUtils (org.locationtech.geowave.core.geotime.util.GeometryUtils)1 GeometryHandler (org.locationtech.geowave.core.geotime.util.GeometryUtils.GeometryHandler)1 ByteArrayRange (org.locationtech.geowave.core.index.ByteArrayRange)1 StringUtils (org.locationtech.geowave.core.index.StringUtils)1 Envelope (org.locationtech.jts.geom.Envelope)1 Geometry (org.locationtech.jts.geom.Geometry)1 LineString (org.locationtech.jts.geom.LineString)1 Point (org.locationtech.jts.geom.Point)1 Polygon (org.locationtech.jts.geom.Polygon)1