@Override public GraphQuery limit(int limit) { q.limit(limit); hasFilter = true; return this; }
public String search(Graph graph, Authorizations authorizations) { Query query = graph.query(authorizations).limit(1); List<Vertex> vertices = Lists.newArrayList(query.vertices()); if (vertices.size() == 0) { throw new VisalloException("query returned no vertices"); } else if (vertices.size() > 1) { throw new VisalloException("query returned more than one vertex"); } return vertices.get(0).getId(); }
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 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 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<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<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); }
GraphQuery query = graph.query(authorizations); addEdgeLabelFilterToQuery(query, relationshipIri, false, workspaceId); query.limit(0); long results = query.search().getTotalHits(); if (results == 0) {
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); }
graph.flush(); Query q = graph.query(AUTHORIZATIONS_A_AND_B).limit(0); TermsAggregation agg = new TermsAggregation("terms-count", "name"); agg.addNestedAggregation(new TermsAggregation("nested", "gender"));
public void deleteProperty(String propertyIri, User user, String workspaceId) { checkDeletePrivileges(user, workspaceId); OntologyProperty property = getPropertyByIRI(propertyIri, workspaceId); if (property != null) { if (property.getSandboxStatus().equals(SandboxStatus.PRIVATE)) { Graph graph = getGraph(); Authorizations authorizations = graph.createAuthorizations(workspaceId); GraphQuery query = graph.query(authorizations); query.has(propertyIri); query.limit(0); long results = query.search().getTotalHits(); if (results == 0) { internalDeleteProperty(property, workspaceId); } else { throw new VisalloException("Unable to delete property that have elements using it"); } } else { throw new VisalloException("Unable to delete published properties"); } } else throw new VisalloResourceNotFoundException("Property not found"); }
@Test public void testQueryExecutionCountWhenPaging() { graph.prepareVertex("v1", VISIBILITY_A).save(AUTHORIZATIONS_A); graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); long startingNumQueries = getNumQueries(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).vertices(); assertEquals(startingNumQueries, getNumQueries()); assertResultsCount(2, 2, vertices); assertEquals(startingNumQueries + 2, getNumQueries()); vertices = graph.query(AUTHORIZATIONS_A).limit(1).vertices(); assertEquals(startingNumQueries + 4, getNumQueries()); assertResultsCount(1, 2, vertices); assertEquals(startingNumQueries + 4, getNumQueries()); vertices = graph.query(AUTHORIZATIONS_A).limit(10).vertices(); assertEquals(startingNumQueries + 6, getNumQueries()); assertResultsCount(2, 2, vertices); assertEquals(startingNumQueries + 6, getNumQueries()); }