简体   繁体   English

使用Traversal查询Azure Cosmos DB图

[英]Use Traversal to query Azure Cosmos DB graph

I am trying to use Traversal to query an Azure Cosmos DB graph as follows 我正在尝试使用Traversal查询Azure Cosmos DB图,如下所示

val cluster = Cluster.build(File("remote.yaml")).create()
val client = cluster.connect()

val graph = EmptyGraph.instance()
val g = graph.traversal().withRemote(DriverRemoteConnection.using(cluster))

val traversal = g.V().count()
val aliased = client.alias("g")

val result = aliased.submit(traversal)

val resultList = result.all().get()

resultList.forEach { println(it) }

Problem is execution hangs after result.all().get() and never get a response. 问题是执行在result.all()。get()之后挂起并且永远不会得到响应。 I only have this problem when submitting a traversal. 提交遍历时我只有这个问题。 When submitting a Gremlin query string directly it works properly. 直接提交Gremlin查询字符串时,它可以正常工作。

I'm in a similar boat, but according to this recent query Does Cosmos DB support Gremlin.net c# GLV? 我在类似的船上,但根据最近的查询, Cosmos DB是否支持Gremlin.net c#GLV? traversals are not possible just yet. 遍历是不可能的。 However, for those using (or thinking about using) Gremlin.NET to connect to Cosmos, I'll share some of what I've been able to do. 但是,对于那些使用(或考虑使用)Gremlin.NET连接到Cosmos的人,我将分享一些我能够做到的事情。

Firstly, I have no trouble connecting to cosmos from the gremlin console, just when using Gremlin.NET as follows: 首先,我可以毫不费力地从gremlin控制台连接到cosmos,就像下面使用Gremlin.NET一样:

var gremlinServer = new GremlinServer(hostname, port, enableSsl: true,                                                                 
username: "/dbs/" + database + "/colls/" + collection,                                                                
password: authKey);
var driver = new DriverRemoteConnection(new GremlinClient(gremlinServer));
//var driver = new DriverRemoteConnection(new GremlinClient(new GremlinServer("localhost", 8182)));

var graph = new Gremlin.Net.Structure.Graph();
var g = graph.Traversal().WithRemote(driver);

g.V().Drop().Next(); // nullreferenceexception

When using Gremlin.NET to work with a locally hosted gremlin server (see commented out line), all works fine. 当使用Gremlin.NET与本地托管的gremlin服务器一起工作时(参见注释掉的行),一切正常。

The only way I can work with cosmos using gremlin.net is to submit queries as string literals eg 我可以使用gremlin.net与cosmos一起工作的唯一方法是将查询作为字符串文字提交,例如

var task = gremlinClient.SubmitAsync<dynamic>("g.V().Drop()");

This works, but I want to be able to use fluent traversals. 这有效,但我希望能够使用流畅的遍历。

I can work with Cosmos quite easily using the Azure/Graph API (documentclient etc), but still only with string literals. 我可以使用Azure / Graph API(documentclient等)轻松地使用Cosmos,但仍然只能使用字符串文字。 Also, this isn't very portable, and apparently slower too 此外,这不是非常便携,而且显然也较慢

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

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