简体   繁体   English

DSE Graph with Java Driver,如何添加边缘

[英]DSE Graph with Java Driver, how to add edges

I want to build a graph completely with the Datastax Java Driver. 我想用Datastax Java Driver完全构建一个图形。 I managed to insert vertices, but I have no clue how to add edges to existing vertices. 我设法插入顶点,但我不知道如何将边添加到现有顶点。

When I run the following code 当我运行以下代码时

session.executeGraph("parent = g.V().has('businessId','sys-1').next()");
session.executeGraph("child = g.V().has('businessId','sys-2').next()");
session.executeGraph("parent.addEdge('consistsOf', child)");

I get an exception 我得到一个例外

Exception in thread "main" com.datastax.driver.core.exceptions.InvalidQueryException: No such property: parent for class: Script285
    at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:50)
    at com.datastax.driver.dse.DriverThrowables.propagateCause(DriverThrowables.java:29)
    at com.datastax.driver.dse.DefaultDseSession.executeGraph(DefaultDseSession.java:77)
    at com.datastax.driver.dse.DefaultDseSession.executeGraph(DefaultDseSession.java:64)
    at de.pratho.valpro.tools.Main.main(Main.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: No such property: parent for class: Script285
    at com.datastax.driver.core.Responses$Error.asException(Responses.java:136)
    at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:179)
    at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:173)
    at com.datastax.driver.core.RequestHandler.access$2500(RequestHandler.java:43)
    at com.datastax.driver.core.RequestHandler$SpeculativeExecution.setFinalResult(RequestHandler.java:788)
    at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:607)
    at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1012)
    at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:935)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:276)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:263)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
    at java.lang.Thread.run(Thread.java:745)

When I run the gremlin statements in the gremlin_console_window it is working fine. 当我在gremlin_console_window中运行gremlin语句时,它运行正常。 So I think variables like parent and child are not working within a Java DseSession ? 所以我认为parentchild等变量在Java DseSession

Unfortunately, I was not able to find much information about how to work with the Java Driver properly. 不幸的是,我无法找到有关如何正确使用Java驱动程序的大量信息。

It looks like you have to create it within the context of the same script, ie: 看起来你必须在同一个脚本的上下文中创建它,即:

DseCluster dseCluster = DseCluster.builder()
            .addContactPoint("127.0.0.1")
            .withGraphOptions(new GraphOptions().setGraphName("demo"))
            .build();
DseSession dseSession = dseCluster.newSession();
SimpleGraphStatement s = new SimpleGraphStatement(
            "def v1 = g.V(id1).next()\n" + 
            "def v2 = g.V(id2).next()\n" +
            "v1.addEdge('relates', v2)");
dseSession.executeGraph(s);

I think the reason for this is that these commands are just interpreted as independent gremlin queries. 我认为这样做的原因是这些命令只被解释为独立的gremlin查询。

I believe this set of documentation may be helpful to you. 我相信这套文档可能对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM