【问题标题】:Gremlin-Server Add Vertex with Multiple Properties (Titan 1.0.0)Gremlin-Server 添加具有多个属性的顶点 (Titan 1.0.0)
【发布时间】:2016-12-02 02:27:15
【问题描述】:

我正在创建一个 Titan 图(由 Dynamodb 支持);我正在使用 Titan 1.0.0 并运行 Gremlin-Server 3(在 TinkerPop3 上)。

我正在尝试将一个顶点添加到我的图形中,并在一行中使用一个标签和多个属性。我可以添加带有标签和单个属性的顶点,并且可以在创建顶点后将多个属性添加到顶点,但似乎我不能一次完成。

为了进行测试,我在 gremlin shell 中运行命令,但最终用例是通过 REST api 与它进行交互(已经正常工作)。

作为说明,我会在每笔交易后回滚,所以我有一张白纸。

这是我开始会话的方式:

gremlin> graph = TitanFactory.open('conf/gremlin-server/dynamodb.properties')
==>standardtitangraph[com.amazon.titan.diskstorage.dynamodb.DynamoDBStoreManager:[127.0.0.1]]
gremlin> g = graph.traversal()
==>graphtraversalsource[standardtitangraph[com.amazon.titan.diskstorage.dynamodb.DynamoDBStoreManager:[127.0.0.1]], standard]

我可以创建一个带有标签和单个属性的顶点,如下所示:

gremlin> graph.addVertex('date_of_birth').property('date_of_birth','1949-01-01')
==>vp[date_of_birth->1949-01-01]
gremlin> g.V().hasLabel('date_of_birth').has('date_of_birth','1949-01-01').valueMap()
==>[date_of_birth:[1949-01-01]]

我还可以创建一个顶点,然后从我刚刚创建的顶点开始遍历,然后附加许多属性:

gremlin> v1 = graph.addVertex('date_of_birth')
==>v[409608296]
gremlin> g.V(v1).property('date_of_birth','1949-01-01').property('year_of_birth',1949).property('date_of_birth','1949-01-01').property('day_of_birth',1).property('age',67).property('month_of_birth',1)
==>v[409608296]
gremlin> g.V(v1).valueMap()
==>[day_of_birth:[1], date_of_birth:[1949-01-01], month_of_birth:[1], age:[67], year_of_birth:[1949]]

这一切都很好,但我试图避免进行 2 次调用来实现此结果,所以我想一次创建具有所有这些属性的顶点。本质上,我希望能够执行以下操作,但由于超过 1 个 .property() 而失败:

gremlin> graph.addVertex('date_of_birth').property('date_of_birth','1949-01-01').property('year_of_birth',1949).property('date_of_birth','1949-01-01').property('day_of_birth',1).property('age',67).property('month_of_birth',1)
No signature of method: com.thinkaurelius.titan.graphdb.relations.SimpleTitanProperty.property() is applicable for argument types: (java.lang.String, java.lang.String) values: [date_of_birth, 1949-01-01]

我也尝试过使用具有多个属性的 1 .property()(以及我能想到的所有其他语法变体),但它似乎只抓住了第一个:

gremlin> graph.addVertex('date_of_birth').property('date_of_birth','1949-01-01','year_of_birth',1949,'date_of_birth','1949-01-01','day_of_birth',1,'age',67,'month_of_birth',1)
gremlin> g.V().hasLabel('date_of_birth').has('date_of_birth','1949-01-01').valueMap()
==>[date_of_birth:[1949-01-01]]

我已经浏览了所有我可以从我能找到的所有来源获得的所有文档,但我找不到关于这种“一次性”方法的任何内容。有没有人这样做过或知道如何做到这一点?

提前致谢!

【问题讨论】:

    标签: amazon-dynamodb titan gremlin tinkerpop3 gremlin-server


    【解决方案1】:

    正如 Titan 文档的 Chapter 3 Getting Started 中所述,GraphOfTheGodsFactory.java 源代码显示了如何添加具有标签和多个属性的顶点。

    saturn = graph.addVertex(T.label, "titan", "name", "saturn", "age", 10000);
    

    addVertex(Object... keyValues)方法最终来自Apache TinkerPop定义的Graph接口。 Titan 1.0.0 使用 TinkerPop 3.0.1,您可以在 TinkerPop 文档中的 addVertex 步骤(以及许多其他步骤)中找到更多 documentation

    【讨论】:

    • 啊!就是这样!让我无法理解的一件事是 T 对象。现在你指出了它,它正好在那个文档的中间palm => face。感谢您的快速回答,为我节省了很多挫败感!
    猜你喜欢
    • 2019-10-29
    • 2016-09-15
    • 2014-12-25
    • 2015-07-06
    • 1970-01-01
    • 2012-03-12
    • 1970-01-01
    • 2016-05-26
    • 1970-01-01
    相关资源
    最近更新 更多