【问题标题】:Use Traversal to query Azure Cosmos DB graph使用 Traversal 查询 Azure Cosmos DB 图
【发布时间】:2018-04-12 19:47:29
【问题描述】:

我正在尝试使用 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) }

问题是执行在 result.all().get() 之后挂起并且从未得到响应。我只有在提交遍历时遇到这个问题。直接提交 Gremlin 查询字符串时,它可以正常工作。

【问题讨论】:

    标签: azure-cosmosdb


    【解决方案1】:

    我也有类似的情况,但根据最近的查询Does Cosmos DB support Gremlin.net c# GLV?,目前还不可能进行遍历。但是,对于那些使用(或考虑使用)Gremlin.NET 连接到 Cosmos 的人,我将分享一些我已经能够做到的事情。

    首先,我从 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
    

    当使用 Gremlin.NET 与本地托管的 gremlin 服务器一起工作时(请参阅注释掉的行),一切正常。

    我可以使用 gremlin.net 处理 cosmos 的唯一方法是将查询作为字符串文字提交,例如

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

    这可行,但我希望能够使用流畅的遍历。

    我可以使用 Azure/Graph API(documentclient 等)非常轻松地使用 Cosmos,但仍然只能使用字符串文字。另外,这不是很便携,apparently slower too

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多