使用Gremlin操作Neptune边时遇‘not spawned anonymously’错误求助
解决Amazon Neptune中Gremlin fold()+coalesce()边Upsert的错误
错误原因分析
错误提示明确指出:The child traversal of [...] was not spawned anonymously - use the __ class rather than a TraversalSource to construct the child traversal。问题出在coalesce的第二个分支中直接使用了TraversalSource g,在fold()之后的遍历上下文里,子遍历必须使用匿名遍历器__来构建,不能直接调用g。
修正后的Gremlin查询
将新增分支中的g.V('54')替换为__.V('54'),同时移除冗余的重复属性设置:
g.E().has(id, '6529056485837422516').fold().coalesce( unfold().property('createdat', 1553676114) .property('status', 0) .property('edgeproperty', 'connects') .property('source', '63') .property('destination', '54'), __.V('54').addE('connects').to(__.V('63')) .property(id, '6529056485837422516') .property('createdat', 1553676114) .property('status', 0) .property('edgeproperty', 'connects') .property('source', '63') .property('destination', '54') )
关键修正点说明
- 替换
g.V('54')为__.V('54'):在coalesce的子遍历逻辑中,必须使用匿名遍历器__发起顶点查询,不能直接使用全局的TraversalSourceg,这是Gremlin遍历上下文的规则,Neptune对此有严格校验。 - 移除重复的
property(id, ...):原查询中重复设置了两次边的id属性,属于冗余操作,只需保留一次即可。
执行逻辑验证
修正后的查询会按以下逻辑执行:
- 先尝试查找指定id的边;
- 若找到边,展开后更新其属性;
- 若未找到边,创建新边并设置所有指定属性。
内容的提问来源于stack exchange,提问作者Abhay Kumar
相关产品推荐
相关产品推荐

