【问题标题】:Getting <key,value> pairs from Titan Graph Node从 Titan Graph 节点获取 <key,value> 对
【发布时间】:2014-09-06 14:05:48
【问题描述】:

我正在使用 TitanGraphDB + Cassandra。我正在按如下方式启动 Titan

cd titan-cassandra-0.3.1
bin/titan.sh config/titan-server-rexster.xml config/titan-server-cassandra.properties

我有一个 Rexster shell,可以用来与上面的 Titan+Cassandra 通信。

cd rexster-console-2.3.0
bin/rexster-console.sh

我想从我的 python 程序中对 Titan Graph DB 进行编程。我为此使用了灯泡包。

我使用下面给出的灯泡从 python 创建了 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 = self.g.vertices.index.lookup(dpid=dpid_str)
vport   = self.g.vertices.index.lookup(port_id=port_id_str)

for s in vswitch
     print s

Here 's' prints the the node `<Vertex: http://localhost:8182/graphs/graph/vertices/4>`
which is expected.How do I extract the key-value pairs from this node?

'dpid'  : dpid_str,
'state' :'active',
'type'  :'switch'

【问题讨论】:

    标签: cassandra titan bulbs


    【解决方案1】:
    >>> switches = self.g.vertices.index.lookup(dpid=dpid_str)
    >>> ports    = self.g.vertices.index.lookup(port_id=port_id_str)
    
    for s in switches
         print s.dpid, s.state, s.type
         print s.data()
    

    ...如果顶点是唯一的(仅返回一个值),则使用 index.get_unique() 而不是 index.lookup()...

     >>> switch = self.g.vertices.index.get_unique(dpid=dpid_str)
     >>> print switch.dpid, switch.state, switch.type
     >>> print switch.data()
    

    有关更多信息,请参阅 Bulbs 文档和快速入门:

    【讨论】:

      猜你喜欢
      • 2017-09-12
      • 1970-01-01
      • 1970-01-01
      • 2015-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多