private CardinalityResult queryGraphQueryWithCardinalityAggregation(String propertyName, Authorizations authorizations) { Query q = graph.query(authorizations).limit(0); CardinalityAggregation agg = new CardinalityAggregation("card", propertyName); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", CardinalityAggregation.class.getName()); return null; } q.addAggregation(agg); return q.vertices().getAggregationResult("card", CardinalityResult.class); }
private StatisticsResult queryGraphQueryWithStatisticsAggregation(String propertyName, Authorizations authorizations) { Query q = graph.query(authorizations).limit(0); StatisticsAggregation agg = new StatisticsAggregation("stats", propertyName); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", StatisticsAggregation.class.getName()); return null; } q.addAggregation(agg); return q.vertices().getAggregationResult("stats", StatisticsResult.class); }
private StatisticsResult queryGraphQueryWithStatisticsAggregation(String propertyName, Authorizations authorizations) { Query q = graph.query(authorizations).limit(0); StatisticsAggregation agg = new StatisticsAggregation("stats", propertyName); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", StatisticsAggregation.class.getName()); return null; } q.addAggregation(agg); return q.vertices().getAggregationResult("stats", StatisticsResult.class); }
private CardinalityResult queryGraphQueryWithCardinalityAggregation(String propertyName, Authorizations authorizations) { Query q = graph.query(authorizations).limit(0); CardinalityAggregation agg = new CardinalityAggregation("card", propertyName); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", CardinalityAggregation.class.getName()); return null; } q.addAggregation(agg); return q.vertices().getAggregationResult("card", CardinalityResult.class); }
private Map<Object, Long> queryGraphQueryWithTermsAggregation(String queryString, String propertyName, ElementType elementType, Authorizations authorizations) { Query q = (queryString == null ? graph.query(authorizations) : graph.query(queryString, authorizations)).limit(0); TermsAggregation agg = new TermsAggregation("terms-count", propertyName); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", agg.getClass().getName()); return null; } q.addAggregation(agg); QueryResultsIterable<? extends Element> elements = elementType == ElementType.VERTEX ? q.vertices() : q.edges(); TermsResult aggregationResult = elements.getAggregationResult("terms-count", TermsResult.class); return termsBucketToMap(aggregationResult.getBuckets()); }
private Map<String, Long> queryGraphQueryWithGeohashAggregation(String propertyName, int precision, Authorizations authorizations) { Query q = graph.query(authorizations).limit(0); GeohashAggregation agg = new GeohashAggregation("geo-count", propertyName, precision); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", GeohashAggregation.class.getName()); return null; } q.addAggregation(agg); return geoHashBucketToMap(q.vertices().getAggregationResult("geo-count", GeohashResult.class).getBuckets()); }
private Map<Object, Long> queryGraphQueryWithTermsAggregation(String queryString, String propertyName, ElementType elementType, Authorizations authorizations) { Query q = (queryString == null ? graph.query(authorizations) : graph.query(queryString, authorizations)).limit(0); TermsAggregation agg = new TermsAggregation("terms-count", propertyName); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", agg.getClass().getName()); return null; } q.addAggregation(agg); QueryResultsIterable<? extends Element> elements = elementType == ElementType.VERTEX ? q.vertices() : q.edges(); TermsResult aggregationResult = elements.getAggregationResult("terms-count", TermsResult.class); return termsBucketToMap(aggregationResult.getBuckets()); }
private Map<String, Long> queryGraphQueryWithGeohashAggregation(String propertyName, int precision, Authorizations authorizations) { Query q = graph.query(authorizations).limit(0); GeohashAggregation agg = new GeohashAggregation("geo-count", propertyName, precision); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", GeohashAggregation.class.getName()); return null; } q.addAggregation(agg); return geoHashBucketToMap(q.vertices().getAggregationResult("geo-count", GeohashResult.class).getBuckets()); }
private PercentilesResult queryGraphQueryWithPercentilesAggregation( String propertyName, Visibility visibility, Authorizations authorizations, double... percents ) { Query q = graph.query(authorizations).limit(0); PercentilesAggregation agg = new PercentilesAggregation("percentiles", propertyName, visibility); agg.setPercents(percents); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", StatisticsAggregation.class.getName()); return null; } q.addAggregation(agg); return q.vertices().getAggregationResult("percentiles", PercentilesResult.class); }
private PercentilesResult queryGraphQueryWithPercentilesAggregation( String propertyName, Visibility visibility, Authorizations authorizations, double... percents ) { Query q = graph.query(authorizations).limit(0); PercentilesAggregation agg = new PercentilesAggregation("percentiles", propertyName, visibility); agg.setPercents(percents); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", StatisticsAggregation.class.getName()); return null; } q.addAggregation(agg); return q.vertices().getAggregationResult("percentiles", PercentilesResult.class); }
private Map<Object, Long> queryGraphQueryWithHistogramAggregation( String propertyName, String interval, Long minDocCount, HistogramAggregation.ExtendedBounds extendedBounds, Authorizations authorizations ) { Query q = graph.query(authorizations).limit(0); HistogramAggregation agg = new HistogramAggregation("hist-count", propertyName, interval, minDocCount); agg.setExtendedBounds(extendedBounds); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", HistogramAggregation.class.getName()); return null; } q.addAggregation(agg); return histogramBucketToMap(q.vertices().getAggregationResult("hist-count", HistogramResult.class).getBuckets()); }
private Map<Object, Long> queryGraphQueryWithHistogramAggregation( String propertyName, String interval, Long minDocCount, HistogramAggregation.ExtendedBounds extendedBounds, Authorizations authorizations ) { Query q = graph.query(authorizations).limit(0); HistogramAggregation agg = new HistogramAggregation("hist-count", propertyName, interval, minDocCount); agg.setExtendedBounds(extendedBounds); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", HistogramAggregation.class.getName()); return null; } q.addAggregation(agg); return histogramBucketToMap(q.vertices().getAggregationResult("hist-count", HistogramResult.class).getBuckets()); }
private RangeResult queryGraphQueryWithRangeAggregation( String propertyName, String format, String keyOne, Object boundaryOne, String keyTwo, Object boundaryTwo, String keyThree, Authorizations authorizations ) { Query q = graph.query(authorizations).limit(0); RangeAggregation agg = new RangeAggregation("range-count", propertyName, format); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", RangeAggregation.class.getName()); return null; } agg.addUnboundedTo(keyOne, boundaryOne); agg.addRange(keyTwo, boundaryOne, boundaryTwo); agg.addUnboundedFrom(keyThree, boundaryTwo); q.addAggregation(agg); return q.vertices().getAggregationResult("range-count", RangeResult.class); }
private RangeResult queryGraphQueryWithRangeAggregation( String propertyName, String format, String keyOne, Object boundaryOne, String keyTwo, Object boundaryTwo, String keyThree, Authorizations authorizations ) { Query q = graph.query(authorizations).limit(0); RangeAggregation agg = new RangeAggregation("range-count", propertyName, format); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", RangeAggregation.class.getName()); return null; } agg.addUnboundedTo(keyOne, boundaryOne); agg.addRange(keyTwo, boundaryOne, boundaryTwo); agg.addUnboundedFrom(keyThree, boundaryTwo); q.addAggregation(agg); return q.vertices().getAggregationResult("range-count", RangeResult.class); }
@Test public void testVertexQueryWithNestedTermsAggregationOnExtendedData() { graph.defineProperty("name").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH, TextIndexHint.FULL_TEXT).define(); graph.defineProperty("gender").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.prepareVertex("v1", VISIBILITY_EMPTY) .addExtendedData("t1", "r1", "name", "Joe", VISIBILITY_EMPTY) .addExtendedData("t1", "r1", "gender", "male", VISIBILITY_EMPTY) .addExtendedData("t1", "r2", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r2", "gender", "male", VISIBILITY_EMPTY) .addExtendedData("t1", "r3", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r3", "gender", "female", VISIBILITY_EMPTY) .addExtendedData("t1", "r4", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r4", "gender", "female", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B); Query q = v1.getExtendedData("t1").query(AUTHORIZATIONS_A_AND_B).limit(0); TermsAggregation agg = new TermsAggregation("terms-count", "name"); agg.addNestedAggregation(new TermsAggregation("nested", "gender")); assumeTrue("terms aggregation not supported", q.isAggregationSupported(agg)); q.addAggregation(agg); TermsResult aggregationResult = q.extendedDataRows().getAggregationResult("terms-count", TermsResult.class); Map<Object, Map<Object, Long>> vertexPropertyCountByValue = nestedTermsBucketToMap(aggregationResult.getBuckets(), "nested"); assertEquals(2, vertexPropertyCountByValue.size()); assertEquals(1, vertexPropertyCountByValue.get("Joe").size()); assertEquals(1L, (long) vertexPropertyCountByValue.get("Joe").get("male")); assertEquals(2, vertexPropertyCountByValue.get("Sam").size()); assertEquals(1L, (long) vertexPropertyCountByValue.get("Sam").get("male")); assertEquals(2L, (long) vertexPropertyCountByValue.get("Sam").get("female")); }
@Test public void testVertexQueryWithNestedTermsAggregationOnExtendedData() { graph.defineProperty("name").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH, TextIndexHint.FULL_TEXT).define(); graph.defineProperty("gender").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.prepareVertex("v1", VISIBILITY_EMPTY) .addExtendedData("t1", "r1", "name", "Joe", VISIBILITY_EMPTY) .addExtendedData("t1", "r1", "gender", "male", VISIBILITY_EMPTY) .addExtendedData("t1", "r2", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r2", "gender", "male", VISIBILITY_EMPTY) .addExtendedData("t1", "r3", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r3", "gender", "female", VISIBILITY_EMPTY) .addExtendedData("t1", "r4", "name", "Sam", VISIBILITY_EMPTY) .addExtendedData("t1", "r4", "gender", "female", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B); Query q = v1.getExtendedData("t1").query(AUTHORIZATIONS_A_AND_B).limit(0); TermsAggregation agg = new TermsAggregation("terms-count", "name"); agg.addNestedAggregation(new TermsAggregation("nested", "gender")); assumeTrue("terms aggregation not supported", q.isAggregationSupported(agg)); q.addAggregation(agg); TermsResult aggregationResult = q.extendedDataRows().getAggregationResult("terms-count", TermsResult.class); Map<Object, Map<Object, Long>> vertexPropertyCountByValue = nestedTermsBucketToMap(aggregationResult.getBuckets(), "nested"); assertEquals(2, vertexPropertyCountByValue.size()); assertEquals(1, vertexPropertyCountByValue.get("Joe").size()); assertEquals(1L, (long) vertexPropertyCountByValue.get("Joe").get("male")); assertEquals(2, vertexPropertyCountByValue.get("Sam").size()); assertEquals(1L, (long) vertexPropertyCountByValue.get("Sam").get("male")); assertEquals(2L, (long) vertexPropertyCountByValue.get("Sam").get("female")); }
TermsAggregation agg = new TermsAggregation("terms-count", "name"); agg.addNestedAggregation(new TermsAggregation("nested", "gender")); assumeTrue("terms aggregation not supported", q.isAggregationSupported(agg)); q.addAggregation(agg); TermsResult aggregationResult = q.vertices().getAggregationResult("terms-count", TermsResult.class);
TermsAggregation agg = new TermsAggregation("terms-count", "name"); agg.addNestedAggregation(new TermsAggregation("nested", "gender")); assumeTrue("terms aggregation not supported", q.isAggregationSupported(agg)); q.addAggregation(agg); TermsResult aggregationResult = q.vertices().getAggregationResult("terms-count", TermsResult.class);
@Test public void testGraphQueryWithTermsAggregationAndPredicates() { graph.defineProperty("name").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH, TextIndexHint.FULL_TEXT).define(); graph.defineProperty("gender").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); Query q = graph.query(AUTHORIZATIONS_EMPTY) .has("name", Compare.EQUAL, "Susan"); TermsAggregation agg = new TermsAggregation("terms-count", "name"); assumeTrue("terms aggregation not supported", q.isAggregationSupported(agg)); q.addAggregation(agg); TermsResult aggregationResult = q.vertices().getAggregationResult("terms-count", TermsResult.class); Map<Object, Long> vertexPropertyCountByValue = termsBucketToMap(aggregationResult.getBuckets()); assertEquals(0, vertexPropertyCountByValue.size()); graph.prepareVertex("v1", VISIBILITY_EMPTY) .addPropertyValue("k1", "gender", "female", VISIBILITY_A) .save(AUTHORIZATIONS_A); getGraph().flush(); q = graph.query(AUTHORIZATIONS_A) .has("gender", Compare.EQUAL, "female"); agg = new TermsAggregation("terms-count", "gender"); assumeTrue("terms aggregation not supported", q.isAggregationSupported(agg)); q.addAggregation(agg); aggregationResult = q.vertices().getAggregationResult("terms-count", TermsResult.class); vertexPropertyCountByValue = termsBucketToMap(aggregationResult.getBuckets()); assertEquals(1, vertexPropertyCountByValue.size()); }
@Test public void testGraphQueryWithTermsAggregationAndPredicates() { graph.defineProperty("name").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH, TextIndexHint.FULL_TEXT).define(); graph.defineProperty("gender").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); Query q = graph.query(AUTHORIZATIONS_EMPTY) .has("name", Compare.EQUAL, "Susan"); TermsAggregation agg = new TermsAggregation("terms-count", "name"); assumeTrue("terms aggregation not supported", q.isAggregationSupported(agg)); q.addAggregation(agg); TermsResult aggregationResult = q.vertices().getAggregationResult("terms-count", TermsResult.class); Map<Object, Long> vertexPropertyCountByValue = termsBucketToMap(aggregationResult.getBuckets()); assertEquals(0, vertexPropertyCountByValue.size()); graph.prepareVertex("v1", VISIBILITY_EMPTY) .addPropertyValue("k1", "gender", "female", VISIBILITY_A) .save(AUTHORIZATIONS_A); getGraph().flush(); q = graph.query(AUTHORIZATIONS_A) .has("gender", Compare.EQUAL, "female"); agg = new TermsAggregation("terms-count", "gender"); assumeTrue("terms aggregation not supported", q.isAggregationSupported(agg)); q.addAggregation(agg); aggregationResult = q.vertices().getAggregationResult("terms-count", TermsResult.class); vertexPropertyCountByValue = termsBucketToMap(aggregationResult.getBuckets()); assertEquals(1, vertexPropertyCountByValue.size()); }