org.apache.tinkerpop.gremlin.structure.Edge Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.Edge.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AddEdgeTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(MODERN) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) public void g_addEXknowsX_fromXaX_toXbX_propertyXweight_0_1X() { final Vertex a = g.V().has("name", "marko").next(); final Vertex b = g.V().has("name", "peter").next(); final Traversal<Edge, Edge> traversal = get_g_addEXknowsX_fromXaX_toXbX_propertyXweight_0_1X(a, b); printTraversalForm(traversal); final Edge edge = traversal.next(); assertEquals(edge.outVertex(), convertToVertex(graph, "marko")); assertEquals(edge.inVertex(), convertToVertex(graph, "peter")); assertEquals("knows", edge.label()); assertEquals(1, IteratorUtils.count(edge.properties())); assertEquals(0.1d, edge.value("weight"), 0.1d); assertEquals(6L, g.V().count().next().longValue()); assertEquals(7L, g.E().count().next().longValue()); }
Example #2
Source File: TestBatchNormalUpdateDateTime.java From sqlg with MIT License | 6 votes |
@Test public void batchUpdateZonedDateTimeEdge() throws InterruptedException { this.sqlgGraph.tx().normalBatchModeOn(); ZonedDateTime zonedDateTime = ZonedDateTime.now(); for (int i = 0; i < 10; i++) { Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person", "createOn", zonedDateTime); Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person", "createOn", zonedDateTime); v1.addEdge("test", v2, "createOn", zonedDateTime); } this.sqlgGraph.tx().commit(); List<Edge> edges = this.sqlgGraph.traversal().E().toList(); Assert.assertEquals(10, edges.size()); Assert.assertEquals(zonedDateTime, edges.get(0).value("createOn")); this.sqlgGraph.tx().normalBatchModeOn(); zonedDateTime = ZonedDateTime.now().minusDays(1); for (Edge edge : edges) { edge.property("createOn", zonedDateTime); } this.sqlgGraph.tx().commit(); batchUpdateZonedDateTimeEdge_assert(this.sqlgGraph, zonedDateTime); if (this.sqlgGraph1 != null) { Thread.sleep(SLEEP_TIME); batchUpdateZonedDateTimeEdge_assert(this.sqlgGraph1, zonedDateTime); } }
Example #3
Source File: TestBatch.java From sqlg with MIT License | 6 votes |
@Test public void testBatchRemoveVerticesAndEdges() throws InterruptedException { Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person"); Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person"); Vertex v3 = this.sqlgGraph.addVertex(T.label, "Person"); Edge edge1 = v1.addEdge("test", v2); Edge edge2 = v1.addEdge("test", v3); this.sqlgGraph.tx().commit(); this.sqlgGraph.tx().normalBatchModeOn(); edge1.remove(); edge2.remove(); v1.remove(); v2.remove(); v3.remove(); this.sqlgGraph.tx().commit(); testBatchRemoveVerticesAndEdges_assert(this.sqlgGraph); if (this.sqlgGraph1 != null) { Thread.sleep(1000); testBatchRemoveVerticesAndEdges_assert(this.sqlgGraph1); } }
Example #4
Source File: TestBatchServerSideEdgeCreation.java From sqlg with MIT License | 6 votes |
@Test public void testBulkAddEdgesStringAndIntegerIds() throws InterruptedException { Vertex realWorkspaceElement1 = this.sqlgGraph.addVertex(T.label, "RealWorkspaceElement", "cmUid", "a"); Vertex realWorkspaceElement2 = this.sqlgGraph.addVertex(T.label, "RealWorkspaceElement", "cmUid", "b"); Vertex virtualGroup = this.sqlgGraph.addVertex(T.label, "VirtualGroup", "name", "asd"); this.sqlgGraph.tx().commit(); Edge e =realWorkspaceElement1.addEdge("realWorkspaceElement_virtualGroup", virtualGroup); this.sqlgGraph.tx().commit(); e.remove(); this.sqlgGraph.tx().commit(); this.sqlgGraph.tx().streamingBatchModeOn(); List<Pair<String, Integer>> ids = new ArrayList<>(); ids.add(Pair.of("a", 1)); ids.add(Pair.of("b", 1)); this.sqlgGraph.bulkAddEdges("RealWorkspaceElement", "VirtualGroup", "realWorkspaceElement_virtualGroup", Pair.of("cmUid", "ID"), ids); this.sqlgGraph.tx().commit(); testBulkAddEdgeStringAndIntegerIds_assert(this.sqlgGraph, realWorkspaceElement1, realWorkspaceElement2, virtualGroup); if (this.sqlgGraph1 != null) { Thread.sleep(SLEEP_TIME); testBulkAddEdgeStringAndIntegerIds_assert(this.sqlgGraph1, realWorkspaceElement1, realWorkspaceElement2, virtualGroup); } }
Example #5
Source File: EdgeAPI.java From hugegraph with Apache License 2.0 | 6 votes |
@GET @Timed @Path("{id}") @Produces(APPLICATION_JSON_WITH_CHARSET) @RolesAllowed({"admin", "$owner=$graph $action=edge_read"}) public String get(@Context GraphManager manager, @PathParam("graph") String graph, @PathParam("id") String id) { LOG.debug("Graph [{}] get edge by id '{}'", graph, id); HugeGraph g = graph(manager, graph); try { Iterator<Edge> edges = g.edges(id); checkExist(edges, HugeType.EDGE, id); return manager.serializer(g).writeEdge(edges.next()); } finally { if (g.tx().isOpen()) { g.tx().close(); } } }
Example #6
Source File: DatabaseFixerTest.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
@Test public void fixAddsAVersionOfRelation() { String vertex1CreatedProp = changeStringWithTimestamp(1500L); GraphWrapper graphWrapper = newGraph().withVertex("v1", v -> v.withTimId("id1") .withProperty("rev", 2) .withProperty("modified", changeStringWithTimestamp(10000L)) .withProperty("created", vertex1CreatedProp) .withProperty("isLatest", true)) .wrap(); DatabaseFixer instance = new DatabaseFixer(graphWrapper); instance.fix(); Optional<Vertex> vertex = graphWrapper.getGraph().traversal().V().has("tim_id", "id1").has("rev", 1).tryNext(); assertThat(vertex, is(present())); Iterator<Edge> versionOfRelations = vertex.get().edges(Direction.OUT, "VERSION_OF"); assertThat(versionOfRelations.hasNext(), is(true)); }
Example #7
Source File: TestVertexNavToEdges.java From sqlg with MIT License | 6 votes |
@Test public void testInOut() { Vertex v1 = sqlgGraph.addVertex(); Vertex v2 = sqlgGraph.addVertex(); Vertex v3 = sqlgGraph.addVertex(); Vertex v4 = sqlgGraph.addVertex(); Vertex v5 = sqlgGraph.addVertex(); Edge e1 = v1.addEdge("label1", v2); Edge e2 = v2.addEdge("label2", v3); Edge e3 = v3.addEdge("label3", v4); sqlgGraph.tx().commit(); assertEquals(1, vertexTraversal(this.sqlgGraph, v2).inE().count().next(), 1); assertEquals(e1, vertexTraversal(this.sqlgGraph, v2).inE().next()); assertEquals(1L, edgeTraversal(this.sqlgGraph, e1).inV().count().next(), 0); assertEquals(v2, edgeTraversal(this.sqlgGraph, e1).inV().next()); assertEquals(0L, edgeTraversal(this.sqlgGraph, e1).outV().inE().count().next(), 0); assertEquals(1L, edgeTraversal(this.sqlgGraph, e2).inV().count().next(), 0); assertEquals(v3, edgeTraversal(this.sqlgGraph, e2).inV().next()); }
Example #8
Source File: PageRankVertexProgramStep.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void configure(final Object... keyValues) { if (keyValues[0].equals(PageRank.edges)) { if (!(keyValues[1] instanceof Traversal)) throw new IllegalArgumentException("PageRank.edges requires a Traversal as its argument"); this.edgeTraversal = new PureTraversal<>(((Traversal<Vertex,Edge>) keyValues[1]).asAdmin()); this.integrateChild(this.edgeTraversal.get()); } else if (keyValues[0].equals(PageRank.propertyName)) { if (!(keyValues[1] instanceof String)) throw new IllegalArgumentException("PageRank.propertyName requires a String as its argument"); this.pageRankProperty = (String) keyValues[1]; } else if (keyValues[0].equals(PageRank.times)) { if (!(keyValues[1] instanceof Integer)) throw new IllegalArgumentException("PageRank.times requires an Integer as its argument"); this.times = (int) keyValues[1]; } else { this.parameters.set(this, keyValues); } }
Example #9
Source File: FileLogOutput.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
@Override public void newEdge(Edge edge) { String modifiedString = edge.value("modified"); try { Change modified = objectMapper.readValue(modifiedString, Change.class); writeAndFlush( String.format( "%d - Edge with tim_id '%s' between Vertex with tim_id '%s' and Vertex with tim_id '%s' created.%n", modified.getTimeStamp(), edge.value("tim_id"), edge.outVertex().value("tim_id"), edge.inVertex().value("tim_id"))); } catch (IOException e) { throw new RuntimeException(e); } }
Example #10
Source File: VertexTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(MODERN) public void g_VX4X_bothE() { final Traversal<Vertex, Edge> traversal = get_g_VX4X_bothE(convertToVertexId("josh")); printTraversalForm(traversal); int counter = 0; final Set<Edge> edges = new HashSet<>(); while (traversal.hasNext()) { counter++; final Edge edge = traversal.next(); edges.add(edge); assertTrue(edge.label().equals("knows") || edge.label().equals("created")); } assertEquals(3, counter); assertEquals(3, edges.size()); }
Example #11
Source File: TestTraversalAddV.java From sqlg with MIT License | 6 votes |
@Test public void g_addV_asXfirstX_repeatXaddEXnextX_toXaddVX_inVX_timesX5X_addEXnextX_toXselectXfirstXX() { final Traversal<Vertex, Edge> traversal = this.sqlgGraph.traversal() .addV().as("first") .repeat( __.addE("next").to(__.addV()).inV()).times(5) .addE("next") .to(__.select("first")); printTraversalForm(traversal); Assert.assertEquals("next", traversal.next().label()); Assert.assertFalse(traversal.hasNext()); Assert.assertEquals(6L, this.sqlgGraph.traversal().V().count().next().longValue()); Assert.assertEquals(6L, this.sqlgGraph.traversal().E().count().next().longValue()); Assert.assertEquals(Arrays.asList(2L, 2L, 2L, 2L, 2L, 2L), this.sqlgGraph.traversal().V().map(__.bothE().count()).toList()); Assert.assertEquals(Arrays.asList(1L, 1L, 1L, 1L, 1L, 1L), this.sqlgGraph.traversal().V().map(__.inE().count()).toList()); Assert.assertEquals(Arrays.asList(1L, 1L, 1L, 1L, 1L, 1L), this.sqlgGraph.traversal().V().map(__.outE().count()).toList()); }
Example #12
Source File: TestGremlinCompileWithInOutV.java From sqlg with MIT License | 5 votes |
@Test public void testToFromEdge() throws InterruptedException { Vertex a = this.sqlgGraph.addVertex(T.label, "A"); Vertex b = this.sqlgGraph.addVertex(T.label, "B"); Edge e1 = a.addEdge("outB", b); this.sqlgGraph.tx().commit(); testToFromEdge_assert(this.sqlgGraph, a); if (this.sqlgGraph1 != null) { Thread.sleep(SLEEP_TIME); testToFromEdge_assert(this.sqlgGraph1, a); } }
Example #13
Source File: GraphMLReader.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * This method is not supported for this reader. * * @throws UnsupportedOperationException when called. */ @Override public Vertex readVertex(final InputStream inputStream, final Function<Attachable<Vertex>, Vertex> vertexAttachMethod, final Function<Attachable<Edge>, Edge> edgeAttachMethod, final Direction attachEdgesOfThisDirection) throws IOException { throw Io.Exceptions.readerFormatIsForFullGraphSerializationOnly(this.getClass()); }
Example #14
Source File: HugeVertex.java From hugegraph with Apache License 2.0 | 5 votes |
public Iterator<Edge> getEdges(Directions direction, String... edgeLabels) { List<Edge> list = new LinkedList<>(); for (HugeEdge edge : this.edges) { if (edge.matchDirection(direction) && edge.belongToLabels(edgeLabels)) { list.add(edge); } } return list.iterator(); }
Example #15
Source File: JavaExample.java From janusgraph-java-example with Apache License 2.0 | 5 votes |
public static void main(String[] args) { JanusGraph graph = JanusGraphFactory.open("conf/janusgraph-berkeleyje-lucene.properties"); GraphTraversalSource g = graph.traversal(); if (g.V().count().next() == 0) { // load the schema and graph data GraphOfTheGodsFactory.load(graph); } Map<Object, Object> saturnProps = g.V().has("name", "saturn").valueMap(true).next(); LOGGER.info(saturnProps.toString()); List<Edge> places = g.E().has("place", Geo.geoWithin(Geoshape.circle(37.97, 23.72, 50))).toList(); LOGGER.info(places.toString()); System.exit(0); }
Example #16
Source File: IdIndexChangeListenerTest.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
@Test public void onEdgeUpdateCallsTheIndexHandler() { UUID timId = UUID.randomUUID(); Edge edge = edgeWithId(timId); Edge nullEdge = null; instance.onEdgeUpdate(NULL_COLLECTION, nullEdge, edge); verify(indexHandler).upsertIntoEdgeIdIndex(timId, edge); }
Example #17
Source File: IndexLabelCoreTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testRebuildIndexLabelOfEdge() { super.initPropertyKeys(); SchemaManager schema = graph().schema(); schema.vertexLabel("author").properties("id", "name") .primaryKeys("id").create(); schema.vertexLabel("book").properties("name") .primaryKeys("name").create(); schema.edgeLabel("authored").singleTime() .link("author", "book") .properties("contribution") .create(); Vertex james = graph().addVertex(T.label, "author", "id", 1, "name", "James Gosling"); Vertex java1 = graph().addVertex(T.label, "book", "name", "java-1"); schema.indexLabel("authoredByContri").onE("authored") .secondary().by("contribution").create(); EdgeLabel authored = schema.getEdgeLabel("authored"); Assert.assertEquals(1, authored.indexLabels().size()); assertContainsIl(authored.indexLabels(), "authoredByContri"); james.addEdge("authored", java1,"contribution", "test"); graph().tx().commit(); Edge edge = graph().traversal().E().hasLabel("authored") .has("contribution", "test").next(); Assert.assertNotNull(edge); schema.edgeLabel("authored").rebuildIndex(); Assert.assertEquals(1, authored.indexLabels().size()); assertContainsIl(authored.indexLabels(), "authoredByContri"); edge = graph().traversal().E().hasLabel("authored") .has("contribution", "test").next(); Assert.assertNotNull(edge); }
Example #18
Source File: TestLocalEdgeVertexStep.java From sqlg with MIT License | 5 votes |
@Test public void testLocalEdgeVertexStep() { Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1"); Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1"); Edge e1 = a1.addEdge("ab", b1); this.sqlgGraph.tx().commit(); List<Vertex> vertices = this.sqlgGraph.traversal().V(a1).local(__.outE("ab").inV()).toList(); assertEquals(1, vertices.size()); assertEquals(b1, vertices.get(0)); }
Example #19
Source File: TestArrayProperties.java From sqlg with MIT License | 5 votes |
@Test public void testLongPrimitiveArrayProperties() { Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsLongArrayValues()); Vertex vertex1 = this.sqlgGraph.addVertex(T.label, "Person", "age", new long[]{1, 2, 3, 4, 5}); Vertex vertex2 = this.sqlgGraph.addVertex(T.label, "Person", "age", new long[]{1, 2, 3, 4, 5}); vertex1.addEdge("test", vertex2, "age", new long[]{1, 2, 3, 4, 5}); this.sqlgGraph.tx().commit(); Vertex v = this.sqlgGraph.traversal().V().next(); assertTrue(Arrays.equals(new long[]{1, 2, 3, 4, 5}, (long[]) v.property("age").value())); Edge e = this.sqlgGraph.traversal().E().next(); assertTrue(Arrays.equals(new long[]{1, 2, 3, 4, 5}, (long[]) e.property("age").value())); }
Example #20
Source File: IoTest.java From tinkerpop with Apache License 2.0 | 5 votes |
private static void assertWeightLoosely(final float expected, final Edge e) { try { assertEquals(expected, e.value("weight"), 0.0001f); } catch (Exception ex) { // for graphs that have strong typing via schema it is possible that a value that came across as graphson // with lossiness will end up having a value expected to float to be coerced to double by the underlying // graph. logger.warn("Attempting to assert weight as double for {} - if your graph is strongly typed from schema this is likely expected", e); assertEquals(new Float(expected).doubleValue(), e.value("weight"), 0.0001d); } }
Example #21
Source File: AtlasJanusVertex.java From atlas with Apache License 2.0 | 5 votes |
@Override public Iterable<AtlasEdge<AtlasJanusVertex, AtlasJanusEdge>> getEdges(AtlasEdgeDirection dir, String[] edgeLabels) { Direction direction = AtlasJanusObjectFactory.createDirection(dir); Iterator<Edge> edges = getWrappedElement().edges(direction, edgeLabels); return graph.wrapEdges(edges); }
Example #22
Source File: GraphOMRSRelationshipMapper.java From egeria with Apache License 2.0 | 5 votes |
private Object getEdgeProperty(Edge edge, String propName) { Property ep = edge.property(propName); if (ep == null || !ep.isPresent()) return null; else return ep.value(); }
Example #23
Source File: TinkerGraph.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
/** * Return all the keys currently being index for said element class ({@link Vertex} or {@link Edge}). * * @param elementClass the element class to get the indexed keys for * @param <E> The type of the element class * @return the set of keys currently being indexed */ public <E extends Element> Set<String> getIndexedKeys(final Class<E> elementClass) { if (Vertex.class.isAssignableFrom(elementClass)) { return null == this.vertexIndex ? Collections.emptySet() : this.vertexIndex.getIndexedKeys(); } else if (Edge.class.isAssignableFrom(elementClass)) { return null == this.edgeIndex ? Collections.emptySet() : this.edgeIndex.getIndexedKeys(); } else { throw new IllegalArgumentException("Class is not indexable: " + elementClass); } }
Example #24
Source File: TestIoEdge.java From sqlg with MIT License | 5 votes |
@Test public void shouldReadWriteEdge() throws Exception { final Vertex v1 = this.sqlgGraph.addVertex(T.label, "person"); final Vertex v2 = this.sqlgGraph.addVertex(T.label, "person"); final Edge e = v1.addEdge("friend", v2, "weight", 0.5d, "acl", "rw"); assertEdge(v1, v2, e, true); }
Example #25
Source File: TestTopology.java From sqlg with MIT License | 5 votes |
@Test public void testRollback() { loadModern(); final Traversal<Vertex, Edge> traversal = this.sqlgGraph.traversal().V().aggregate("x").as("a").select("x").unfold().addE("existsWith").to("a").property("time", "now"); IteratorUtils.asList(traversal); this.sqlgGraph.tx().rollback(); }
Example #26
Source File: TinkerHelper.java From tinkerpop with Apache License 2.0 | 5 votes |
protected static void addOutEdge(final TinkerVertex vertex, final String label, final Edge edge) { if (null == vertex.outEdges) vertex.outEdges = new HashMap<>(); Set<Edge> edges = vertex.outEdges.get(label); if (null == edges) { edges = new HashSet<>(); vertex.outEdges.put(label, edges); } edges.add(edge); }
Example #27
Source File: ElementFactoryTest.java From act-platform with ISC License | 5 votes |
private Edge mockAndRunCreateEdges(ObjectFactBindingEntity inBinding, FactEntity.FactObjectBinding outBinding) { mockObject(inBinding); mockObject(outBinding.getObjectID()); mockFact(inBinding.getFactID(), outBinding); return elementFactory.createEdges(inBinding).iterator().next(); }
Example #28
Source File: VertexTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_EX11AsStringX() { final Object edgeId = convertToEdgeId("josh", "created", "lop"); final Traversal<Edge, Edge> traversal = get_g_EX11X(edgeId.toString()); assert_g_EX11X(edgeId, traversal); }
Example #29
Source File: HBaseBulkLoaderTest.java From hgraphdb with Apache License 2.0 | 5 votes |
@Test public void testBulkLoader() throws Exception { HBaseBulkLoader loader = new HBaseBulkLoader(graph); Vertex v1 = loader.addVertex(T.id, "A"); Vertex v2 = loader.addVertex(T.id, "B", "P1", "V1", "P2", "2"); loader.setProperty(v2, "P4", "4"); Edge e = loader.addEdge(v1, v2, "edge", "P3", "V3"); loader.setProperty(e, "P5", "5"); loader.close(); v1 = graph.vertex("A"); assertNotNull(v1); Iterator<Edge> it = v1.edges(Direction.OUT); assertTrue(it.hasNext()); e = it.next(); assertEquals("edge", e.label()); assertEquals("V3", e.property("P3").value()); assertEquals("5", e.property("P5").value()); v2 = e.inVertex(); assertEquals("B", v2.id()); assertEquals("V1", v2.property("P1").value()); assertEquals("2", v2.property("P2").value()); assertEquals("4", v2.property("P4").value()); }
Example #30
Source File: EdgeReader.java From hgraphdb with Apache License 2.0 | 5 votes |
@Override public void load(Edge edge, Result result) { if (result.isEmpty()) { throw new HBaseGraphNotFoundException(edge, "Edge does not exist: " + edge.id()); } Object inVertexId = null; Object outVertexId = null; String label = null; Long createdAt = null; Long updatedAt = null; Map<String, byte[]> rawProps = new HashMap<>(); for (Cell cell : result.listCells()) { String key = Bytes.toString(CellUtil.cloneQualifier(cell)); if (!Graph.Hidden.isHidden(key)) { rawProps.put(key, CellUtil.cloneValue(cell)); } else if (key.equals(Constants.TO)) { inVertexId = ValueUtils.deserialize(CellUtil.cloneValue(cell)); } else if (key.equals(Constants.FROM)) { outVertexId = ValueUtils.deserialize(CellUtil.cloneValue(cell)); } else if (key.equals(Constants.LABEL)) { label = ValueUtils.deserialize(CellUtil.cloneValue(cell)); } else if (key.equals(Constants.CREATED_AT)) { createdAt = ValueUtils.deserialize(CellUtil.cloneValue(cell)); } else if (key.equals(Constants.UPDATED_AT)) { updatedAt = ValueUtils.deserialize(CellUtil.cloneValue(cell)); } } final String labelStr = label; Map<String, Object> props = rawProps.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> ValueUtils.deserializePropertyValue(graph, ElementType.EDGE, labelStr, e.getKey(), e.getValue()))); if (inVertexId != null && outVertexId != null && label != null) { HBaseEdge newEdge = new HBaseEdge(graph, edge.id(), label, createdAt, updatedAt, props, graph.findOrCreateVertex(inVertexId), graph.findOrCreateVertex(outVertexId)); ((HBaseEdge) edge).copyFrom(newEdge); } else { throw new IllegalStateException("Unable to parse edge from cells"); } }