You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gremlin merge API在3.6.2抛异常,3.7.0正常运行求助

Gremlin 3.6.2与3.7.0 merge操作兼容性问题:原因及修复

版本差异原因

  • 3.6.2版本的MergeVertexStep内部会对Merge.onCreate/Merge.onMatch传入的Map执行putAll修改操作,但Map.of()创建的是Java不可变集合(ImmutableCollections实现),不支持修改操作,因此触发UnsupportedOperationException。
  • 3.7.0版本中Gremlin修复了该缺陷,内部会自动将不可变Map转换为可变集合后再处理,因此代码可以正常执行。

修复方案

针对3.6.2版本,只需将Merge.onCreate和Merge.onMatch参数中的不可变Map替换为可变Map即可,推荐使用new HashMap<>(Map.of(...))的方式快速转换:

修复后的简单复现代码

g.mergeV(Map.of(T.id, 300))
  .option(Merge.onCreate, new HashMap<>(Map.of(T.label, "Dog", "name", "Toby", "age", 10)))
  .option(Merge.onMatch, new HashMap<>(Map.of("age", 11)))
  .next();

修复后的原业务代码

TinkerGraph.open().traversal()
.mergeV(Map.of(
    T.id, "e1",
    T.label, "endpoint"))
.as("e")
.mergeV(Map.of(
    T.id, "p1",
    T.label, "permission"))
.option(Merge.onCreate, new HashMap<>(Map.of("value", "read-only")))
.as("p")
.mergeE(Map.of(
    T.label, "REQUIRES_PERMISSION",
    Direction.from, Merge.outV,
    Direction.to, Merge.inV
))
.option(Merge.outV, select("e"))
.option(Merge.inV, select("p"))
.iterate();

内容的提问来源于stack exchange,提问作者Paul Schwarz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 05:25:36