Gremlin-Server 添加具有多个属性的顶点 (Titan 1.0.0) [英] Gremlin-Server Add Vertex with Multiple Properties (Titan 1.0.0)

查看:15
本文介绍了Gremlin-Server 添加具有多个属性的顶点 (Titan 1.0.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm creating a Titan graph (backed by Dynamodb); I'm using Titan 1.0.0 and running Gremlin-Server 3 (on TinkerPop3).

I'm trying to add a vertex to my graph with a label and multiple properties in a single line. I'm able to add a vertex with a label and a single property, and I can add multiple properties to a vertex after it has been created, but it seems that I can't do it all at once.

For testing I'm running commands in the gremlin shell, but the end use case is interacting with it via REST api (which is already working fine).

As a note, I'm rolling back after each of these transactions so I have a clean slate.

Here is how I'm initiating my session:

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]

I can create a vertex with a label and a single property like this:

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]]

I can also create a vertex and then append many properties afterward with a traversal starting at the vertex I just created:

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]]

This is all well and good, but I'm trying to avoid making 2 calls to achieve this result, so I'd like to create the vertex with all of these properties at once. Essentially, I want to be able to do something like the following, but it fails with more than 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]

I've also tried using 1 .property() with multiple properties (along with all other syntax variations I could think of), but it only seems to catch the first one:

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]]

I've looked through all of the documentation I can get my hands on from all sources I can find and I can't find anything on this "all at once" method. Has anyone done this before or know how it could be done?

Thanks in advance!

解决方案

As described in Chapter 3 Getting Started of the Titan docs, the GraphOfTheGodsFactory.java source code shows how to add a vertex with a label and multiple properties.

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

The method addVertex(Object... keyValues) ultimately comes from Graph interface defined by Apache TinkerPop. Titan 1.0.0 uses TinkerPop 3.0.1, and you can find more documentation on the addVertex step (and many other steps) in the TinkerPop docs.

这篇关于Gremlin-Server 添加具有多个属性的顶点 (Titan 1.0.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆