清理顶点(和边)?
g.V().drop()
不能与traversal().withRemote()
OrientGraph.traversal()
一起工作时。drop()
顶点与GraphTraversalSource g
?
GraphTraversalSource g = traversal().withRemote("conf/remote-graph.properties");
OrientGraph orientGraph = OrientGraph.open(configuration);
GraphTraversalSource g = orientGraph.traversal();
docker run -d -p 8182:8182 janusgraph/janusgraph
drop()
g.V().count().next()
等于 2.g.V().count().next()
增加 2.我已经尝试过将
.next()
附加到几乎所有内容上。 g.V().drop().next()
原因
Exception in thread "main" java.util.NoSuchElementException
2023-05-04 08:08:03,834 [INFO] [c.j.m.Manifests.gremlin-driver-loop-1] :: 0 attributes loaded from 97 stream(s) in 20ms, 57 saved, 1788 ignored: []
2023-05-04 08:08:03,909 [INFO] [o.a.t.g.d.Connection.gremlin-driver-conn-scheduler-1] :: Created new connection for ws://localhost:8182/gremlin
2023-05-04 08:08:03,909 [INFO] [o.a.t.g.d.Connection.gremlin-driver-conn-scheduler-2] :: Created new connection for ws://localhost:8182/gremlin
2023-05-04 08:08:03,910 [INFO] [o.a.t.g.d.ConnectionPool.gremlin-driver-host-scheduler-1] :: Opening connection pool on Host{address=localhost/127.0.0.1:8182, hostUri=ws://localhost:8182/gremlin} with core size of 2
Exception in thread "main" java.util.NoSuchElementException
at org.apache.tinkerpop.gremlin.driver.ResultSet$1.next(ResultSet.java:187)
at org.apache.tinkerpop.gremlin.driver.ResultSet$1.next(ResultSet.java:169)
at org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteTraversal$TraverserIterator.next(DriverRemoteTraversal.java:115)
at org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteTraversal$TraverserIterator.next(DriverRemoteTraversal.java:100)
at org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteTraversal.nextTraverser(DriverRemoteTraversal.java:92)
at org.apache.tinkerpop.gremlin.process.remote.traversal.step.map.RemoteStep.processNextStart(RemoteStep.java:80)
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:135)
at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:40)
at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.next(DefaultTraversal.java:249)
at Main.main(Main.java:15)
│ pom.xml
│
├───src
│ ├───main
│ │ ├───java
│ │ │ Main.java
│ │ │
│ │ └───resources
│ │ │ log4j2.xml
│ │ │
│ │ ├───conf
│ │ │ remote-graph.properties
│ │ │ remote-objects.yaml
Main.java
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Transaction;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
public class Main {
private static final Logger logger = LogManager.getLogger(Main.class);
public static void main(String[] args) throws Exception {
GraphTraversalSource g = traversal().withRemote("conf/remote-graph.properties");
Transaction tx = g.tx();
tx.open();
g.V().drop();
// tx.commit();
// tx = g.tx();
Vertex v1 = g.addV("person").property("name","marko").next();
Vertex v2 = g.addV("person").property("name","stephen").next();
g.V(v1).addE("knows").to(v2).property("weight",0.75).iterate();
tx.commit();
logger.info("g.V().count().next():\t" + g.V().count().next());
g.close();
}
}
remote-graph.properties
gremlin.remote.remoteConnectionClass=org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection
gremlin.remote.driver.clusterFile=src/main/resources/conf/remote-objects.yaml
gremlin.remote.driver.sourceName=g
remote-objects.yaml
hosts: [localhost]
port: 8182
serializer: {
className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1,
config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }
}
pom.xml
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.20.0</version>
</dependency>
<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>gremlin-core</artifactId>
<version>3.6.2</version>
</dependency>
<dependency>
<groupId>org.janusgraph</groupId>
<artifactId>janusgraph-core</artifactId>
<version>0.6.4-20230429-020227.dc3f877</version>
</dependency>
</dependencies>
gremlin 控制台自动尝试
next
遍历,直到达到配置的次数。 java程序中的遍历要生效,必须自己加上iterate()
,所以g.V().drop().iterate()
.