g.V(id).property(Cardinality, key, arrayValue) bugged?

109 views
Skip to first unread message

Thomas Driessen

unread,
Jun 26, 2020, 9:08:30 AM6/26/20
to Gremlin-users
Hi,

I'm not sure if this is a bug or if I'm using this method incorrectly, so here's what I've done:

When I call

   g.V(someid).property(Cardinality.list, "test", new String[]{"value1", "value2"})

I receive an java.lang.IllegalArgumentException: The provided key/value array length must be a multiple of two

However if I'm doing the same without explicitly stating the Cardinality like this:

   g.V(someId).property("test", new String[]{"value1", "value2"})

the property is added as expected and I also get the array back when I query it.


Is this a bug or am I doing something wrong?

Gremlin version I'm using: 3.4.4

Kind regards,
Thomas

Stephen Mallette

unread,
Jun 26, 2020, 9:44:00 AM6/26/20
to gremli...@googlegroups.com
Your String[] is being interpreted as varargs which become meta-properties:

gremlin> g.addV().property(VertexProperty.Cardinality.list, "test", ["value1", "value2"] as String[])

The provided key/value array length must be a multiple of two
Type ':help' or ':h' for help.
Display stack trace? [yN]n
gremlin> g.addV().property(VertexProperty.Cardinality.list, "test", ["value1", "value2","value3"] as String[])
==>v[0]
gremlin> g.V().properties('test')
==>vp[test->value1]
gremlin> g.V().properties('test').properties()
==>p[value2->value3]


I suppose the question is, are you trying to do multi-properties of two strings "value1" and "value2" or are you doing multi-properties of String[]. If the former then:

gremlin> g.addV().property(VertexProperty.Cardinality.list, "test", "value1").property(VertexProperty.Cardinality.list, "test", "value2")
==>v[0]
gremlin> g.V().properties('test')
==>vp[test->value1]
==>vp[test->value2]


If the latter then I would probably try to store it as a List<String> rather than String[]. 

--
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/2dc61705-6e66-40f2-b70f-5c53c0fa20deo%40googlegroups.com.

Thomas Driessen

unread,
Jun 26, 2020, 10:10:55 AM6/26/20
to Gremlin-users
I was trying the latter ;)

As always: thanks for your quick answer :) 

Kind regards,
Thomas


Am Freitag, 26. Juni 2020 15:44:00 UTC+2 schrieb Stephen Mallette:
Your String[] is being interpreted as varargs which become meta-properties:

gremlin> g.addV().property(VertexProperty.Cardinality.list, "test", ["value1", "value2"] as String[])
The provided key/value array length must be a multiple of two
Type ':help' or ':h' for help.
Display stack trace? [yN]n
gremlin> g.addV().property(VertexProperty.Cardinality.list, "test", ["value1", "value2","value3"] as String[])
==>v[0]
gremlin> g.V().properties('test')
==>vp[test->value1]
gremlin> g.V().properties('test').properties()
==>p[value2->value3]


I suppose the question is, are you trying to do multi-properties of two strings "value1" and "value2" or are you doing multi-properties of String[]. If the former then:

gremlin> g.addV().property(VertexProperty.Cardinality.list, "test", "value1").property(VertexProperty.Cardinality.list, "test", "value2")
==>v[0]
gremlin> g.V().properties('test')
==>vp[test->value1]
==>vp[test->value2]


If the latter then I would probably try to store it as a List<String> rather than String[]. 

On Fri, Jun 26, 2020 at 9:08 AM Thomas Driessen <thomas.d...@gmail.com> wrote:
Hi,

I'm not sure if this is a bug or if I'm using this method incorrectly, so here's what I've done:

When I call

   g.V(someid).property(Cardinality.list, "test", new String[]{"value1", "value2"})

I receive an java.lang.IllegalArgumentException: The provided key/value array length must be a multiple of two

However if I'm doing the same without explicitly stating the Cardinality like this:

   g.V(someId).property("test", new String[]{"value1", "value2"})

the property is added as expected and I also get the array back when I query it.


Is this a bug or am I doing something wrong?

Gremlin version I'm using: 3.4.4

Kind regards,
Thomas

--
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 gremli...@googlegroups.com.

thomas.dr...@gmail.com

unread,
Jun 26, 2020, 11:01:58 AM6/26/20
to Gremlin-users
Uhm maybe a small follow-up question:
If I'm storing list properties by  g.addV().property(VertexProperty.Cardinality.list, "test", "value1").property(VertexProperty.Cardinality.list, "test", "value2")  
Is there then a common pattern on how to retrieve lists back as lists and single values back as single values?
Usually I used g.V(someid).valueMap().by(__.unfold()), but this would unfold also lists and only return the first value.
I also thought of g.V(someId).valueMap().by(__.choose(__.count(Scope.local).is(1), __.unfold(), __.identity()))
but this would turn single valued lists into single values...

Any advice is appreciated :)

Stephen Mallette

unread,
Jun 26, 2020, 1:19:56 PM6/26/20
to gremli...@googlegroups.com
Gremlin doesn't know anything about your schema so you would have to deal with such things manually:

gremlin> g.V().project('name','test').
......1>         by('name').
......2>         by(values('test').fold())
==>[name:thomas,test:[value1,value2]]


We tend to discuss this as a best practice in the sense that we like to see Gremlin that is explicit in terms of the data it returns. In much the same way you don't write SELECT * FROM table in SQL you typically don't want to valueMap() too conveniently. 


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/5b8c6a32-4d0d-4680-b0cc-d884a6fe05c3n%40googlegroups.com.

thomas.dr...@gmail.com

unread,
Jun 29, 2020, 8:17:31 AM6/29/20
to Gremlin-users
Thanks!
Reply all
Reply to author
Forward
0 new messages