在 gremlin 中仅提取值作为 csv 格式
Extract Only Values as csv format in gremlin
我正在尝试从图形数据库中提取值。我正在尝试使用下面的 gremlin 控制台命令,但它正在返回键值对,我们可以将其转换为列表。
%%gremlin
g.V().hasLabel('airport').limit(2).project('id','label','region','country').by(id()).by(label()).by('region').by('country').fold()
输出
[{'id': '1', 'label': 'airport', 'region': 'US-GA', 'country': 'US'}, {'id': '2', 'label': 'airport', 'region': 'US-AK', 'country': 'US'}]
预期输出:
'1', 'airport', 'US-GA', 'US'
'2', 'airport', 'US-AK', 'US'
or
[['1','airport','US-GA','US'], ['2','airport', 'US-AK','US']]
您可以使用 values
而不是 project
。 project
和 valueMap
return 之类的步骤是 key:value 映射,而 values
不在其结果中包含键。
gremlin> g.V().
hasLabel('airport').
limit(2).
local(union(id(),label(),values('region','country')).fold())
==>[1,airport,US,US-GA]
==>[2,airport,US,US-AK]
作为替代方案,您可以将 select(values)
添加到您当前的查询中,我认为我更喜欢这样,因为它避免了需要 local
和 union
步骤。
gremlin> g.V().
hasLabel('airport').
limit(2).
project('id','label','region','country').
by(id()).
by(label()).
by('region').by('country').
select(values).
fold()
==>[[1,airport,US-GA,US],[2,airport,US-AK,US]]
我正在尝试从图形数据库中提取值。我正在尝试使用下面的 gremlin 控制台命令,但它正在返回键值对,我们可以将其转换为列表。
%%gremlin
g.V().hasLabel('airport').limit(2).project('id','label','region','country').by(id()).by(label()).by('region').by('country').fold()
输出
[{'id': '1', 'label': 'airport', 'region': 'US-GA', 'country': 'US'}, {'id': '2', 'label': 'airport', 'region': 'US-AK', 'country': 'US'}]
预期输出:
'1', 'airport', 'US-GA', 'US'
'2', 'airport', 'US-AK', 'US'
or
[['1','airport','US-GA','US'], ['2','airport', 'US-AK','US']]
您可以使用 values
而不是 project
。 project
和 valueMap
return 之类的步骤是 key:value 映射,而 values
不在其结果中包含键。
gremlin> g.V().
hasLabel('airport').
limit(2).
local(union(id(),label(),values('region','country')).fold())
==>[1,airport,US,US-GA]
==>[2,airport,US,US-AK]
作为替代方案,您可以将 select(values)
添加到您当前的查询中,我认为我更喜欢这样,因为它避免了需要 local
和 union
步骤。
gremlin> g.V().
hasLabel('airport').
limit(2).
project('id','label','region','country').
by(id()).
by(label()).
by('region').by('country').
select(values).
fold()
==>[[1,airport,US-GA,US],[2,airport,US-AK,US]]