Cassandra 灯泡:g.vertices.index.lookup(dpi=dpid\u str)未按预期工作

Cassandra 灯泡:g.vertices.index.lookup(dpi=dpid\u str)未按预期工作,cassandra,titan,bulbs,Cassandra,Titan,Bulbs,我正在使用Titan GraphDB+Cassandra。我正在启动Titan,如下所示 cd titan-cassandra-0.3.1 bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties 我有一个雷克斯特外壳,可以用来和上面的泰坦+卡桑德拉通信 cd rexster-console-2.3.0 bin/rexster-console.sh 我想从我的python程序中编

我正在使用Titan GraphDB+Cassandra。我正在启动Titan,如下所示

cd titan-cassandra-0.3.1
bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties
我有一个雷克斯特外壳,可以用来和上面的泰坦+卡桑德拉通信

cd rexster-console-2.3.0
bin/rexster-console.sh
我想从我的python程序中编程Titan Graph DB。我正在为此使用Bulls包

我使用下面给出的灯泡从python创建了3种类型的顶点。 这3种类型的顶点是

- switch
- port
- device

from bulbs.titan import Graph
 vswitch = self.g.vertices.get_or_create('dpid',dpid_str,{'state':'active','dpid':dpid_str,'type':'switch'})
 vport   = self.g.vertices.get_or_create('port_id',port_id,{'desc':desc,'port_id':port_id,'state':state,'port_state':port_state,'number':number,'type':'port'})
如果我尝试打印变量vswitch、vport和vdevice,我会得到以下结果

vswitch     <Vertex: http://localhost:8182/graphs/graph/vertices/4>
vport       <Vertex: http://localhost:8182/graphs/graph/vertices/28>
并尝试打印出vswitch和vport变量,我得到以下值

<generator object <genexpr> at 0x26d6370>)
<generator object <genexpr> at 0x26d63c0>

在尝试使用g.vertices.index.lookup(dpid=dpid\u str)检索上述顶点时,我是否做错了什么?

灯泡
g.vertices.index.lookup()

使用
next()
获取生成器中的下一个值:

>>> # lookup() returns an generator (can return more than 1 value)

>>> switches = self.g.vertices.index.lookup(dpid=dpid_str)
>>> switch = switches.next()

>>> ports   = self.g.vertices.index.lookup(port_id=port_id_str)
>>> port = ports.next()
或者您可以使用
list()
生成器
转换为Python
list

>>> switches = self.g.vertices.index.lookup(dpid=dpid_str)
>>> list(switches)

>>> ports   = self.g.vertices.index.lookup(port_id=port_id_str)
>>> list(ports)
但是,如果索引项是唯一的,则可以使用
get_unique()
方法返回一个值或
None

# returns 1 vertex or None (errors if more than 1)
>>> vertex = g.vertices.index.get_unique( "dpid", dpid_str) 

Rexter索引文档:

index.lookup()

index.get_unique()

注意:迭代器和生成器是Python编程的基础知识——如果您是新手,它们在任何地方都可以使用,并且不特定于灯泡 关于Python编程,请参阅我的答案,以获取学习Python编程的优秀在线资源列表

# returns 1 vertex or None (errors if more than 1)
>>> vertex = g.vertices.index.get_unique( "dpid", dpid_str)