assertNumStep(numV / 5, 1, gts.V(sv[0]).outE("knows").has("weight", 1), TitanVertexStep.class); assertNumStep(numV, 1, gts.V(sv[0]).outE("knows"), TitanVertexStep.class); assertNumStep(numV, 1, gts.V(sv[0]).out("knows"), TitanVertexStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").limit(10)), TitanVertexStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").range(10, 20)), LocalStep.class); assertNumStep(numV, 2, gts.V(sv[0]).outE("knows").order().by("weight", decr), TitanVertexStep.class, OrderGlobalStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").order().by("weight", decr).limit(10)), TitanVertexStep.class); assertNumStep(numV / 5, 2, gts.V(sv[0]).outE("knows").has("weight", 1).order().by("weight", incr), TitanVertexStep.class, OrderGlobalStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).order().by("weight", incr).limit(10)), TitanVertexStep.class); assertNumStep(5, 1, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).has("weight", 1).order().by("weight", incr).range(10, 15)), LocalStep.class); assertNumStep(1, 1, gts.V(sv[0]).outE("knows").filter(__.inV().is(vs[50])), TitanVertexStep.class); assertNumStep(1, 1, gts.V(sv[0]).outE("knows").filter(__.otherV().is(vs[50])), TitanVertexStep.class); assertNumStep(1, 1, gts.V(sv[0]).bothE("knows").filter(__.otherV().is(vs[50])), TitanVertexStep.class); assertNumStep(1, 2, gts.V(sv[0]).bothE("knows").filter(__.inV().is(vs[50])), TitanVertexStep.class, TraversalFilterStep.class); assertNumStep(numV / 5, 1, gts.V(sv[0]).properties("names").has("weight", 1), TitanPropertiesStep.class); assertNumStep(numV, 1, gts.V(sv[0]).properties("names"), TitanPropertiesStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.properties("names").order().by("weight", decr).limit(10)), TitanPropertiesStep.class); assertNumStep(numV, 2, gts.V(sv[0]).outE("knows").values("weight"), TitanVertexStep.class, TitanPropertiesStep.class); assertNumStep(1, 1, gts.V().has("id", numV / 5), TitanGraphStep.class); assertNumStep(1, 1, gts.V().has("id", numV / 5).has("weight", (numV / 5) % 5), TitanGraphStep.class); assertNumStep(numV / 5, 1, gts.V().has("weight", 1), TitanGraphStep.class); assertNumStep(10, 1, gts.V().has("weight", 1).range(0, 10), TitanGraphStep.class); assertNumStep(superV, 1, gts.V().has("id", sid), TitanGraphStep.class); assertNumStep(1, 1, gts.V().has("id", numV / 5).as("x"), TitanGraphStep.class); assertNumStep(1, 1, gts.V().has("id", numV / 5).has("weight", (numV / 5) % 5).as("x"), TitanGraphStep.class);
private void addGeoshape(Function<Geoshape,Geoshape> makeGeoshape) { JanusGraphTransaction tx = graph.newTransaction(); graph.traversal().E().has("place").toList().forEach(e-> { Geoshape place = (Geoshape) e.property("place").value(); e.property("shape", makeGeoshape.apply(place)); }); tx.commit(); }
private void testOr(final Graph aGraph) { final GraphTraversalSource g = aGraph.traversal(); final Vertex hiro = g.addV().property("name", "Hiro").property("age", 2).property("length", 90).next(); final Vertex totoro = g.addV().property("name", "Totoro").property("age", 1).next(); final Vertex john = g.addV().property("name", "John").property("age", 3).property("length", 110).next(); final Vertex mike = g.addV().property("name", "Mike").property("age", 4).property("length", 130).next(); aGraph.tx().commit(); assertCount(1, g.V().has("name", "Totoro")); assertCount(1, g.V().has("age", 2)); assertCount(1, g.V().or(__.has("name", "Hiro"),__.has("age", 2))); assertCount(2, g.V().or(__.has("name", "Totoro"),__.has("age", 2))); assertCount(2, g.V().or(__.has("name", "Totoro").has("age", 1),__.has("age", 2))); assertCount(2, g.V().or(__.and(__.has("name", "Totoro"), __.has("age", 1)),__.has("age", 2))); assertTraversal(g.V().has("length", P.lte(100)).or(__.has("name", "Totoro"),__.has("age", P.gte(2))), hiro); assertTraversal(g.V().or(__.has("name", "Totoro"),__.has("age", P.gte(2))).has("length", P.lte(100)), hiro); assertTraversal(g.V().or(__.has("name", "Totoro"),__.has("age", 2)).order().by(ORDER_AGE_DECR), hiro, totoro); assertTraversal(g.V().or(__.has("name", "Totoro"),__.has("age", 2)).order().by(ORDER_AGE_INCR), totoro, hiro); assertTraversal(g.V().or(__.has("name", "Hiro"),__.has("age", 2)).order().by(ORDER_AGE_INCR), hiro); assertTraversal(g.V().or(__.has("name", "Totoro"), __.has("length", P.lte(120)).order().by(ORDER_LENGTH_DECR)), totoro, john, hiro); assertTraversal(g.V().or(__.has("name", "Totoro"), __.has("length", P.lte(120)).order().by(ORDER_LENGTH_INCR)), totoro, hiro, john); assertTraversal(g.V().or(__.has("name", "John"), __.has("length", P.lte(120)).order().by(ORDER_LENGTH_INCR)), john, hiro); assertTraversal(g.V().or(__.has("name", "Totoro"), __.has("length", P.lte(120)).order().by(ORDER_AGE_DECR)), totoro, john, hiro); assertTraversal(g.V().or(__.has("name", "Totoro"), __.has("length", P.lte(120)).order().by(ORDER_AGE_INCR)), totoro, hiro, john); assertTraversal(g.V().or(__.has("name", "Totoro"), __.has("length", P.lte(120)).order().by(ORDER_LENGTH_DECR)).order().by(ORDER_AGE_INCR), totoro, hiro, john);
@Override public GraphTraversalSource traversal(final Graph graph, final TraversalStrategy... strategies) { return new GraphTraversalSource(graph).withComputer(FulgoraGraphComputer.class).withStrategies(strategies); }
@Override public GraphTraversalSource traversal(final Graph graph) { return new GraphTraversalSource(graph).withComputer(FulgoraGraphComputer.class); }
@Test public void testSimpleTinkerPopTraversal() { Vertex v1 = graph.addVertex("name", "josh"); Vertex v2 = graph.addVertex("name", "lop"); v1.addEdge("created", v2); //graph.tx().commit(); Object id = graph.traversal().V().has("name", "josh").outE("created").as("e").inV().has("name", "lop").<Edge>select("e").next().id(); assertNotNull(id); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldTriggerAddVertexPropertyChanged() { final StubMutationListener listener1 = new StubMutationListener(); final StubMutationListener listener2 = new StubMutationListener(); final EventStrategy.Builder builder = EventStrategy.build() .addListener(listener1) .addListener(listener2); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final Vertex vSome = graph.addVertex("some", "thing"); vSome.property(VertexProperty.Cardinality.single, "that", "thing"); final GraphTraversalSource gts = create(eventStrategy); final Vertex vAny = gts.V().addV().property("any", "thing").next(); gts.V(vAny).property(VertexProperty.Cardinality.single, "any", "thing else").next(); tryCommit(graph, g -> assertEquals(1, IteratorUtils.count(gts.V().has("any", "thing else")))); assertEquals(1, listener1.addVertexEventRecorded()); assertEquals(1, listener2.addVertexEventRecorded()); assertEquals(1, listener2.vertexPropertyChangedEventRecorded()); assertEquals(1, listener1.vertexPropertyChangedEventRecorded()); }
v1.property(property, value1); v1 = getV(graph, v1.id()); v1.property(property, value2); g.V().drop().iterate(); v1 = g.addV().property(property, value1).property(property, value2).next(); g.addV().property(property, value1).property(property, value2).next(); assertEquals(2, g.V().has(property, value1).toList().size()); g.V().properties().drop().iterate(); assertFalse(g.V().has(property, value1).hasNext()); assertFalse(g.V().has(property, value2).hasNext());
/** * Get all {@link InlineHintModel} instances attached to this {@link ReportFileModel} */ default List<InlineHintModel> getInlineHints() { List<Vertex> vertices = new GraphTraversalSource(getWrappedGraph().getBaseGraph()).V(getElement()) .in(FileReferenceModel.FILE_MODEL) .has(WindupVertexFrame.TYPE_PROP, InlineHintModel.TYPE) .toList(); return vertices.stream().map(v -> getGraph().frameElement(v, InlineHintModel.class)) .collect(Collectors.toList()); }
Vertex v10086 = graph.addVertex(T.label, "phone", "no", "10086"); Assert.assertEquals(8, graph.traversal().E().toList().size()); List<Edge> edges = graph.traversal().V(v1).outE("call") .has("calltime", "2017-5-3 12:08:02") Assert.assertEquals(Utils.date("2017-5-3 12:08:02"), edges.get(0).value("calltime")); edges = graph.traversal().V(v1).outE("call") .has("calltime", P.lt("2017-5-2")) edges = graph.traversal().V(v1).outE("call") .has("calltime", P.gte("2017-5-3")) edges = graph.traversal().V(v1).outE("call") .has("calltime", P.gte("2017-5-3")) .where(__.otherV().hasId(v2.id())) edges = graph.traversal().V(v1).outE("call") Assert.assertEquals(5, edges.size()); edges = graph.traversal().V(v1).outE("call") .has("calltime", P.between("2017-5-2","2017-5-4")) .where(__.not(__.otherV().hasId((v10086.id()))))
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldGenerateDefaultIdOnGraphAddVWithSpecifiedId() throws Exception { final ElementIdStrategy strategy = ElementIdStrategy.build().create(); final GraphTraversalSource sg = create(strategy); final Vertex v = sg.addV().property(T.id, "STEPHEN").property("name", "stephen").next(); assertEquals("stephen", v.value("name")); assertEquals("STEPHEN", sg.V(v).id().next()); assertEquals("STEPHEN", sg.V("STEPHEN").id().next()); }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) public void shouldTriggerAddEdge() { final StubMutationListener listener1 = new StubMutationListener(); final StubMutationListener listener2 = new StubMutationListener(); final EventStrategy.Builder builder = EventStrategy.build() .addListener(listener1) .addListener(listener2); if (graph.features().graph().supportsTransactions()) builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph)); final EventStrategy eventStrategy = builder.create(); final Vertex v = graph.addVertex(); v.addEdge("self", v); final GraphTraversalSource gts = create(eventStrategy); gts.V(v).as("v").addE("self").to("v").next(); tryCommit(graph, g -> assertEquals(2, IteratorUtils.count(gts.E()))); assertEquals(0, listener1.addVertexEventRecorded()); assertEquals(0, listener2.addVertexEventRecorded()); assertEquals(1, listener1.addEdgeEventRecorded()); assertEquals(1, listener2.addEdgeEventRecorded()); }
@Benchmark public GraphTraversal.Admin<Vertex,Vertex> testTranslationLong() { return translator.translate(g.V().match( as("a").has("song", "name", "HERE COMES SUNSHINE"), as("a").map(inE("followedBy").values("weight").mean()).as("b"), as("a").inE("followedBy").as("c"), as("c").filter(values("weight").where(P.gte("b"))).outV().as("d")). <String>select("d").by("name").asAdmin().getBytecode()); }
public String generateGremlin() { final int targetStepCount = rand.nextInt(10); final StringBuilder sb = new StringBuilder("g.V()"); final Vertex start = syntaxGraph.traversal().V().has("starter", true).order().by(this::shuffle).next(); sb.append((String) start.value("step")); syntaxGraph.traversal().V(start).times(targetStepCount - 1).repeat( __.local(__.outE().has("weight", P.gte(rand.nextDouble())) .inV().order().by(this::shuffle).limit(1)).sideEffect(t -> sb.append((String) t.get().value("step"))) ).iterate(); return sb.toString(); }
@Test public void testTinkerPopCardinality() { PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); PropertyKey name = mgmt.makePropertyKey("name").cardinality(Cardinality.SINGLE).dataType(String.class).make(); PropertyKey names = mgmt.makePropertyKey("names").cardinality(Cardinality.LIST).dataType(String.class).make(); mgmt.buildIndex("byId", Vertex.class).addKey(id).buildCompositeIndex(); finishSchema(); GraphTraversalSource gts; Vertex v; v = graph.addVertex("id", 1); v.property(single, "name", "t1"); graph.addVertex("id", 2, "names", "n1", "names", "n2"); graph.tx().commit(); gts = graph.traversal(); v = gts.V().has("id", 1).next(); v.property(single, "name", "t2"); v = gts.V().has("id", 1).next(); v.property(single, "name", "t3"); assertCount(1, gts.V(v).properties("name")); assertCount(2, gts.V().has("id", 2).properties("names")); assertCount(2, gts.V().hasLabel("vertex")); }
@Test @LoadGraphWith(MODERN) public void shouldSupportMultipleScopesWithEdgeFunction() throws ExecutionException, InterruptedException { final ComputerResult result = graphProvider.getGraphComputer(graph).program(new MultiScopeVertexWithEdgeFunctionProgram()).submit().get(); assertEquals(result.graph().traversal().V().has("name", "josh").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 0L); assertEquals(result.graph().traversal().V().has("name", "lop").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 4L); assertEquals(result.graph().traversal().V().has("name", "ripple").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 10L); assertEquals(result.graph().traversal().V().has("name", "marko").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 20L); }
@Test @LoadGraphWith(MODERN) public void shouldFilterVertexCriterionAndKeepLabels() throws Exception { // this will exclude "peter" final Traversal<Vertex, ?> vertexCriterion = has("name", P.within("ripple", "josh", "marko")); final GraphTraversalSource sg = g.withStrategies(SubgraphStrategy.build().vertices(vertexCriterion).create()); assertEquals(9, g.V().as("a").out().in().as("b").dedup("a", "b").count().next().intValue()); assertEquals(2, sg.V().as("a").out().in().as("b").dedup("a", "b").count().next().intValue()); final List<Object> list = sg.V().as("a").out().in().as("b").dedup("a", "b").values("name").toList(); assertThat(list, hasItems("marko", "josh")); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE) @FeatureRequirement(featureClass = Graph.Features.EdgePropertyFeatures.class, feature = Graph.Features.EdgePropertyFeatures.FEATURE_DOUBLE_VALUES) public void shouldNotBeEqualPropertiesAsThereIsDifferentKey() { final Object joshCreatedLopEdgeId = convertToEdgeId("josh", "created", "lop"); final Edge e = g.V(convertToVertexId("josh")).next().addEdge("created", g.V(convertToVertexId("lop")).next(), "weight", 0.4d); assertFalse(DetachedFactory.detach(e.property("weight")).equals(DetachedFactory.detach(g.E(joshCreatedLopEdgeId).next().property("weight")))); } }