【问题标题】:Apache TinkerPop allow duplicated Vertex IDApache TinkerPop 允许重复的顶点 ID
【发布时间】:2022-11-11 07:56:12
【问题描述】:

在这个测试中我们可以看到它不允许为相同的数据类型插入相同的顶点 ID,但对于不同的数据类型它允许。

  • 这是预期的行为还是错误?
  • 如何知道 Vertex 创建后的 Vertex ID 数据类型是什么?
gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.V()

# generate vertex id automatically by UUID.randomUUID()
gremlin> g.addV().property(id,UUID.randomUUID())
==>v[b47bb233-9a2a-49c8-8ada-0ac0fe9be6f2]
gremlin> g.V()
==>v[b47bb233-9a2a-49c8-8ada-0ac0fe9be6f2]

# generate vertex id manually as UUID datatype.
gremlin> g.addV().property(id,UUID.fromString("c2d673de-2425-4b42-bc1e-68ff20e3b0a8"))
==>v[c2d673de-2425-4b42-bc1e-68ff20e3b0a8]
gremlin> g.V()
==>v[c2d673de-2425-4b42-bc1e-68ff20e3b0a8]
==>v[b47bb233-9a2a-49c8-8ada-0ac0fe9be6f2]

# generate vertex id manually as STRING datatype.
gremlin>  g.addV().property(id,"c2d673de-2425-4b42-bc1e-68ff20e3b0a8")
==>v[c2d673de-2425-4b42-bc1e-68ff20e3b0a8]
gremlin> g.V()
==>v[c2d673de-2425-4b42-bc1e-68ff20e3b0a8]
==>v[b47bb233-9a2a-49c8-8ada-0ac0fe9be6f2]
==>v[c2d673de-2425-4b42-bc1e-68ff20e3b0a8]

# here we can see the vertex with same id duplicated.
gremlin>  g.V().id()
==>c2d673de-2425-4b42-bc1e-68ff20e3b0a8
==>b47bb233-9a2a-49c8-8ada-0ac0fe9be6f2
==>c2d673de-2425-4b42-bc1e-68ff20e3b0a8

# trying to insert it again as UUID datatype.
gremlin> g.addV().property(id,UUID.fromString("c2d673de-2425-4b42-bc1e-68ff20e3b0a8"))
Vertex with id already exists: c2d673de-2425-4b42-bc1e-68ff20e3b0a8

# trying to insert it again as STRING datatype.
gremlin>  g.addV().property(id,"c2d673de-2425-4b42-bc1e-68ff20e3b0a8")
Vertex with id already exists: c2d673de-2425-4b42-bc1e-68ff20e3b0a8

【问题讨论】:

    标签: java gremlin tinkerpop janusgraph


    【解决方案1】:

    这是预期的行为。你可以做:

    gremlin> g.V().project('id', 'class')
      .by(id())
      .by(map{it->it.get().id().getClass()})
    ==>[id:b6609a02-4574-4e6f-87ab-6ea3edaa9e55,class:class java.lang.String]
    ==>[id:b6609a02-4574-4e6f-87ab-6ea3edaa9e55,class:class java.util.UUID]
    

    显然,比较 String 对象和 UUID 对象总是会导致 false。

    顺便说一句,您打开的图是一个 TinkerGraph,它作为 Apache TinkerPop 的一部分随 JanusGraph 一起提供。 JanusGraph 本身不允许指定顶点 ID,除非以这种方式明确配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-15
      • 2019-05-18
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-18
      相关资源
      最近更新 更多