@Test @LoadGraphWith(MODERN) public void shouldSucceedWithProperTraverserRequirements() throws Exception { final VertexProgramQ vp = VertexProgramQ.build().property("pl").create(); final Map<String, List<Integer>> expected = new HashMap<>(); expected.put("vadas", Collections.singletonList(2)); expected.put("lop", Arrays.asList(2, 2, 2, 3)); expected.put("josh", Collections.singletonList(2)); expected.put("ripple", Arrays.asList(2, 3)); try { g.V().repeat(__.out()).emit().program(vp).dedup() .valueMap("name", "pl").forEachRemaining((Map<Object, Object> map) -> { final String name = (String) ((List) map.get("name")).get(0); final List<Integer> pathLengths = (List<Integer>) map.get("pl"); assertTrue(expected.containsKey(name)); final List<Integer> expectedPathLengths = expected.remove(name); assertTrue(expectedPathLengths.containsAll(pathLengths)); assertTrue(pathLengths.containsAll(expectedPathLengths)); }); assertTrue(expected.isEmpty()); } catch (VerificationException ex) { assumeNoException(ex); } }
List<Vertex> partitions; if (abstractLabel instanceof VertexLabel) { partitions = traversalSource.V() .hasLabel(SQLG_SCHEMA + "." + Topology.SQLG_SCHEMA_SCHEMA) .has("name", abstractLabel.getSchema().getName()) .out(SQLG_SCHEMA_SCHEMA_VERTEX_EDGE) .has(SQLG_SCHEMA_VERTEX_LABEL_NAME, abstractLabel.getName()) .repeat(__.out(SQLG_SCHEMA_VERTEX_PARTITION_EDGE, SQLG_SCHEMA_PARTITION_PARTITION_EDGE)) .until(__.has(SQLG_SCHEMA_PARTITION_NAME, partition.getName())) .toList(); partitions = traversalSource.V() .hasLabel(SQLG_SCHEMA + "." + Topology.SQLG_SCHEMA_SCHEMA) .has("name", abstractLabel.getSchema().getName()) .out(SQLG_SCHEMA_OUT_EDGES_EDGE) .has(SQLG_SCHEMA_EDGE_LABEL_NAME, abstractLabel.getName()) .repeat(__.out(SQLG_SCHEMA_EDGE_PARTITION_EDGE, SQLG_SCHEMA_PARTITION_PARTITION_EDGE)) .until(__.has(SQLG_SCHEMA_PARTITION_NAME, partition.getName())) .toList(); Preconditions.checkState(partitions.size() == 1); Vertex partitionVertex = partitions.get(0); partitionVertex.remove();
public static GraphTraversal<?, ?> buildMatch(GraphTraversalSource g, Map<String, GraphTraversal<?, ?>> tableIdTraversalMap, List<Pair<String, String>> joinPairs, SchemaConfig schemaConfig, Map<String, GremlinToEnumerableConverter> tableIdConverterMap) { final GraphTraversal<?, ?> startTraversal = g.V(); final List<GraphTraversal<?, ?>> matchTraversals = new ArrayList<>(); if(joinPairs.size() > 1) { int pairs = joinPairs.size(); while (sorted.size() < pairs - 1) { String end = startPair.getValue(); if(labelInfo.getDirection().equals(Direction.OUT)) { if(leftTableDef.isVertex && rightTableDef.isVertex) { connectingTraversal = __.out(labelInfo.getLabel()); } else if(leftTableDef.isVertex && !rightTableDef.isVertex) { connectingTraversal = __.outE(labelInfo.getLabel()); return startTraversal.match(matchTraversals.toArray(new GraphTraversal<?, ?>[matchTraversals.size()]));
@Test @LoadGraphWith(MODERN) public void shouldSupportGraphFilter() throws Exception { fail("Should throw an unsupported operation exception"); } catch (final UnsupportedOperationException e) { assertEquals(GraphComputer.Exceptions.graphFilterNotSupported().getMessage(), e.getMessage()); fail("Should throw an unsupported operation exception"); } catch (final UnsupportedOperationException e) { assertEquals(GraphComputer.Exceptions.graphFilterNotSupported().getMessage(), e.getMessage()); graphProvider.getGraphComputer(graph).vertices(__.out()); fail(); } catch (final IllegalArgumentException e) { assertEquals(e.getMessage(), GraphComputer.Exceptions.vertexFilterAccessesIncidentEdges(__.out()).getMessage()); graphProvider.getGraphComputer(graph).edges(__.<Vertex>out().outE()); fail(); } catch (final IllegalArgumentException e) { assertEquals(e.getMessage(), GraphComputer.Exceptions.edgeFilterAccessesAdjacentVertices(__.<Vertex>out().outE()).getMessage());
@Test @LoadGraphWith(MODERN) public void shouldFilterComplexVertexCriterion() throws Exception { checkResults(Arrays.asList("vadas", "josh"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in("knows").has("name", "marko")).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in().has("name", "marko")).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in("knows").where(out("created").has("name", "lop"))).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in().where(has("name", "marko").out("created").has("name", "lop"))).create()). V().values("name")); checkResults(Arrays.asList("marko", "vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.or(both().has("name", "marko"), has("name", "marko"))).create()). V().where(bothE().count().is(P.neq(0))).values("name")); }
public void addToLastItemOfCollection(Vertex rawCollection, Vertex result) { if (curCollection == rawCollection && lastVertex != null) { //should be the one that usually called lastVertex.addEdge(TinkerpopSaver.NEXT_RAW_ITEM_EDGE_NAME, result); lastVertex = result; } else if (!rawCollection.edges(Direction.OUT, TinkerpopSaver.NEXT_RAW_ITEM_EDGE_NAME).hasNext()) { //should be called only once rawCollection.addEdge(TinkerpopSaver.NEXT_RAW_ITEM_EDGE_NAME, result); lastVertex = result; curCollection = rawCollection; } else { //should never be called LOG.error("This method is slow and ought to never be called."); Vertex previous = graphWrapper.getGraph().traversal().V(rawCollection.id()) .out(TinkerpopSaver.RAW_ITEM_EDGE_NAME) .not(__.where(__.out(TinkerpopSaver.NEXT_RAW_ITEM_EDGE_NAME))) .next(); previous.addEdge(TinkerpopSaver.NEXT_RAW_ITEM_EDGE_NAME, result); } }
@Test @LoadGraphWith(MODERN) public void shouldNotHaveAnonymousTraversalMixups() throws Exception { if (!g.getStrategies().getStrategy(TranslationStrategy.class).isPresent()) { logger.debug("No " + TranslationStrategy.class.getSimpleName() + " is registered and thus, skipping test."); return; } final GraphTraversalSource a = g; final GraphTraversalSource b = g.withoutStrategies(TranslationStrategy.class); assert a.getStrategies().getStrategy(TranslationStrategy.class).isPresent(); assert !b.getStrategies().getStrategy(TranslationStrategy.class).isPresent(); assertEquals(6l, a.V().out().count().next().longValue()); assertEquals(6l, b.V().out().count().next().longValue()); assert a.getStrategies().getStrategy(TranslationStrategy.class).isPresent(); assert !b.getStrategies().getStrategy(TranslationStrategy.class).isPresent(); assertEquals(2l, a.V().repeat(__.out()).times(2).count().next().longValue()); assertEquals(2l, b.V().repeat(__.out()).times(2).count().next().longValue()); assert a.getStrategies().getStrategy(TranslationStrategy.class).isPresent(); assert !b.getStrategies().getStrategy(TranslationStrategy.class).isPresent(); }
List<Vertex> partitions; if (abstractLabel instanceof VertexLabel) { partitions = traversalSource.V() .hasLabel(SQLG_SCHEMA + "." + Topology.SQLG_SCHEMA_SCHEMA) .has("name", abstractLabel.getSchema().getName()) .out(SQLG_SCHEMA_SCHEMA_VERTEX_EDGE) .has(SQLG_SCHEMA_VERTEX_LABEL_NAME, abstractLabel.getName()) .repeat(__.out(SQLG_SCHEMA_VERTEX_PARTITION_EDGE, SQLG_SCHEMA_PARTITION_PARTITION_EDGE)) .until(__.has(SQLG_SCHEMA_PARTITION_NAME, partition.getName())) .toList(); partitions = traversalSource.V() .hasLabel(SQLG_SCHEMA + "." + Topology.SQLG_SCHEMA_SCHEMA) .has("name", abstractLabel.getSchema().getName()) .out(SQLG_SCHEMA_OUT_EDGES_EDGE) .has(SQLG_SCHEMA_EDGE_LABEL_NAME, abstractLabel.getName()) .repeat(__.out(SQLG_SCHEMA_EDGE_PARTITION_EDGE, SQLG_SCHEMA_PARTITION_PARTITION_EDGE)) .until(__.has(SQLG_SCHEMA_PARTITION_NAME, partition.getName())) .toList(); Preconditions.checkState(partitions.size() == 1); Vertex partitionVertex = partitions.get(0); partitionVertex.remove();
@Test @LoadGraphWith(MODERN) public void shouldSupportGraphFilter() throws Exception { fail("Should throw an unsupported operation exception"); } catch (final UnsupportedOperationException e) { assertEquals(GraphComputer.Exceptions.graphFilterNotSupported().getMessage(), e.getMessage()); fail("Should throw an unsupported operation exception"); } catch (final UnsupportedOperationException e) { assertEquals(GraphComputer.Exceptions.graphFilterNotSupported().getMessage(), e.getMessage()); graphProvider.getGraphComputer(graph).vertices(__.out()); fail(); } catch (final IllegalArgumentException e) { assertEquals(e.getMessage(), GraphComputer.Exceptions.vertexFilterAccessesIncidentEdges(__.out()).getMessage()); graphProvider.getGraphComputer(graph).edges(__.<Vertex>out().outE()); fail(); } catch (final IllegalArgumentException e) { assertEquals(e.getMessage(), GraphComputer.Exceptions.edgeFilterAccessesAdjacentVertices(__.<Vertex>out().outE()).getMessage());
@Test @LoadGraphWith(MODERN) public void shouldFilterComplexVertexCriterion() throws Exception { checkResults(Arrays.asList("vadas", "josh"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in("knows").has("name", "marko")).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in().has("name", "marko")).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in("knows").where(out("created").has("name", "lop"))).create()). V().values("name")); checkResults(Arrays.asList("vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.<Vertex>in().where(has("name", "marko").out("created").has("name", "lop"))).create()). V().values("name")); checkResults(Arrays.asList("marko", "vadas", "josh", "lop"), g.withStrategies(SubgraphStrategy.build().vertices(__.or(both().has("name", "marko"), has("name", "marko"))).create()). V().where(bothE().count().is(P.neq(0))).values("name")); }
@Override public Traversal<Vertex, Map<String, Map<String, Map<String, Object>>>> getCoworkerSummaryOLTP() { return g.V().hasLabel("person").filter(outE("created")).as("p1") .V().hasLabel("person").where(neq("p1")).filter(outE("created")).as("p2") .map(out("created").where(in("created").as("p1")).values("name").fold()) .<String, Map<String, Map<String, Object>>>group().by(select("p1").by("name")). by(group().by(select("p2").by("name")). by(project("numCoCreated", "coCreated").by(count(local)).by())); }
@Test @LoadGraphWith(MODERN) public void shouldFailWithImproperTraverserRequirements() throws Exception { final VertexProgramQ vp = VertexProgramQ.build().property("pl").useTraverserRequirements(false).create(); try { g.V().repeat(__.out()).emit().program(vp).dedup() .forEachRemaining((Vertex v) -> assertFalse(v.property("pl").isPresent())); } catch (VerificationException ex) { assumeNoException(ex); } }
try { GraphTraversalSource traversalSource = sqlgGraph.topology(); List<Vertex> vertices = traversalSource.V() .hasLabel(SQLG_SCHEMA + "." + SQLG_SCHEMA_SCHEMA) .has("name", schema) .has("name", abstractLabel) .toList(); if (vertices.size() == 0) { throw new IllegalStateException("Found no vertex for " + schema + "." + abstractLabel); ); vertex.addEdge(SQLG_SCHEMA_VERTEX_PARTITION_EDGE, partition); .has("name", abstractLabel) .out(SQLG_SCHEMA_VERTEX_PARTITION_EDGE) .repeat(__.out(SQLG_SCHEMA_PARTITION_PARTITION_EDGE)) .until(__.has("name", partitionParent)) .toList(); .has("name", abstractLabel) .out(SQLG_SCHEMA_EDGE_PARTITION_EDGE) .repeat(__.out(SQLG_SCHEMA_PARTITION_PARTITION_EDGE)) .until(__.has("name", partitionParent)) .toList();