private static QueryResultsIterable<? extends Element> executeQuery( VertexiumCypherQueryContext ctx, Query query, MatchConstraint<?, ?> matchConstraint ) { QueryResultsIterable<? extends Element> elements; if (matchConstraint instanceof NodeMatchConstraint) { elements = query.vertices(ctx.getFetchHints()); } else if (matchConstraint instanceof RelationshipMatchConstraint) { elements = query.edges(ctx.getFetchHints()); } else { throw new VertexiumCypherNotImplemented("unexpected constraint type: " + matchConstraint.getClass().getName()); } return elements; }
private static QueryResultsIterable<? extends Element> executeQuery( VertexiumCypherQueryContext ctx, Query query, MatchConstraint<?, ?> matchConstraint ) { QueryResultsIterable<? extends Element> elements; if (matchConstraint instanceof NodeMatchConstraint) { elements = query.vertices(ctx.getFetchHints()); } else if (matchConstraint instanceof RelationshipMatchConstraint) { elements = query.edges(ctx.getFetchHints()); } else { throw new VertexiumCypherNotImplemented("unexpected constraint type: " + matchConstraint.getClass().getName()); } return elements; }
@Override public Iterable<Edge> getEdges(final String key, final Object value) { final Authorizations authorizations = getAuthorizationsProvider().getAuthorizations(); return new ConvertingIterable<org.vertexium.Edge, Edge>(getGraph().query(authorizations).has(key, Compare.EQUAL, value).edges(getFetchHints())) { @Override protected Edge convert(org.vertexium.Edge edge) { return VertexiumBlueprintsEdge.create(VertexiumBlueprintsGraph.this, edge, authorizations); } }; }
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()); }
@Test public void testGraphQueryForEdgesUsingEdgeLabel() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e2", v1, v3, LABEL_LABEL2, VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e3", v3, v1, LABEL_LABEL2, VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A) .has(Edge.LABEL_PROPERTY_NAME, LABEL_LABEL1) .edges(); assertEdgeIdsAnyOrder(edges, "e1"); edges = graph.query(AUTHORIZATIONS_A) .has(Edge.LABEL_PROPERTY_NAME, LABEL_LABEL2) .edges(); assertEdgeIdsAnyOrder(edges, "e2", "e3"); }
@Test public void testGraphQueryForEdgesUsingEdgeLabel() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e2", v1, v3, LABEL_LABEL2, VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e3", v3, v1, LABEL_LABEL2, VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A) .has(Edge.LABEL_PROPERTY_NAME, LABEL_LABEL1) .edges(); assertEdgeIdsAnyOrder(edges, "e1"); edges = graph.query(AUTHORIZATIONS_A) .has(Edge.LABEL_PROPERTY_NAME, LABEL_LABEL2) .edges(); assertEdgeIdsAnyOrder(edges, "e2", "e3"); }
@Test public void testGraphQueryForEdgesUsingInOutVertexIds() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e2", v1, v3, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e3", v3, v1, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A) .has(Edge.OUT_VERTEX_ID_PROPERTY_NAME, "v1") .has(Edge.IN_VERTEX_ID_PROPERTY_NAME, "v2") .edges(); assertEdgeIdsAnyOrder(edges, "e1"); edges = graph.query(AUTHORIZATIONS_A) .has(Edge.OUT_VERTEX_ID_PROPERTY_NAME, "v1") .edges(); assertEdgeIdsAnyOrder(edges, "e1", "e2"); }
@Test public void testGraphQueryForEdgesUsingInOutVertexIds() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e2", v1, v3, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e3", v3, v1, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A) .has(Edge.OUT_VERTEX_ID_PROPERTY_NAME, "v1") .has(Edge.IN_VERTEX_ID_PROPERTY_NAME, "v2") .edges(); assertEdgeIdsAnyOrder(edges, "e1"); edges = graph.query(AUTHORIZATIONS_A) .has(Edge.OUT_VERTEX_ID_PROPERTY_NAME, "v1") .edges(); assertEdgeIdsAnyOrder(edges, "e1", "e2"); }
@Test public void testGraphQueryForEdgesUsingInOrOutVertexId() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e2", v1, v3, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e3", v2, v3, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A) .has(Edge.IN_OR_OUT_VERTEX_ID_PROPERTY_NAME, "v1") .edges(); assertEdgeIdsAnyOrder(edges, "e1", "e2"); }
@Test public void testGraphQueryForEdgesUsingInOrOutVertexId() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v3 = graph.addVertex("v3", VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e2", v1, v3, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.addEdge("e3", v2, v3, LABEL_LABEL1, VISIBILITY_A, AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<Edge> edges = graph.query(AUTHORIZATIONS_A) .has(Edge.IN_OR_OUT_VERTEX_ID_PROPERTY_NAME, "v1") .edges(); assertEdgeIdsAnyOrder(edges, "e1", "e2"); }
@Test public void testAddEdgeWithoutIndexing() { assumeTrue("add edge without indexing not supported", !isDefaultSearchIndex()); Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A) .setProperty("prop1", "value1", VISIBILITY_A) .setIndexHint(IndexHint.DO_NOT_INDEX) .save(AUTHORIZATIONS_A); graph.flush(); Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A_AND_B) .has("prop1", "value1") .edges(); assertEdgeIds(edges); }
@Test public void testAddEdgeWithoutIndexing() { assumeTrue("add edge without indexing not supported", !isDefaultSearchIndex()); Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A) .setProperty("prop1", "value1", VISIBILITY_A) .setIndexHint(IndexHint.DO_NOT_INDEX) .save(AUTHORIZATIONS_A); graph.flush(); Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A_AND_B) .has("prop1", "value1") .edges(); assertEdgeIds(edges); }
@Test public void testDisableEdgeIndexing() { assumeTrue("disabling indexing not supported", disableEdgeIndexing(graph)); Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B); Vertex v2 = graph.prepareVertex("v2", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B); graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A) .setProperty("prop1", "value1", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A) .has("prop1", "value1") .edges(); Assert.assertEquals(0, count(edges)); }
@Test public void testDisableEdgeIndexing() { assumeTrue("disabling indexing not supported", disableEdgeIndexing(graph)); Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B); Vertex v2 = graph.prepareVertex("v2", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B); graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A) .setProperty("prop1", "value1", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A) .has("prop1", "value1") .edges(); Assert.assertEquals(0, count(edges)); }
.skip(offset) .limit(size) .edges();
@Test public void testGraphQueryEdgeHasWithSecurity() { Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B); Vertex v2 = graph.prepareVertex("v2", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B); Vertex v3 = graph.prepareVertex("v3", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B); graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A) .setProperty("age", 25, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareEdge("e2", v1, v3, LABEL_LABEL1, VISIBILITY_A) .setProperty("age", 25, VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A) .has("age", Compare.EQUAL, 25) .edges(); Assert.assertEquals(1, count(edges)); }
@Test public void testGraphQueryEdgeHasWithSecurity() { Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B); Vertex v2 = graph.prepareVertex("v2", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B); Vertex v3 = graph.prepareVertex("v3", VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B); graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_A) .setProperty("age", 25, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareEdge("e2", v1, v3, LABEL_LABEL1, VISIBILITY_A) .setProperty("age", 25, VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Edge> edges = graph.query(AUTHORIZATIONS_A) .has("age", Compare.EQUAL, 25) .edges(); Assert.assertEquals(1, count(edges)); }
.edges(FetchHints.EDGE_REFS);
.edges(FetchHints.EDGE_REFS);