Java Code Examples for org.apache.tinkerpop.gremlin.structure.Edge#remove()
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.Edge#remove() .
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: 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 2
Source File: TinkerGraphTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldRemoveEdgeFromAnIndex() { final TinkerGraph g = TinkerGraph.open(); g.createIndex("oid", Edge.class); final Vertex v = g.addVertex(); v.addEdge("friend", v, "oid", "1", "weight", 0.5f); final Edge e = v.addEdge("friend", v, "oid", "1", "weight", 0.5f); v.addEdge("friend", v, "oid", "2", "weight", 0.6f); // a tricky way to evaluate if indices are actually being used is to pass a fake BiPredicate to has() // to get into the Pipeline and evaluate what's going through it. in this case, we know that at index // is used because only oid 1 should pass through the pipeline due to the inclusion of the // key index lookup on "oid". If there's an weight of something other than 0.5f in the pipeline being // evaluated then something is wrong. assertEquals(new Long(2), g.traversal().E().has("weight", P.test((t, u) -> { assertEquals(0.5f, t); return true; }, 0.5)).has("oid", "1").count().next()); e.remove(); assertEquals(new Long(1), g.traversal().E().has("weight", P.test((t, u) -> { assertEquals(0.5f, t); return true; }, 0.5)).has("oid", "1").count().next()); }
Example 3
Source File: TinkerGraphTransformationInjectConnectedSegments.java From trainbenchmark with Eclipse Public License 1.0 | 6 votes |
@Override public void activate(final Collection<TinkerGraphConnectedSegmentsInjectMatch> matches) throws Exception { for (final TinkerGraphConnectedSegmentsInjectMatch match : matches) { // create (segment2) node final Vertex segment2 = driver.getGraph().addVertex(ModelConstants.SEGMENT); segment2.property(ModelConstants.ID, driver.generateNewVertexId()); segment2.property(ModelConstants.LENGTH, TrainBenchmarkConstants.DEFAULT_SEGMENT_LENGTH); // (segment2)-[:monitoredBy]->(sensor) segment2.addEdge(ModelConstants.MONITORED_BY, match.getSensor()); // (segment1)-[:connectsTo]->(segment2) match.getSegment1().addEdge(ModelConstants.CONNECTS_TO, segment2); // (segment2)-[:connectsTo]->(segment3) segment2.addEdge(ModelConstants.CONNECTS_TO, match.getSegment3()); // remove (segment1)-[:connectsTo]->(segment3) final Iterable<Edge> connectsToEdges = () -> match.getSegment1().edges(Direction.OUT, ModelConstants.CONNECTS_TO); for (final Edge connectsToEdge : connectsToEdges) { if (connectsToEdge.inVertex().equals(match.getSegment3())) { connectsToEdge.remove(); } } } }
Example 4
Source File: TinkerGraphTest.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
@Test public void shouldRemoveEdgeFromAnIndex() { final TinkerGraph g = TinkerGraph.open(); g.createIndex("oid", Edge.class); final Vertex v = g.addVertex(); v.addEdge("friend", v, "oid", "1", "weight", 0.5f); final Edge e = v.addEdge("friend", v, "oid", "1", "weight", 0.5f); v.addEdge("friend", v, "oid", "2", "weight", 0.6f); // a tricky way to evaluate if indices are actually being used is to pass a fake BiPredicate to has() // to get into the Pipeline and evaluate what's going through it. in this case, we know that at index // is used because only oid 1 should pass through the pipeline due to the inclusion of the // key index lookup on "oid". If there's an weight of something other than 0.5f in the pipeline being // evaluated then something is wrong. assertEquals(new Long(2), g.traversal().E().has("weight", P.test((t, u) -> { assertEquals(0.5f, t); return true; }, 0.5)).has("oid", "1").count().next()); e.remove(); assertEquals(new Long(1), g.traversal().E().has("weight", P.test((t, u) -> { assertEquals(0.5f, t); return true; }, 0.5)).has("oid", "1").count().next()); }
Example 5
Source File: GraphOMRSMetadataStore.java From egeria with Apache License 2.0 | 6 votes |
synchronized void removeRelationshipFromStore(String relationshipGUID) { final String methodName = "removeRelationshipFromStore"; // TODO - could capture existing relationship and move it to 'history' // Look in the graph GraphTraversalSource g = instanceGraph.traversal(); Iterator<Edge> edgeIt = g.E().hasLabel("Relationship").has(PROPERTY_KEY_RELATIONSHIP_GUID, relationshipGUID); if (edgeIt.hasNext()) { Edge edge = edgeIt.next(); log.debug("{} found existing edge {}", methodName, edge); edge.remove(); log.debug("{} removed relationship edge with guid {}", methodName, relationshipGUID); } g.tx().commit(); }
Example 6
Source File: VertexDuplicator.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
static void moveIncomingEdges(Vertex vertex, Vertex duplicate, IndexHandler indexHandler) { for (Iterator<Edge> edges = vertex.edges(Direction.IN); edges.hasNext(); ) { Edge edge = edges.next(); if (edge.label().equals(VERSION_OF)) { continue; } Edge duplicateEdge = edge.outVertex().addEdge(edge.label(), duplicate); for (Iterator<Property<Object>> properties = edge.properties(); properties.hasNext(); ) { Property<Object> property = properties.next(); duplicateEdge.property(property.key(), property.value()); } if (duplicateEdge.<Boolean>property("isLatest").orElse(false)) { duplicateEdge.<String>property("tim_id") .ifPresent(p -> indexHandler.upsertIntoEdgeIdIndex(UUID.fromString(p), duplicateEdge)); } edge.remove(); } }
Example 7
Source File: TestGlobalUniqueIndex.java From sqlg with MIT License | 5 votes |
@Test public void testEdgeUniqueConstraintDelete() { Map<String, PropertyType> properties = new HashMap<>(); properties.put("namea", PropertyType.STRING); VertexLabel aVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("A", properties); VertexLabel bVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("B", properties); EdgeLabel edgeLabel = aVertexLabel.ensureEdgeLabelExist("ab", bVertexLabel, properties); Set<PropertyColumn> propertyColumns = new HashSet<>(edgeLabel.getProperties().values()); this.sqlgGraph.getTopology().ensureGlobalUniqueIndexExist(propertyColumns); Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "namea", "a1"); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "namea", "a2"); Edge edge = a1.addEdge("ab", a2, "namea", "123"); this.sqlgGraph.tx().commit(); Assert.assertEquals(1, this.sqlgGraph.globalUniqueIndexes().V().count().next().intValue()); try { a1.addEdge("ab", a2, "namea", "123"); fail("GlobalUniqueIndex should prevent this form happening"); } catch (Exception e) { //swallow this.sqlgGraph.tx().rollback(); } edge.remove(); this.sqlgGraph.tx().commit(); Assert.assertEquals(0, this.sqlgGraph.globalUniqueIndexes().V().count().next().intValue()); a1.addEdge("ab", a2, "namea", "123"); //this time it passes. this.sqlgGraph.tx().commit(); Assert.assertEquals(1, this.sqlgGraph.globalUniqueIndexes().V().count().next().intValue()); }
Example 8
Source File: SpecializedElementsWithOndiskTest.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Test public void shouldSupportEdgeRemoval() { TinkerGraph graph = newGratefulDeadGraphWithSpecializedElements(); Vertex song1 = graph.addVertex(Song.label); Vertex song2 = graph.addVertex(Song.label); Edge followedBy = song1.addEdge(FollowedBy.label, song2); assertEquals(2, graph.traversal().V().toList().size()); assertEquals(1, graph.traversal().E().toList().size()); followedBy.remove(); assertEquals(2, graph.traversal().V().toList().size()); assertEquals(0, graph.traversal().E().toList().size()); graph.close(); }
Example 9
Source File: TestBatch.java From sqlg with MIT License | 5 votes |
@Test public void testBatchRemoveEdges_UserSuppliedPK() throws InterruptedException { VertexLabel personVertexLabel = this.sqlgGraph.getTopology().getPublicSchema() .ensureVertexLabelExist( "Person", new HashMap<String, PropertyType>() {{ put("uid1", PropertyType.varChar(100)); put("uid2", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Arrays.asList("uid1", "uid2")) ); personVertexLabel.ensureEdgeLabelExist( "test", personVertexLabel, new HashMap<String, PropertyType>() {{ put("uid1", PropertyType.varChar(100)); put("uid2", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Arrays.asList("uid1", "uid2")) ); Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString()); Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString()); Vertex v3 = this.sqlgGraph.addVertex(T.label, "Person", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString()); Edge edge1 = v1.addEdge("test", v2, "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString()); Edge edge2 = v1.addEdge("test", v3, "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString()); this.sqlgGraph.tx().commit(); this.sqlgGraph.tx().normalBatchModeOn(); edge1.remove(); edge2.remove(); this.sqlgGraph.tx().commit(); testBatchRemoveEdges_assert(this.sqlgGraph); if (this.sqlgGraph1 != null) { Thread.sleep(1000); testBatchRemoveEdges_assert(this.sqlgGraph1); } }
Example 10
Source File: BaseCoreTest.java From hugegraph with Apache License 2.0 | 5 votes |
protected void clearData() { HugeGraph graph = graph(); // Clear uncommitted data(maybe none) graph.tx().rollback(); int count = 0; // Clear edge do { count = 0; for (Edge e : graph().traversal().E().limit(TX_BATCH).toList()) { count++; e.remove(); } graph.tx().commit(); } while (count == TX_BATCH); // Clear vertex do { count = 0; for (Vertex v : graph().traversal().V().limit(TX_BATCH).toList()) { count++; v.remove(); } graph.tx().commit(); } while (count == TX_BATCH); }
Example 11
Source File: TestRemoveElement.java From sqlg with MIT License | 5 votes |
@Test public void testRemoveEdge() { Vertex marko = this.sqlgGraph.addVertex(T.label, "Person", "name", "marko"); Vertex john = this.sqlgGraph.addVertex(T.label, "Person", "name", "john"); Vertex peter = this.sqlgGraph.addVertex(T.label, "Person", "name", "peter"); Edge edge1 = marko.addEdge("friend", john); Edge edge2 = marko.addEdge("friend", peter); this.sqlgGraph.tx().commit(); Assert.assertEquals(3L, this.sqlgGraph.traversal().V().count().next(), 0); Assert.assertEquals(2L, vertexTraversal(this.sqlgGraph, marko).out("friend").count().next(), 0); edge1.remove(); this.sqlgGraph.tx().commit(); Assert.assertEquals(3L, this.sqlgGraph.traversal().V().count().next(), 0); Assert.assertEquals(1L, vertexTraversal(this.sqlgGraph, marko).out("friend").count().next(), 0); }
Example 12
Source File: TitanEventualGraphTest.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
/** * Tests that timestamped edges can be updated */ @Test public void testTimestampedEdgeUpdates() { clopen(option(GraphDatabaseConfiguration.STORE_META_TIMESTAMPS, "edgestore"), true, option(GraphDatabaseConfiguration.STORE_META_TTL, "edgestore"), true); // Transaction 1: Init graph with two vertices and one edge TitanTransaction tx = graph.buildTransaction().commitTime(Instant.ofEpochSecond(100)).start(); TitanVertex v1 = tx.addVertex(); TitanVertex v2 = tx.addVertex(); Edge e = v1.addEdge("related",v2); e.property("time", 25); tx.commit(); tx = graph.buildTransaction().commitTime(Instant.ofEpochSecond(200)).start(); v1 = tx.getVertex(v1.longId()); assertNotNull(v1); e = Iterators.getOnlyElement(v1.edges(Direction.OUT, "related")); assertNotNull(e); assertEquals(Integer.valueOf(25), e.value("time")); e.property("time", 125); tx.commit(); tx = graph.buildTransaction().commitTime(Instant.ofEpochSecond(300)).start(); v1 = tx.getVertex(v1.longId()); assertNotNull(v1); e = Iterators.getOnlyElement(v1.edges(Direction.OUT, "related")); assertEquals(Integer.valueOf(125), e.value("time")); e.remove(); tx.commit(); }
Example 13
Source File: TitanEventualGraphTest.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
private void processTx(TitanTransaction tx, int txid, long vid, long uid) { TitanVertex v = getV(tx,vid); TitanVertex u = getV(tx,uid); assertEquals(5.0,v.<Double>value("weight").doubleValue(),0.00001); VertexProperty p = getOnlyElement(v.properties("weight")); assertEquals(1,p.<Integer>value("sig").intValue()); sign(v.property("weight",6.0),txid); p = getOnlyElement(v.properties("name")); assertEquals(1,p.<Integer>value("sig").intValue()); assertEquals("John",p.value()); p.remove(); sign(v.property("name","Bob"),txid); for (String pkey : new String[]{"value","valuef"}) { p = getOnlyElement(v.properties(pkey)); assertEquals(1,p.<Integer>value("sig").intValue()); assertEquals(2,p.value()); sign((TitanVertexProperty)p,txid); } Edge e = getOnlyElement(v.query().direction(OUT).labels("es").edges()); assertEquals(1,e.<Integer>value("sig").intValue()); e.remove(); sign(v.addEdge("es",u),txid); e = getOnlyElement(v.query().direction(OUT).labels("o2o").edges()); assertEquals(1,e.<Integer>value("sig").intValue()); sign((TitanEdge)e,txid); e = getOnlyElement(v.query().direction(OUT).labels("o2m").edges()); assertEquals(1,e.<Integer>value("sig").intValue()); e.remove(); sign(v.addEdge("o2m",u),txid); for (String label : new String[]{"em","emf"}) { e = getOnlyElement(v.query().direction(OUT).labels(label).edges()); assertEquals(1,e.<Integer>value("sig").intValue()); sign((TitanEdge)e,txid); } }
Example 14
Source File: TinkerGraphTransformationInjectSwitchMonitored.java From trainbenchmark with Eclipse Public License 1.0 | 5 votes |
@Override public void activate(final Collection<TinkerGraphSwitchMonitoredInjectMatch> matches) { for (final TinkerGraphSwitchMonitoredInjectMatch match : matches) { final Iterable<Edge> monitoredBys = () -> match.getSw().edges(Direction.OUT, ModelConstants.MONITORED_BY); for (final Edge monitoredBy : monitoredBys) { monitoredBy.remove(); } } }
Example 15
Source File: TinkerGraphTransformationInjectRouteSensor.java From trainbenchmark with Eclipse Public License 1.0 | 5 votes |
@Override public void activate(final Collection<TinkerGraphRouteSensorInjectMatch> matches) { for (final TinkerGraphRouteSensorInjectMatch match : matches) { final Iterable<Edge> requiress = () -> match.getRoute().edges(Direction.OUT, ModelConstants.REQUIRES); for (final Edge requires : requiress) { if (requires.inVertex().equals(match.getSensor())) { requires.remove(); } } } }
Example 16
Source File: TinkerGraphTransformationInjectSemaphoreNeighbor.java From trainbenchmark with Eclipse Public License 1.0 | 5 votes |
@Override public void activate(final Collection<TinkerGraphSemaphoreNeighborInjectMatch> matches) { for (final TinkerGraphSemaphoreNeighborInjectMatch match : matches) { final Iterable<Edge> entries = () -> match.getRoute().edges(Direction.OUT, ModelConstants.ENTRY); for (final Edge entry : entries) { if (entry.inVertex().equals(match.getSemaphore())) { entry.remove(); } } } }
Example 17
Source File: BitsyGraphIT.java From bitsy with Apache License 2.0 | 4 votes |
private void removeEdge(Graph graph, Edge edge) { edge.remove(); }
Example 18
Source File: TransactionImpl.java From grakn with GNU Affero General Public License v3.0 | 4 votes |
private void mergeAttributeEdge(Vertex mergeTargetV, Vertex ent, GraphTraversal<Vertex, Edge> attributeEdge) { Edge edge = attributeEdge.next(); Object[] properties = propertiesToArray(Lists.newArrayList(edge.properties())); ent.addEdge(Schema.EdgeLabel.ATTRIBUTE.getLabel(), mergeTargetV, properties); edge.remove(); }
Example 19
Source File: GraphOMRSMetadataStore.java From egeria with Apache License 2.0 | 4 votes |
synchronized void removeEntityProxyFromStore(String entityGUID) { final String methodName = "removeEntityProxyFromStore"; // TODO - could capture existing entity and move it to 'history' // Look in the graph GraphTraversalSource g = instanceGraph.traversal(); GraphTraversal<Vertex, Vertex> gt = g.V().hasLabel("Entity").has(PROPERTY_KEY_ENTITY_GUID, entityGUID); // Only looking for proxy entities: gt = gt.has(PROPERTY_KEY_ENTITY_IS_PROXY, true); if (gt.hasNext()) { Vertex vertex = gt.next(); Boolean isProxy = entityMapper.isProxy(vertex); if (isProxy) { log.debug("{} found entity proxy vertex {} to be removed", methodName, vertex); // Look for associated classifications. Iterator<Edge> classifierEdges = vertex.edges(Direction.OUT, "Classifier"); while (classifierEdges.hasNext()) { Edge classifierEdge = classifierEdges.next(); Vertex classificationVertex = classifierEdge.inVertex(); // Get the classification's name for debug/info only Classification existingClassification = new Classification(); try { classificationMapper.mapVertexToClassification(classificationVertex, existingClassification); } catch (Exception e) { log.error("{} caught exception from classification mapper for classification {}", methodName, existingClassification.getName()); // Nothing you can do - just keep going } log.debug("{} removing classification {} from entity proxy", methodName, existingClassification.getName()); classifierEdge.remove(); classificationVertex.remove(); } // Finally remove the entity vertex... vertex.remove(); log.debug("{} removed entity proxy vertex with guid {}", methodName, entityGUID); } } g.tx().commit(); }
Example 20
Source File: Titan1Graph.java From incubator-atlas with Apache License 2.0 | 3 votes |
@Override public void removeEdge(AtlasEdge<Titan1Vertex, Titan1Edge> edge) { Edge wrapped = edge.getE().getWrappedElement(); wrapped.remove(); }