Search in sources :

Example 21 with VertexiumException

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

the class ConfigurationUtils method createProvider.

@SuppressWarnings("unchecked")
public static <T> T createProvider(String className, Graph graph, GraphConfiguration config) throws VertexiumException {
    checkNotNull(className, "className is required");
    className = className.trim();
    LOGGER.debug("creating provider '%s'", className);
    Class<Graph> graphClass = Graph.class;
    Class<GraphConfiguration> graphConfigurationClass = GraphConfiguration.class;
    try {
        Class<?> clazz = Class.forName(className);
        try {
            Constructor constructor;
            try {
                constructor = clazz.getConstructor(graphClass);
                return (T) constructor.newInstance(graph);
            } catch (NoSuchMethodException ignore1) {
                try {
                    constructor = clazz.getConstructor(graphClass, graphConfigurationClass);
                    return (T) constructor.newInstance(graph, config);
                } catch (NoSuchMethodException ignore2) {
                    try {
                        constructor = clazz.getConstructor(graphConfigurationClass);
                        return (T) constructor.newInstance(config);
                    } catch (NoSuchMethodException ignore3) {
                        try {
                            constructor = clazz.getConstructor(Map.class);
                            return (T) constructor.newInstance(config.getConfig());
                        } catch (NoSuchMethodException ignoreInner) {
                            constructor = clazz.getConstructor();
                            return (T) constructor.newInstance();
                        }
                    }
                }
            }
        } catch (IllegalArgumentException e) {
            StringBuilder possibleMatches = new StringBuilder();
            for (Constructor<?> s : clazz.getConstructors()) {
                possibleMatches.append(s.toGenericString());
                possibleMatches.append(", ");
            }
            throw new VertexiumException("Invalid constructor for " + className + ". Expected <init>(" + graphConfigurationClass.getName() + "). Found: " + possibleMatches, e);
        }
    } catch (NoSuchMethodException e) {
        throw new VertexiumException("Provider must have a single argument constructor taking a " + graphConfigurationClass.getName(), e);
    } catch (ClassNotFoundException e) {
        throw new VertexiumException("No provider found with class name " + className, e);
    } catch (Exception e) {
        throw new VertexiumException(e);
    }
}
Also used : GraphConfiguration(org.vertexium.GraphConfiguration) Constructor(java.lang.reflect.Constructor) VertexiumException(org.vertexium.VertexiumException) VertexiumException(org.vertexium.VertexiumException) IOException(java.io.IOException) Graph(org.vertexium.Graph)

Example 22 with VertexiumException

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

the class GeoPoint method parse.

public static GeoPoint parse(String str) {
    String description;
    Matcher m = WITH_DESCRIPTION_PATTERN.matcher(str);
    if (m.matches()) {
        description = m.group(1).trim();
        str = m.group(2).trim();
    } else {
        description = null;
    }
    String[] parts = str.split(",");
    if (parts.length < 2) {
        throw new VertexiumException("Too few parts to GeoPoint string. Expected at least 2 found " + parts.length + " for string: " + str);
    }
    if (parts.length >= 4) {
        throw new VertexiumException("Too many parts to GeoPoint string. Expected less than or equal to 3 found " + parts.length + " for string: " + str);
    }
    double latitude = parsePart(parts[0]);
    double longitude = parsePart(parts[1]);
    Double altitude = null;
    if (parts.length >= 3) {
        altitude = Double.parseDouble(parts[2]);
    }
    return new GeoPoint(latitude, longitude, altitude, description);
}
Also used : Matcher(java.util.regex.Matcher) VertexiumException(org.vertexium.VertexiumException)

Example 23 with VertexiumException

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

the class ElasticsearchGraphQueryIterable method reduceRangeResults.

private static RangeResult reduceRangeResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
    Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
    for (Aggregation agg : aggs) {
        if (agg instanceof Range) {
            Range r = (Range) agg;
            for (Range.Bucket b : r.getBuckets()) {
                List<MultiBucketsAggregation.Bucket> l = bucketsByKey.computeIfAbsent(b.getKey(), k -> new ArrayList<>());
                l.add(b);
            }
        } else {
            throw new VertexiumException("Aggregation is not a range: " + agg.getClass().getName());
        }
    }
    return new MultiBucketsAggregationReducer<RangeResult, RangeBucket>() {

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

        @Override
        protected RangeResult bucketsToResults(List<RangeBucket> buckets) {
            return new RangeResult(buckets);
        }
    }.reduce(query, bucketsByKey);
}
Also used : Range(org.elasticsearch.search.aggregations.bucket.range.Range) InternalRange(org.elasticsearch.search.aggregations.bucket.range.InternalRange) VertexiumException(org.vertexium.VertexiumException) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) Aggregation(org.elasticsearch.search.aggregations.Aggregation) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation)

Example 24 with VertexiumException

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

the class ElasticsearchGraphQueryIterable method reduceTermsResults.

private static TermsResult reduceTermsResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
    Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
    for (Aggregation agg : aggs) {
        if (agg instanceof Terms) {
            Terms h = (Terms) agg;
            for (Terms.Bucket b : h.getBuckets()) {
                TopHits exactMatchTopHits = b.getAggregations().get(ElasticsearchSearchQueryBase.TOP_HITS_AGGREGATION_NAME);
                String mapKey = bucketKeyToString(b.getKey(), exactMatchTopHits);
                List<MultiBucketsAggregation.Bucket> existingBucketByName = bucketsByKey.computeIfAbsent(mapKey, k -> new ArrayList<>());
                existingBucketByName.add(b);
            }
        } else {
            throw new VertexiumException("Aggregation is not a terms: " + agg.getClass().getName());
        }
    }
    return new MultiBucketsAggregationReducer<TermsResult, TermsBucket>() {

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

        @Override
        protected TermsResult bucketsToResults(List<TermsBucket> buckets) {
            return new TermsResult(buckets);
        }
    }.reduce(query, bucketsByKey);
}
Also used : InternalTerms(org.elasticsearch.search.aggregations.bucket.terms.InternalTerms) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) VertexiumException(org.vertexium.VertexiumException) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) Aggregation(org.elasticsearch.search.aggregations.Aggregation) TopHits(org.elasticsearch.search.aggregations.metrics.tophits.TopHits) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation)

Example 25 with VertexiumException

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

the class ElasticsearchGraphQueryIterable method reducePercentilesResults.

private static PercentilesResult reducePercentilesResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
    List<Percentile> results = new ArrayList<>();
    if (aggs.size() != 1) {
        throw new VertexiumException("Unexpected number of aggregations. Expected 1 but found: " + aggs.size());
    }
    Aggregation agg = aggs.get(0);
    if (agg instanceof Percentiles) {
        Percentiles percentiles = (Percentiles) agg;
        StreamUtils.stream(percentiles).filter(percentile -> !Double.isNaN(percentile.getValue())).forEach(percentile -> results.add(new Percentile(percentile.getPercent(), percentile.getValue())));
    } else {
        throw new VertexiumException("Aggregation is not a percentile: " + agg.getClass().getName());
    }
    return new PercentilesResult(results);
}
Also used : MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) Aggregation(org.elasticsearch.search.aggregations.Aggregation) SearchHit(org.elasticsearch.search.SearchHit) InternalDateHistogram(org.elasticsearch.search.aggregations.bucket.histogram.InternalDateHistogram) InternalGeoHashGrid(org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid) java.util(java.util) InternalHistogram(org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram) InternalExtendedStats(org.elasticsearch.search.aggregations.metrics.stats.extended.InternalExtendedStats) VertexiumException(org.vertexium.VertexiumException) SearchHits(org.elasticsearch.search.SearchHits) InternalTerms(org.elasticsearch.search.aggregations.bucket.terms.InternalTerms) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) TopHits(org.elasticsearch.search.aggregations.metrics.tophits.TopHits) ExtendedStats(org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats) GeoRect(org.vertexium.type.GeoRect) Range(org.elasticsearch.search.aggregations.bucket.range.Range) org.vertexium.query(org.vertexium.query) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) InternalRange(org.elasticsearch.search.aggregations.bucket.range.InternalRange) SearchResponse(org.elasticsearch.action.search.SearchResponse) Aggregation(org.elasticsearch.search.aggregations.Aggregation) StreamUtils(org.vertexium.util.StreamUtils) Percentiles(org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles) GeoPoint(org.vertexium.type.GeoPoint) GeoHashGrid(org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid) Percentiles(org.elasticsearch.search.aggregations.metrics.percentiles.Percentiles) 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