Setting null values

200 views
Skip to first unread message

Philip Graff

unread,
Nov 19, 2018, 10:05:27 AM11/19/18
to Gremlin-users
Hi all,

I've noticed that if I try to set a property value as null, I get different behavior depending on when I do it. If I do it following an addV() step - i.e. when I create the Vertex, in this case - then the property is just not set and no error is thrown. However, if I do it on an existing Element, then I get an IllegalStateException from the AddPropertyStep. In the latter case, any properties I set before the one with the null value are actually set, but any after are not. In the former case, all properties without a null value are set. See the example below.

gremlin> graph = TinkerFactory.createModern()

==>tinkergraph[vertices:6 edges:6]

gremlin> g = graph.traversal()

==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]

gremlin> g.V(1).property("x", 1).property("y", null).property("z", 2)

The AddPropertyStep does not have a provided value: AddPropertyStep({key=[y]})

Type ':help' or ':h' for help.

Display stack trace? [yN]N

gremlin> g.V(1).properties()

==>vp[name->marko]

==>vp[x->1]

==>vp[age->29]

gremlin> g.addV("test").property("x", 1).property("y", null).property("z", 2)

==>v[13]

gremlin> g.V(13).properties()

==>vp[x->1]

==>vp[z->2]

gremlin>


I wouldn't expect this to be the desired behavior. Shouldn't setting a property on a new Vertex also throw the IllegalStateException? The fact that it quietly moves on means that I don't know if my property is set or not in a general sense.

Thanks,
Phil 

Thanos Giannakis

unread,
Nov 24, 2018, 6:43:30 AM11/24/18
to Gremlin-users
Hi Phlip,
I have noticed the same issue. Adding a vertex with a null property works, it just ignores the property in the travelsal, but trying to update a property value with null will throw an exception.

I think the desired solution would be, if a property is updated with null, then remove the property. Else you need to detect this in application level and handle it. 

Thanos

Stephen Mallette

unread,
Nov 26, 2018, 6:48:43 AM11/26/18
to gremli...@googlegroups.com
That's an interesting inconsistency. I guess it has to do with property() being treated as a modulator to addV() and then the AddVertexStep having a different flow of processing than AddPropertyStep.

> I think the desired solution would be, if a property is updated with null, then remove the property. Else you need to detect this in application level and handle it. 

That could be a way to resolve it but I think that rather than institute a major change in behavior we should just have AddVertexStep have similar functionality to AddVertexStep (or the other way around) and keep property removal explicit to drop(). Created an issue:


--
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/2dce4aca-d725-4598-9522-7069cab95597%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages