c# - AWS Neptune Gremlin C# GraphTraversalSource 不工作
问题描述
我已经看到了多个这样做的例子(各种语言),这表明这应该可行。也许我错过了一步?注释掉表明我尝试过的其他事情的行。
以下是我如何让我的 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# 中,这只是部分代码,更多的是教程。似乎没有注入别名,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:Bytecode, @value={$type=System.Collections.Generic.Dictionary
2[[System.String , mscorlib],[System.Collections.Generic.IEnumerable 1[[System.Collections.Generic.IEnumerable
1[[System.Object, mscorlib]], 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对象"作为遍历源。
解决方案
您建立连接的方法是正确的,尽管现在不推荐使用这种方法。您现在应该使用:
g = Traversal().withRemote(remoteConnection);
但是,这不是导致您的问题的原因。Neptune 正在等待包含别名“g”的请求。在您的集群上启用审计日志记录以准确查看您的代码作为别名而不是“g”发送的内容可能会很好。
推荐阅读
- java - CloudFunction 作为 gradle 子项目
- javascript - 为什么等待服务器响应后不执行代码行
- python - 'TypeError:在尝试模拟异常时不允许捕获不从 BaseException 继承的类'
- python - 如何在 python 中调用使用命令行界面的 Web 服务?
- javascript - 如何使用 JavaScript 查找一个字符是否在字符串中多次出现?
- c - 如果存在等于给定数字的数字组合,则打印
- macos - macOS 上的终端/iTerm2 窗口名称:如何取消 SSH 以显示下一个进程?
- javascript - 将对象传播到参数中?
- algorithm - 将椭圆弧拟合到点或其他曲线
- node.js - 在 Discord.js 中查找所有具有角色的成员