首页 文章

无法在DSE图中打印节点属性

提问于
浏览
-1

道歉,因为这可能是关于该主题的非常基本的问题,但我是Gremlin / DSE Graph的新手,我尝试了很多方法来提取我插入到我的图表中的数据,但不知怎的,我无法使其工作 .

以下是我所拥有的:1 . 将allow_scans设置为true的图形2.在所有顶点的NodeID上定义了propertyKey和vertexes以及物化索引的模式 .

现在没有关系,只有顶点有数据点 .

我编写了一个程序,将我的所有节点插入到DSE Graph中,该程序正在成功运行,因为我在程序创建每个Vertex之后得到如下的响应:

Result({u'id': {u'out_vertex': {u'community_id': 853347840, u'~label': u'vertex', u'member_id': 14}, u'~type': u'Name', u'local_id': u'00000000-0000-8012-0000-000000000000'}, u'value': u'amount', u'label': u'Name'})]

好的所以现在插入节点,我想提取它们并打印它们的名字:所以我做了:

g.V().hasLabel('FIELD').has('NodeID','2559b635f077e86c7370ab1c4c798a06').values('Name');

上述成功失败,结果为空白 . 我的意思是它成功运行null输出,就像没有错误,但没有输出 . (在gremlin-console中为null,在DataStax Studio中为“成功 - 无结果”)

然后我遇到了文档,图表不知道'has'是否只返回一个节点或更多,所以我按照文档和教程使用next for iterating:

g.V().hasLabel('FIELD').has('NodeID','2559b635f077e86c7370ab1c4c798a06').next().values('Name');

即使这样也失败了

org.apache.tinkerpop.gremlin.driver.exception.ResponseException

(Datastax工作室不显示更多信息) - 如何进一步调试?

我甚至遇到过使用map的lambda方法:

g.V().hasLabel('FIELD').has('NodeID','2559b635f077e86c7370ab1c4c798a06').map{it.get().value('Name')};

回答'它'没有被定义 .

(我甚至尝试过valueMap - 不确定是否需要它)

找到并打印节点的属性值我做错了什么?

任何方向或查询可以帮助我提取名称和其他属性?即使是多步查询?但我不认为这应该是那么复杂 .

UPDATE

根据答案我得到以下回溯:

gremlin> :> g.V().hasLabel('FIELD').has('NodeID','2559b635f077e86c7370ab1c4c798a06').valueMap(true).next();
org.apache.tinkerpop.gremlin.groovy.plugin.RemoteException
Type ':help' or ':h' for help.
Display stack trace? [yN]y
org.apache.tinkerpop.gremlin.groovy.plugin.RemoteException
        at org.apache.tinkerpop.gremlin.console.groovy.plugin.DriverRemoteAcceptor.submit(DriverRemoteAcceptor.java:170)
        at org.apache.tinkerpop.gremlin.console.commands.SubmitCommand.execute(SubmitCommand.groovy:41)
        at org.codehaus.groovy.tools.shell.Shell.execute(Shell.groovy:104)
        at org.codehaus.groovy.tools.shell.Groovysh.super$2$execute(Groovysh.groovy)
        at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132)
        at org.codehaus.groovy.tools.shell.Groovysh.executeCommand(Groovysh.groovy:259)
        at org.apache.tinkerpop.gremlin.console.GremlinGroovysh.execute(GremlinGroovysh.groovy:84)
        at org.codehaus.groovy.tools.shell.Shell.leftShift(Shell.groovy:122)
        at org.codehaus.groovy.tools.shell.ShellRunner.work(ShellRunner.groovy:95)
        at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$work(InteractiveShellRunner.groovy)
        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:498)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:152)
        at org.codehaus.groovy.tools.shell.InteractiveShellRunner.work(InteractiveShellRunner.groovy:124)
        at org.codehaus.groovy.tools.shell.ShellRunner.run(ShellRunner.groovy:59)
        at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$run(InteractiveShellRunner.groovy)
        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:498)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:152)
        at org.codehaus.groovy.tools.shell.InteractiveShellRunner.run(InteractiveShellRunner.groovy:83)
        at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232)
        at org.apache.tinkerpop.gremlin.console.Console.<init>(Console.groovy:152)
        at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232)
        at org.apache.tinkerpop.gremlin.console.Console.main(Console.groovy:401)

我能够在另一个图中做一些类似的操作 . 图表有问题吗?

UPDATE 2

我的图形顶点被错误地定义 .

深入研究此解决方案的关键是结果中的 ~label . 它指向 vertex 而不是它应该 Field

在定义数据插入团队时,他们必须在没有引号的情况下添加标签时将标签放在引号中 . 因此我无法遍历节点 .

1 回答

  • 2

    您需要确保迭代遍历 . 最常见的是你会使用:

    • iterate() 得到零结果

    • next() 得到一个结果

    • toList() 得到很多结果

    我猜 NodeID 是独一无二的,所以尝试这样的事情:

    g.V().hasLabel('FIELD').has('NodeID','2559b635f077e86c7370ab1c4c798a06').
    values('Name').next();
    

    如果您对该顶点上的所有属性感兴趣,请尝试:

    g.V().hasLabel('FIELD').has('NodeID','2559b635f077e86c7370ab1c4c798a06').
    valueMap(true).next();
    

相关问题