【问题标题】:Tinkerpop3 Gremlin Traversal ErrorTinkerpop3 Gremlin 遍历错误
【发布时间】:2024-01-24 02:30:01
【问题描述】:

我有一个结构如下的图表:

|-ProductFit
|-|-Part
|-|-App
|-|-|-ProductID
|-|-|-ProductModelID
|-|-|-ProductYearID

|-ProductID
|-|-ProductName
|-|-ProductModelID
|-|-ProductYearID

|-ProductModelID
|-|-ProductModelName

|-ProductYearID
|-|-ProductYear

ProductFit 是我的第一个独立顶点,ProductID、ProductModelID 和 ProductYearID 作为我连接的顶点。

现在,ProductFit 中的某些 ProductID 字段的值错误,我需要从 ProductID 的其他顶点获取值。

这是我的查询:

g.V().has('ProductFit','Part','PA01').properties('App')
.valueMap('ProductID','ProductModelID','ProductYearID')
.choose(values('ProductModelID'))
.option(PM01, g.V().has('ProductFit','Part','PA01').properties('App').values('ProductModelID'))
.option(PM02, g.V().has('ProductID','ProductModelID','PM01'))
.values('ProductModelID')

但这给了我这个错误:

java.util.HashMap cannot be cast to org.apache.tinkerpop.gremlin.structure.Element

是在遍历过程中我不能从一个顶点转到另一个顶点还是查询有问题? TIA。

【问题讨论】:

    标签: gremlin tinkerpop3


    【解决方案1】:

    您的choose() 正在使用values(),这并不是要从Map 中挑选值。它旨在与Element 一起使用。我在 The Crew 玩具图上遇到了同样的错误:

    gremlin> graph = TinkerFactory.createTheCrew()
    ==>tinkergraph[vertices:6 edges:14]
    gremlin> g = graph.traversal()
    ==>graphtraversalsource[tinkergraph[vertices:6 edges:14], standard]
    gremlin> g.V().properties('location').valueMap().choose(values('startTime')).option(2004,constant(1)).option(none,constant(2))
    java.util.HashMap cannot be cast to org.apache.tinkerpop.gremlin.structure.Element
    Type ':help' or ':h' for help.
    Display stack trace? [yN]n
    

    你应该改用select:

    gremlin> g.V().properties('location').valueMap().choose(select('startTime')).option(2004,constant(1)).option(none,constant(2))
    ==>2
    ==>2
    ==>1
    ...
    ==>2
    

    【讨论】: