@Override public Traversal<Vertex, String> get_g_V_chooseXhasLabelXpersonX_valuesXnameX_constantXinhumanXX() { return g.V().choose(hasLabel("person"), values("name"), constant("inhuman")); } }
@Test @LoadGraphWith(MODERN) public void shouldFindShortestPathsWithStartEndVertexFilter() throws Exception { final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()). program(ShortestPathVertexProgram.build() .source(__.has("name", "marko")) .target(__.hasLabel("software")).create(graph)).submit().get(); assertTrue(result.memory().exists(ShortestPathVertexProgram.SHORTEST_PATHS)); final List<Path> shortestPaths = result.memory().get(ShortestPathVertexProgram.SHORTEST_PATHS); final List<Path> expected = Arrays.stream(ALL_SHORTEST_PATHS) .filter(p -> p[0].equals("marko") && Arrays.asList("lop", "ripple").contains(p[p.length - 1])) .map(helper::makePath).collect(Collectors.toList()); helper.checkResults(expected, shortestPaths); }
@Override public Traversal<Vertex, Path> get_g_V_hasXname_markoX_shortestPath_targetXhasLabelXsoftwareXX() { return g.V().has("name", "marko").shortestPath().with(target, __.hasLabel("software")); }
@Override public Traversal<Vertex, String> get_g_V_chooseXhasLabelXpersonX_and_outXcreatedX__outXknowsX__identityX_name() { return g.V().choose(hasLabel("person").and().out("created"), out("knows"), identity()).values("name"); }
private GraphTraversal<Vertex, Vertex> runMPTest(final Direction direction) throws Exception { final VertexProgramR svp = VertexProgramR.build().direction(direction).create(); final ComputerResult result = graphProvider.getGraphComputer(graph).program(svp).vertices(__.hasLabel(VertexProgramR.VERTEX_LABEL)).submit().get(); return result.graph().traversal().V().hasLabel(VertexProgramR.VERTEX_LABEL); }
@Test @LoadGraphWith(MODERN) public void shouldNotAllowBadGraphComputers() { try { graph.compute(BadGraphComputer.class); fail("Providing a bad graph computer class should fail"); } catch (Exception ex) { validateException(Graph.Exceptions.graphDoesNotSupportProvidedGraphComputer(BadGraphComputer.class), ex); } if (!new BadGraphComputer().features().supportsGraphFilter()) { try { new BadGraphComputer().vertices(__.hasLabel("software")); fail("Should throw an unsupported operation exception"); } catch (final UnsupportedOperationException e) { assertEquals(GraphComputer.Exceptions.graphFilterNotSupported().getMessage(), e.getMessage()); } try { new BadGraphComputer().edges(__.bothE()); fail("Should throw an unsupported operation exception"); } catch (final UnsupportedOperationException e) { assertEquals(GraphComputer.Exceptions.graphFilterNotSupported().getMessage(), e.getMessage()); } } else { fail("Should not support graph filter: " + BadGraphComputer.class); } }
graphProvider.getGraphComputer(graph).vertices(__.hasLabel("software")); fail("Should throw an unsupported operation exception"); } catch (final UnsupportedOperationException e) { graphProvider.getGraphComputer(graph).vertices(__.hasLabel("software")).program(new VertexProgramM(VertexProgramM.SOFTWARE_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).program(new VertexProgramM(VertexProgramM.PEOPLE_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).edges(__.bothE("knows")).program(new VertexProgramM(VertexProgramM.KNOWS_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).edges(__.bothE("knows")).program(new VertexProgramM(VertexProgramM.PEOPLE_KNOWS_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).edges(__.<Vertex>bothE("knows").has("weight", P.gt(0.5f))).program(new VertexProgramM(VertexProgramM.PEOPLE_KNOWS_WELL_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).edges(__.<Vertex>bothE().limit(0)).program(new VertexProgramM(VertexProgramM.VERTICES_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).edges(__.<Vertex>outE().limit(1)).program(new VertexProgramM(VertexProgramM.ONE_OUT_EDGE_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).vertices(__.hasLabel("software")).program(new VertexProgramM(VertexProgramM.SOFTWARE_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.SOFTWARE_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).program(new VertexProgramM(VertexProgramM.PEOPLE_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.PEOPLE_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).edges(__.bothE("knows")).program(new VertexProgramM(VertexProgramM.KNOWS_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.KNOWS_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).edges(__.bothE("knows")).program(new VertexProgramM(VertexProgramM.PEOPLE_KNOWS_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.PEOPLE_KNOWS_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).edges(__.<Vertex>bothE("knows").has("weight", P.gt(0.5f))).program(new VertexProgramM(VertexProgramM.PEOPLE_KNOWS_WELL_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.PEOPLE_KNOWS_WELL_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).edges(__.<Vertex>bothE().limit(0)).program(new VertexProgramM(VertexProgramM.VERTICES_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.VERTICES_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).edges(__.<Vertex>outE().limit(1)).program(new VertexProgramM(VertexProgramM.ONE_OUT_EDGE_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.ONE_OUT_EDGE_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).vertices(__.hasLabel("software")).mapReduce(new MapReduceJ(VertexProgramM.SOFTWARE_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).mapReduce(new MapReduceJ(VertexProgramM.PEOPLE_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).edges(__.bothE("knows")).mapReduce(new MapReduceJ(VertexProgramM.KNOWS_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).edges(__.bothE("knows")).mapReduce(new MapReduceJ(VertexProgramM.PEOPLE_KNOWS_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).edges(__.<Vertex>bothE("knows").has("weight", P.gt(0.5f))).mapReduce(new MapReduceJ(VertexProgramM.PEOPLE_KNOWS_WELL_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).edges(__.<Vertex>bothE().limit(0)).mapReduce(new MapReduceJ(VertexProgramM.VERTICES_ONLY)).submit().get(); graphProvider.getGraphComputer(graph).edges(__.<Vertex>outE().limit(1)).mapReduce(new MapReduceJ(VertexProgramM.ONE_OUT_EDGE_ONLY)).submit().get();
@Benchmark public GraphTraversal.Admin<Vertex,Vertex> testTranslationWithStrategy() { return translator.translate(g.withStrategies(ReadOnlyStrategy.instance()) .withStrategies(SubgraphStrategy.build().vertices(hasLabel("person")).create()) .V().out().in("link").out().in("link").asAdmin().getBytecode()); } }
@Override public GraphTraversal<Vertex, ? extends Element> applyTraversalInner( GraphTraversal<Vertex, ? extends Element> traversal, EmbeddedGraknTx<?> graph, Collection<Var> vars) { return traversal.not(__.hasLabel(Schema.BaseType.SHARD.name())); }
@Override public void applyTraversal(GraphTraversal<Vertex, Vertex> traversal) { traversal.not(__.hasLabel(Schema.BaseType.CASTING.name())); }
checkResults(Arrays.asList("aachen", "purcellville", "santa fe", "seattle"), sg.V().propertyMap("location").select(Column.values).unfold().unfold().value()); sg = g.withStrategies(SubgraphStrategy.build().edges(__.<Edge>hasLabel("uses").has("skill", 5)).create()); checkResults(Arrays.asList(5, 5, 5), sg.V().outE().valueMap().select(Column.values).unfold()); checkResults(Arrays.asList(5, 5, 5), sg.V().outE().propertyMap().select(Column.values).unfold().value());
@Override public void applyTraversal(GraphTraversal<Vertex, Vertex> traversal) { // Whenever looking up by ID, we have to confirm this is not a casting traversal.has(ITEM_IDENTIFIER.name(), id).not(__.hasLabel(CASTING.name())); }
@Override public Traversal<Vertex, String> get_g_V_chooseXhasLabelXpersonX_valuesXnameX_constantXinhumanXX() { return g.V().choose(hasLabel("person"), values("name"), constant("inhuman")); } }
@Override public Traversal<Vertex, Path> get_g_V_hasXname_markoX_shortestPath_targetXhasLabelXsoftwareXX() { return g.V().has("name", "marko").shortestPath().with(target, __.hasLabel("software")); }
@Override public void applyTraversal(GraphTraversal<Vertex, Vertex> traversal) { if (!allowCastings) { // Make sure we never get instances of role types traversal.not(__.hasLabel(ROLE_TYPE.name())); } inSubs(inSubs(traversal).in(ISA.getLabel())); }
@Override public void applyTraversal(GraphTraversal<Vertex, Vertex> traversal) { if (!allowCastings) { // Make sure we never get castings' types traversal.not(__.hasLabel(CASTING.name())); } outSubs(outSubs(traversal).out(ISA.getLabel())); }
@Override public Traversal<Vertex, String> get_g_V_chooseXhasLabelXpersonX_and_outXcreatedX__outXknowsX__identityX_name() { return g.V().choose(hasLabel("person").and().out("created"), out("knows"), identity()).values("name"); }
static <T> GraphTraversal<T, Vertex> inSubs(GraphTraversal<T, Vertex> traversal) { // These traversals make sure to only navigate types by checking they do not have a `THING_TYPE_LABEL_ID` property return union(traversal, ImmutableSet.of( __.<Vertex>not(__.has(THING_TYPE_LABEL_ID.name())).not(__.hasLabel(Schema.BaseType.SHARD.name())), __.repeat(__.in(SUB.getLabel())).emit() )).unfold(); }
private GraphTraversal<Vertex, Vertex> runMPTest(final Direction direction) throws Exception { final VertexProgramR svp = VertexProgramR.build().direction(direction).create(); final ComputerResult result = graphProvider.getGraphComputer(graph).program(svp).vertices(__.hasLabel(VertexProgramR.VERTEX_LABEL)).submit().get(); return result.graph().traversal().V().hasLabel(VertexProgramR.VERTEX_LABEL); }
static <T> GraphTraversal<T, Vertex> outSubs(GraphTraversal<T, Vertex> traversal) { // These traversals make sure to only navigate types by checking they do not have a `THING_TYPE_LABEL_ID` property return union(traversal, ImmutableSet.of( __.<Vertex>not(__.has(THING_TYPE_LABEL_ID.name())).not(__.hasLabel(Schema.BaseType.SHARD.name())), __.repeat(__.out(SUB.getLabel())).emit() )).unfold(); }