无法在DSE图表中打印节点属性 [英] Unable to print node properties in DSE graph

查看:225
本文介绍了无法在DSE图表中打印节点属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

现在没有关系,只有带数据点的顶点。



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

 结果({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'标签':u'Name'})] 

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

  gV()。hasLabel('FIELD')。具有( '节点ID', '2559b635f077e86c7370ab1c4c798a06')的值( '姓名'); 

以上空白结果失败成功。我的意思是它运行成功,空输出像没有错误,但没有输出。 (在gremlin-console中为null,在DataStax Studio中为'Success - No Results')

然后我发现文档中图表不知道'has'是否只会返回一个节点或更多,所以我用next来按照文档和教程进行迭代:

  gV()。hasLabel('FIELD' )。先后( '节点ID', '2559b635f077e86c7370ab1c4c798a06')next()的值( '姓名')。; 

即使这样也会失败


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

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



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

  GV()hasLabel( '场')具有( '节点ID', '2559b635f077e86c7370ab1c4c798a06')地图{it.get()值( '姓名')}。。。; 

其中'it'没有被定义。

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



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

任何可以帮助我提取姓名和其他属性的指示或查询?即使是多步查询?但我认为这不应该是那么复杂。



更新

按照答案,我得到以下回溯:

  gremlin>产品:> 。g.V()hasLabel(场)具有(节点ID, 2559b635f077e86c7370ab1c4c798a06’ )valueMap(真)的.next(); 
org.apache.tinkerpop.gremlin.groovy.plugin.RemoteException
输入':help'或':h'寻求帮助。
显示堆栈跟踪? [yN] y
org.apache.tinkerpop.gremlin.console.groovy.plugin.DriverRemoteAcceptor.submit(DriverRemoteAcceptor.java:170)中的org.apache.tinkerpop.gremlin.groovy.plugin.RemoteException

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)
在java.lang.reflect.Method.invoke(Method.java:498)
在org.codehaus.groovy.reflection.CachedMethod.invoke (CachedMethod.java:93)
在groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
在groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215)
。在org.codehaus.groovy.r untime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132)
在org.codehaus.groovy.tools.shell.Groovysh.executeCommand(Groovysh.groovy:259)
。在org.apache.tinkerpop.gremlin。 console.GremlinGroovysh.execute(GremlinGroovysh.groovy:84)
在org.codehaus.groovy.tools.shell.Shell.leftShift(Shell.groovy:122)
在org.codehaus.groovy.tools。 shell.ShellRunner.work(ShellRunner.groovy:95)
。在org.codehaus.groovy.tools.shell.InteractiveShellRunner.super $ 2 $工作(InteractiveShellRunner.groovy)$ b $在sun.reflect.NativeMethodAccessorImpl.invoke0 b (本机方法)
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
在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)在org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:152)

在org.codehaus.groovy.tools.shell.InteractiveShellRunner.work(InteractiveShellRunner .groovy:124)
在org.codehaus.groovy.tools.shell.ShellRunner.run(ShellRunner.groovy:59)
在org.codehaus.groovy.tools.shell.InteractiveShellRunner.super $ 2 $在sun.reflect.NativeMethodAccessorImpl.invoke运行(InteractiveShellRunner.groovy)在sun.reflect.NativeMethodAccessorImpl.invoke0
(本机方法)
(NativeMethodAccessorImpl.java:62)
。在sun.reflect。 DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
在java.lang.reflect .Method.invoke(Method.java:498)
在org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
在groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java :325)在groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215
)在org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132

。在org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:152)
在org.codehaus.groovy.tools.shell.InteractiveShellRunner.run(InteractiveShellRunner.groovy:83)
。在组织。 codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232)
at org.apache.tinkerpop.gremlin.console.Console。< init>(Console.groovy:152)
org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232)
at org.apache.tinkerpop.gremlin.console.Console.main(Console.groovy:401)

我可以在另一个图表中做类似的操作。图表有什么问题?



更新2



错误地定义。

深入研究该解决方案的关键在于结果中的〜label 。它指向顶点而不是它应该是字段



在定义数据插入团队时,如果他们不得不提供不包含引号的标签,则会将标签置于引号中。因此我无法遍历节点。

解决方案

您需要确保迭代遍历。大多数情况下,您可以使用以下任一方法:




  • iterate() li>
  • next()获得一个结果
  • toList() code>得到很多结果



我猜测 NodeID 是唯一的,所以试试这样:

  gV()。hasLabel('FIELD')。has('NodeID', '2559b635f077e86c7370ab1c4c798a06')。 
values('Name')。next();

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

  gV()。hasLabel('FIELD')。has('NodeID','2559b635f077e86c7370ab1c4c798a06')。 
valueMap(true).next();


Apologies as this might be very basic question on the topic but I am new to Gremlin/DSE Graph and i tried many ways to extract data i am inserting to my graph but somehow i am unable to make it work.

Here is what i have: 1. Graph with allow_scans set to true 2. Schema with propertyKey and vertexes defined and materialized index on NodeID of all Vertexes.

There are no relationships right now, just vertexes with data points.

I wrote a program to insert all my nodes to DSE Graph which is working successfully as i get response like below after program created every 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'})]

Ok So now the nodes are inserted, i want to extract them and print their names: So i did:

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

Above failed successfully with blank result. I mean it runs successfully with null output like there is no error but then there is no output. (null in gremlin-console and 'Success - No Results' in DataStax Studio)

Then i came across documentation that graph will not know if the 'has' will only return one node or more, so i used next for iterating as per documentation and tutorials:

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

Even this failed with

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

(Datastax studio doesnt show more information) - How can i debug this further?

I even came across lambda approach in which i use map :

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

which responded with 'it' not being defined.

(i even tried valueMap - not sure if it was even required)

What am i doing wrong to find and print properties values of a node?

Any directions or query which can help me extract the names and other properties? Even a multi-step query? however i don't think this should be that complicated.

UPDATE:

As per answer i get the following traceback:

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)

I am able to do some similar operations in another graph. Is something wrong with the graph?

UPDATE 2

My Graph vertices were wrongly defined.

The key to drill down to this solution is in the ~label in the result. It points to vertex instead it should be Field

While defining the data insert team had put label in quotes when they had to put mention label without quotes. Hence i was not able to traverse the nodes.

解决方案

You need to make sure to iterate the traversal. Most commonly you would use either:

  • iterate() get zero result
  • next() get one result
  • toList() get many results

I'd guess that NodeID is unique, so try something like this:

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

If you're interested in all of the properties on that vertex, try:

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

这篇关于无法在DSE图表中打印节点属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆