Search in sources :

Example 26 with VertexiumException

use of org.vertexium.VertexiumException in project vertexium by visallo.

the class ElasticsearchGraphQueryIterable method reduceGeohashResults.

private static GeohashResult reduceGeohashResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
    Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
    for (Aggregation agg : aggs) {
        if (agg instanceof GeoHashGrid) {
            GeoHashGrid h = (GeoHashGrid) agg;
            for (GeoHashGrid.Bucket b : h.getBuckets()) {
                List<MultiBucketsAggregation.Bucket> existingBucket = bucketsByKey.computeIfAbsent(b.getKey(), k -> new ArrayList<>());
                existingBucket.add(b);
            }
        } else {
            throw new VertexiumException("Aggregation is not a geohash: " + agg.getClass().getName());
        }
    }
    return new MultiBucketsAggregationReducer<GeohashResult, GeohashBucket>() {

        @Override
        protected GeohashBucket createBucket(final Object key, long count, Map<String, AggregationResult> nestedResults, List<MultiBucketsAggregation.Bucket> buckets) {
            GeoPoint geoPoint = getAverageGeoPointFromBuckets(buckets);
            return new GeohashBucket(key.toString(), count, geoPoint, nestedResults) {

                @Override
                public GeoRect getGeoCell() {
                    org.elasticsearch.common.geo.GeoPoint northWest = new org.elasticsearch.common.geo.GeoPoint();
                    org.elasticsearch.common.geo.GeoPoint southEast = new org.elasticsearch.common.geo.GeoPoint();
                    GeohashUtils.decodeCell(key.toString(), northWest, southEast);
                    return new GeoRect(new GeoPoint(northWest.getLat(), northWest.getLon()), new GeoPoint(southEast.getLat(), southEast.getLon()));
                }
            };
        }

        @Override
        protected GeohashResult bucketsToResults(List<GeohashBucket> buckets) {
            return new GeohashResult(buckets);
        }
    }.reduce(query, bucketsByKey);
}
Also used : GeoRect(org.vertexium.type.GeoRect) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) Aggregation(org.elasticsearch.search.aggregations.Aggregation) GeoPoint(org.vertexium.type.GeoPoint) VertexiumException(org.vertexium.VertexiumException) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) InternalGeoHashGrid(org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid) GeoHashGrid(org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid)

Example 27 with VertexiumException

use of org.vertexium.VertexiumException in project vertexium by visallo.

the class ElasticsearchGraphQueryIterable method reduceHistogramResults.

private static HistogramResult reduceHistogramResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
    Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
    for (Aggregation agg : aggs) {
        if (agg instanceof Histogram) {
            Histogram h = (Histogram) agg;
            org.vertexium.query.Aggregation queryAgg = query.getAggregationByName(query.getAggregationName(h.getName()));
            boolean isCalendarFieldQuery = queryAgg != null && queryAgg instanceof CalendarFieldAggregation;
            for (Histogram.Bucket b : h.getBuckets()) {
                if (isCalendarFieldQuery && b.getKey().toString().equals("-1.0")) {
                    continue;
                }
                List<MultiBucketsAggregation.Bucket> l = bucketsByKey.computeIfAbsent(b.getKey(), k -> new ArrayList<>());
                l.add(b);
            }
        } else {
            throw new VertexiumException("Aggregation is not a histogram: " + agg.getClass().getName());
        }
    }
    return new MultiBucketsAggregationReducer<HistogramResult, HistogramBucket>() {

        @Override
        protected HistogramBucket createBucket(Object key, long count, Map<String, AggregationResult> nestedResults, List<MultiBucketsAggregation.Bucket> buckets) {
            return new HistogramBucket(key, count, nestedResults);
        }

        @Override
        protected HistogramResult bucketsToResults(List<HistogramBucket> buckets) {
            return new HistogramResult(buckets);
        }
    }.reduce(query, bucketsByKey);
}
Also used : InternalDateHistogram(org.elasticsearch.search.aggregations.bucket.histogram.InternalDateHistogram) InternalHistogram(org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram) Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) Aggregation(org.elasticsearch.search.aggregations.Aggregation) org.vertexium.query(org.vertexium.query) VertexiumException(org.vertexium.VertexiumException) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation)

Example 28 with VertexiumException

use of org.vertexium.VertexiumException in project vertexium by visallo.

the class GeohashUtils method decodeCell.

public static void decodeCell(String key, org.elasticsearch.common.geo.GeoPoint northWest, org.elasticsearch.common.geo.GeoPoint southEast) {
    try {
        double[] interval = decodeCell(key);
        northWest.reset(interval[1], interval[2]);
        southEast.reset(interval[0], interval[3]);
    } catch (Exception e) {
        throw new VertexiumException("Could not decode cell", e);
    }
}
Also used : VertexiumException(org.vertexium.VertexiumException) VertexiumException(org.vertexium.VertexiumException)

Example 29 with VertexiumException

use of org.vertexium.VertexiumException in project vertexium by visallo.

the class ElasticsearchResource method expandVertexiumPlugin.

private void expandVertexiumPlugin(File vertexiumPluginDir) {
    InputStream zipIn = getClass().getResourceAsStream("/vertexium-elasticsearch5-plugin.zip");
    File pluginZip = new File(vertexiumPluginDir.getParentFile(), "vertexium-elasticsearch5-plugin.zip");
    try (OutputStream zipOut = new FileOutputStream(pluginZip)) {
        IOUtils.copy(zipIn, zipOut);
    } catch (Exception ex) {
        throw new VertexiumException("Could not write plugin zip file", ex);
    }
    try {
        ZipFile zipFile = new ZipFile(pluginZip);
        zipFile.extractFile("elasticsearch/plugin-descriptor.properties", vertexiumPluginDir.getAbsolutePath(), null, "plugin-descriptor.properties");
    } catch (Exception ex) {
        throw new VertexiumException("Could not extract plugin", ex);
    }
    pluginZip.delete();
}
Also used : ZipFile(net.lingala.zip4j.core.ZipFile) ZipFile(net.lingala.zip4j.core.ZipFile) VertexiumException(org.vertexium.VertexiumException) VertexiumException(org.vertexium.VertexiumException)

Example 30 with VertexiumException

use of org.vertexium.VertexiumException in project vertexium by visallo.

the class InMemoryAuthorizations method canRead.

@Override
public boolean canRead(Visibility visibility) {
    Preconditions.checkNotNull(visibility, "visibility is required");
    // this is just a shortcut so that we don't need to construct evaluators and visibility objects to check for an empty string.
    if (visibility.getVisibilityString().length() == 0) {
        return true;
    }
    VisibilityEvaluator visibilityEvaluator = new VisibilityEvaluator(new Authorizations(this.getAuthorizations()));
    ColumnVisibility columnVisibility = new ColumnVisibility(visibility.getVisibilityString());
    try {
        return visibilityEvaluator.evaluate(columnVisibility);
    } catch (VisibilityParseException e) {
        throw new VertexiumException("could not evaluate visibility " + visibility.getVisibilityString(), e);
    }
}
Also used : Authorizations(org.vertexium.security.Authorizations) VisibilityEvaluator(org.vertexium.security.VisibilityEvaluator) ColumnVisibility(org.vertexium.security.ColumnVisibility) VisibilityParseException(org.vertexium.security.VisibilityParseException) VertexiumException(org.vertexium.VertexiumException)

Aggregations

VertexiumException (org.vertexium.VertexiumException)34 Aggregation (org.elasticsearch.search.aggregations.Aggregation)6 MultiBucketsAggregation (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)3 Key (org.apache.accumulo.core.data.Key)3 Value (org.apache.accumulo.core.data.Value)3 DataTableRowKey (org.vertexium.accumulo.keys.DataTableRowKey)3 StreamingPropertyValue (org.vertexium.property.StreamingPropertyValue)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 List (java.util.List)2 ScannerBase (org.apache.accumulo.core.client.ScannerBase)2 Span (org.apache.accumulo.core.trace.Span)2 GeoHashGrid (org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid)2 InternalGeoHashGrid (org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid)2 Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)2 InternalDateHistogram (org.elasticsearch.search.aggregations.bucket.histogram.InternalDateHistogram)2 InternalHistogram (org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram)2