Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't delete/remove multiple property keys on Vertex Titan 1.0 Tinkerpop 3

Very basic question,
I just upgraded my Titan from 0.54 to Titan 1.0 Hadoop 1 / TP3 version 3.01.

I encounter a problem with deleting values of

Property key: Cardinality.LIST/SET

Maybe it is due to upgrade process or just my TP3 misunderstanding.

 // ----- CODE ------:

tg = TitanFactory.open(c);

TitanManagement mg = tg.openManagement();

//create KEY (Cardinality.LIST) and commit changes
tm.makePropertyKey("myList").dataType(String.class).cardinality( Cardinality.LIST).make();
mg.commit();

//add vertex with multi properties

Vertex v = tg.addVertex();

v.property("myList", "role1");
v.property("myList", "role2");
v.property("myList", "role3");
v.property("myList", "role4");
v.property("myList", "role4");

Now, I want to delete all the values "role1,role2...."

// iterate over all values and try to remove the values 
 List<String> values = IteratorUtils.toList(v.values("myList"));
        for (String val : values) {
            v.property("myList", val).remove();
         }
  tg.tx().commit();

//---------------- THE EXPECTED RESULT ----------: Empty vertex properties

But unfortunately the result isn't empty:

System.out.println("Values After Delete" + IteratorUtils.toList(v.values("myList")));

//------------------- OUTPUT --------------:

After a delete, values are still apparent!

15:19:59,780  INFO ThriftKeyspaceImpl:745 - Detected partitioner org.apache.cassandra.dht.Murmur3Partitioner for keyspace titan

15:19:59,784  INFO Values After Delete [role1, role2, role3, role4, role4]

Any ideas?

like image 687
VitalyT Avatar asked Apr 11 '16 13:04

VitalyT


2 Answers

You're not executing graph traversals with the higher level Gremlin API, but you're currently mutating the graph with the lower level graph API. Doing for loops in Gremlin is often an antipattern.

According to the TinkerPop 3.0.1 Drop Step documentation, you should be able to do the following from the Gremlin console:

v = g.addV().next()
g.V(v).property("myList", "role1")
g.V(v).property("myList", "role2")
// ...
g.V(v).properties('myList').drop()
like image 196
jbmusso Avatar answered Sep 24 '22 07:09

jbmusso


property(key, value) will set the value of the property on the vertex (javadoc). What you should do is get the VertexProperties (javadoc).

for (VertexProperty vp : v.properties("name")) {
    vp.remove();
}

@jbmusso offered a solid solution using the GraphTraversal instead.

like image 39
Jason Plurad Avatar answered Sep 24 '22 07:09

Jason Plurad