Determining if the AddPropertyStep creates a VertexProperty or a Property

26 views
Skip to first unread message

potera...@gmail.com

unread,
Jul 28, 2015, 5:09:29 AM7/28/15
to Gremlin-users
Hi Guys,

I'm trying to set a timestamp on vertex properties as they get created. To do that, in my strategy I would have to replace the AddPropertyStep with a new instance of the AddPropertyStep that takes in my property and it's value through the vertexPropertyKeyValues parameter:

stepsToModify.addAll(TraversalHelper.getStepsOfAssignableClass(AddPropertyStep.class, traversal));
stepsToModify.forEach(s -> {
AddPropertyStep ps = (AddPropertyStep) s;
TraversalHelper.replaceStep(s, new AddPropertyStep(traversal, ps.getCardinality(), ps.getKey(), ps.getValue(), appendToKeyValues(ps.getVertexPropertyKeyValues(), Constants.CREATED, System.currentTimeMillis())), traversal);
});

where appendToKeyValues method will simply add the "created" property and it's value to the vertexPropertyKeyValues collection.

It works when adding properties on vertices g.V(0).property("my key", "my value")  but obviously it fails when adding properties to edges g.V(0).outE("some edge").property("my key", "my value"). That is because if I make use of the vertexPropertyKeyValues, the AddPropertyStep will consider that I'm trying to add vertex properties which doesn't make sense in case of edges.

//pasted from the AddPropertyStep's constructor
this.asVertex = null != cardinality || this.vertexPropertyKeyValues.length > 0;

//pasted from the sideEffect method of the AddPropertyStep class
if (asVertex)
((Vertex) traverser.get()).property(cardinality, key, value, vertexPropertyKeyValues);
else
traverser.get().property(key, value);

To fix it, I think the sideEffect method should do the following:

if (Vertex.class.isAssignableFrom(traverser.get().getClass())){
    ((Vertex) traverser.get()).property(cardinality, key, value, vertexPropertyKeyValues);
else
traverser.get().property(key, value);

The only work around that I could think of was to create a custom AddPropertyStep that applies the above fix. But custom steps are not recommended in TP3, for reasons that are beyond the current topic.

Am I missing something ? Is there any solution to find out whether the AddPropertyStep is applied to a vertex or an edge, at the strategy level ?

Thanks,
Cosmin. 


Stephen Mallette

unread,
Jul 28, 2015, 6:34:41 AM7/28/15
to Gremlin-users
That asVertex thing you pointed out isn't so good:


Trying to get it fixed for 3.0.1.

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/68ee9fac-babb-4656-b7f4-521bd231c5c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages