Re: Failing to store List as property value


Debasish Kanhar <d.k...@...>
 

Hi Manish,

Well you are adding List property to JanusGraph in wrong way. The way I do to create List properties once the schema is defined is as follows:

The following things should work, and if it doesn't let us know.

JanusGraph graph = JanusGraphFactory.open("/
janusgraph-0.2.0-hadoop2/conf/janusgraph-cassandra.properties")
      
JanusGraphManagement mgmt = graph.openManagement();
mgmt.makePropertyKey("test1").dataType(String.class).cardinality(Cardinality.LIST).make();
mgmt.commit();
JanusGraphVertex v = graph.addVertex();
ArrayList al = new ArrayList();
al.add("aaa");
al.add("bbb");


Now we have to iterate over the list elements, and add it to JanusGraphVertex v object as follows:

for (int i = 0; i < al.size(); ++i) {
    elem = al.get(i);
    v.property("test1", elem);
}   

Or else, if you want to add manually, this should suffice:

v.property("test1", "aaaa").property("test1", "bbbb").property("test1", "cccc")......

As you can see, gremlin doesn't expect you to pass List, and it will parse that list into property. Rather it expects you to pass the list element wise, and it keeps on appending to property key which you defined as List in schema declaration. If the same wasn't declared as List in schema, then it replaces the prior value.

Join {janusgraph-dev@lists.lfaidata.foundation to automatically receive all group messages.