c# - AWS Neptune Gremlin C# GraphTraversalSource 不工作

标签 c# gremlin amazon-neptune

我见过多个这样做的例子(各种语言),这表明这应该有效。也许我错过了一步?注释掉表明我尝试过的其他事情的行。

下面是我如何让我的 gremlin 客户端和一个 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;

然后……

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# 中并且只是部分代码,更多的是教程。似乎没有注入(inject)别名,g 似乎默认可用?再次注意,我在提交的 groovy 脚本中使用了 g,这有效。

为了根据建议进行记录,我们添加了日志记录,这是示例语句生成的内容:

"RequestMessage{, requestId=709ba190-0ce9-4272-aadb-4b28c21accf6, op='bytecode', processor='traversal', args={gremlin={$type=System.Collections.Generic.Dictionary 2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib, @type=g:字节码, @value={$type=System.Collections.Generic.Dictionary2[[系统.String, mscorlib],[System.Collections.Generic.IEnumerable1[[System.Collections.Generic.IEnumerable1[[System.Object, mscorlib]], mscorlib], mscorlib]], mscorlib,步骤={$type=System.Linq.Enumerable+WhereSelectListIterator2[[Gremlin.Net.Process.Traversal.Instruction, Gremlin.Net],[System.Collections.Generic.IEnumerable1[ [System.Object, mscorlib]], mscorlib]], System.Core, $values=[[V], [hasLabel, article], [has, languageCode, fr-FR], [count]]}}}, 别名={$type=System.Collections.Generic.Dictionary2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib, g=g}, $type=System.Collections.Generic。字典2[[System.String, msco rlib],[System.Object, mscorlib]], mscorlib}}”

我不确定这是否有帮助。最初的错误消息暗示该语句不是以某种方式以“g”开头,但鉴于我正在做的事情,我不明白为什么不是 - 这是从具有“g”的 drm 构建 gts 对象"作为遍历源。

最佳答案

您建立连接的方法是正确的,尽管现在已弃用这种方法。你现在应该使用:

g = Traversal().withRemote(remoteConnection);

但是,这不是导致您出现问题的原因。 Neptune 期待包含别名“g”的请求。最好在您的集群上启用审核日志记录,以准确查看您的代码作为别名而不是“g”发送的内容。

关于c# - AWS Neptune Gremlin C# GraphTraversalSource 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63357287/

相关文章:

c# - IsMouseOver WPF 中的不透明度

c# - xmlns ='' > 不是预期的。 - XML 文档中存在错误 (2, 2)

c# - 分解神对象的接口(interface)继承?

azure - Gremlin Graph API 查询日志记录

gremlin - 通过应用程序负载均衡器连接到 AWS Neptune

gremlin - 如何使用 Gremlin 沿路径收集所有顶点和边属性

c# - 在 c# 中使用 ssl 的 Google Cloud Sql 连接

azure-cosmosdb - CosmosDB 上的 Gremlin - 删除并重新创建顶点的属性而不删除顶点

python - gremlin-python : what is a valid vertex custom id?

amazon-web-services - Neptune 加载程序 FROM_OR_TO_VERTEX_ARE_MISSING