简体   繁体   English

格式化CosmosDB Gremlin查询

[英]Formatting CosmosDB Gremlin Query

I'm new to Gremlin and CosmosDB. 我是Gremlin和CosmosDB的新手。 I've been following the tinkerpop tutorials and am using the TinkerFactory.createModern() test graph. 我一直在关注tinkerpop教程,并且正在使用TinkerFactory.createModern()测试图。

在此处输入图片说明

What I am looking for is to return a graphson object similar to this from cosmosdb. 我正在寻找的是从cosmosdb返回与此类似的graphson对象。

{
"user": {
    "name": "Marko",
    "age": 29       
},
"knows": [
    {"name": "josh", "age": 32},
    {"name": "vadas", "age": 27}
],
"created": [
    {"name": "lop", "lang": "java"} 
]
}

My thoughts were to try 我的想法是尝试

g.V().has('name', 'marko').as('user').out('knows').as('knows').out('created').as('created').select('user', 'knows', 'created')

What i really get back is in the picture below. 我真正得到的回报是在下面的图片中。 I was hoping to have single user object, with an array of knows objects and software objects. 我希望拥有单个用户对象,并带有一系列已知对象和软件对象。

If this is possible can you please explain what steps need to be used to get this format. 如果可以的话,请您说明需要什么步骤来获取这种格式。

在此处输入图片说明

Hope my question is clear and thanks to anyone that can help =) 希望我的问题很清楚,并感谢能提供帮助的任何人=)

You should use project() : 您应该使用project()

gremlin> g.V().has('person','name','marko').
......1>   project('user','knows','created').
......2>     by(project('name','age').by('name').by('age')).
......3>     by(out('knows').project('name','age').by('name').by('age')).
......4>     by(out('created').project('name','lang').by('name').by('lang'))
==>[user:[name:marko,age:29],knows:[name:vadas,age:27],created:[name:lop,lang:java]]

That syntax should work with CosmosDB. 该语法应与CosmosDB一起使用。 In TinkerPop 3.4.0, things get a little nicer as you can use valueMap() a bit more effectively (but I don't think that CosmosDB supports that as of the time of this answer): 在TinkerPop 3.4.0中,事情变得更好一些了,因为您可以更有效地使用valueMap()了(但是我不认为CosmosDB在此回答时还支持该功能):

gremlin> g.V().has('person','name','marko').
......1>   project('user','knows','created').
......2>     by(valueMap('name','age').by(unfold())).
......3>     by(out('knows').valueMap('name','age').by(unfold())).
......4>     by(out('created').valueMap('name','lang').by(unfold()))
==>[user:[name:marko,age:29],knows:[name:vadas,age:27],created:[name:lop,lang:java]]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM