AWS Neptune Gremlin C#中的GraphTraversalSource无法工作

3

我看到多个示例(使用不同语言)都可以完成这个操作,这表明这应该可以工作。也许我漏掉了某个步骤?注释掉了指示我尝试过其他方法的行。

这是我获取我的“gremlin client”和“graphTraversalSource”直接使用的方法。

var gremlinServer = new GremlinServer(endpoint, 8182, enableSsl: true);
GremlinClient = new GremlinClient(gremlinServer);

//var remoteConnection = new DriverRemoteConnection(GremlinClient, "g");
var remoteConnection = new DriverRemoteConnection(GremlinClient);
//g = AnonymousTraversalSource.Traversal().WithRemote(remoteConnection);
g = new Graph().Traversal().WithRemote(remoteConnection);

如果我像这样将查询作为字符串提交:
var gndrSetCnt = GremlinQueryCount(GremlinClient, "g.V().count().next();");
var gndrResult = gndrSetCnt.Result;

and then....

private async Task<long> GremlinQueryCount(GremlinClient gremlinClient, string query)
{
    return await gremlinClient.SubmitWithSingleResultAsync<long>(query);
}

虽然它笨拙,但仍可以正常工作。不过,如果我试图直接使用"g",像这样:

var example = g.V().Count().Next();

然后我会得到这样的错误信息:

Gremlin.Net.Driver.Exceptions.ResponseException: 'InvalidRequestArguments: {"detailedMessage":"A message with [bytecode] op code requires the [aliases] argument to be a Map containing one alias assignment named 'g'.","requestId":"ae024dd7-0fca-472b-acc6-7f717ca4bf2d","code":"InvalidParameterException"}'

我是否忽略了什么步骤?我在多个示例中看到过这种情况,似乎没有做其他任何操作,但我承认只有一个C#示例,并且那只是部分代码,更像是教程。貌似没有注入别名,g似乎默认可用?请注意,我在提交的Groovy脚本中使用g,它可以正常工作。据建议记录,我们添加了日志记录,以下是样本语句产生的内容:“RequestMessage {,requestId = 709ba190-0ce9-4272-aadb-4b28c21accf6,op ='bytecode',processor ='traversal',args = {gremlin = {$type = System.Collections.Generic.Dictionary2 [[System.String, mscorlib],[System.Object, mscorlib]],mscorlib,@type = g:Bytecode,@value = {$type = System.Collections.Generic.Dictionary 2 [[System.String, mscorlib],[System.Collections.Generic.IEnumerable1[[System.Collections.Generic.IEnumerable1[[System.Object, mscorlib]],mscorlib]],mscorlib,step ={$type = System.Linq.Enumerable+WhereSelectListIterator 2 [[Gremlin.Net.Process.Traversal.Instruction ,Gremlin.Net],[System.Collections.Generic.IEnumerable 1 [[System.Object,mscorlib]],mscorlib]],System.Core,$values = [[V],[hasLabel,article],[has,languageCode,fr-FR],[count]]}}},aliases = {$type = System.Collections.Generic.Dictionary 2 [[System.String,mscorlib],[System.Object,mscorlib]],mscorlib,g = g},$type = System.Collections.Generic.Dictionary 2 [[System.String,mscorlib],[System.Object,mscorlib]],mscorlib}}”我不确定这是否有帮助。原始错误消息表明,某种方式语句没有以“g”开头,但我不明白为什么会这样,因为我正在从具有“g”作为遍历源的drm中构建gts对象。

你使用的Gremlin.Net版本是哪个?另外,你可以尝试一下是否只是使用Gremlin服务器出现了相同的问题?你可以使用Docker启动Gremlin服务器进行测试,例如:docker run --rm -p 8182:8182 -it tinkerpop/gremlin-server。从你展示的代码来看,它应该在一般情况下能够运行。 - Florian Hockmann
1个回答

0

您建立连接的方法是正确的,尽管这是一种现在已经过时的方式。您现在应该使用:

g = Traversal().withRemote(remoteConnection);

然而,那并不是导致你问题的原因。Neptune 期望请求包含一个别名为 'g' 的参数。最好在你的集群上启用审计日志,以便准确查看你的代码发送的别名是否为 'g'。


感谢您的回复,我们已经添加了日志,并将响应添加到原始问题中。 - houghm

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接