The property does not exist as the key has no associated value for the provided element

1,345 views
Skip to first unread message

Lalith Kiran

unread,
Sep 18, 2018, 12:06:04 PM9/18/18
to Gremlin-users
Guys,

Can someone help me with the following issue,

gremlin> g.V().has("LOCATION", textContains('PRTGMI01')).where(__.in().has('~label','Equip_Vrtx').count().is(0)).emit().repeat(__.bothE().bothV()).times(1).path().unfold().dedup().order().by('MOUNTING_POSITION_NUMBER')
The property does not exist as the key has no associated value for the provided element: v[41582720]:MOUNTING_POSITION_NUMBER
Type ':help' or ':h' for help.
Display stack trace? [yN]N

The property of MOUNTING_POSITION_NUMBER exists in the edges but not the vertices, which is why, when I try sorting the values above query gives me the reported error. I am trying to sort the edges alone but I also need both the vertices and edges in the resultset.

I am really looking forward to a fix on this as I have tried various ways to correct this but am not able to.

Appreciate if someone could assist me by fixing this.

Thanks,
Lalith

Daniel Kuppitz

unread,
Sep 18, 2018, 4:28:48 PM9/18/18
to gremli...@googlegroups.com
If you really want to flatten everythin, then you need to provide a default value for the vertices.

g.V().has("LOCATION", textContains('PRTGMI01')).
  not(__.in().has('~label','Equip_Vrtx')).
  union(identity().
        bothE().union(identity(),
                      otherV())).
  dedup().
  order().
    by(coalesce(values('MOUNTING_POSITION_NUMBER'), constant(0)))

Cheers,
Daniel

--
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/8916b5ee-bc0b-4004-a450-67846f4c0c01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lalith Kiran

unread,
Sep 21, 2018, 10:22:11 AM9/21/18
to Gremlin-users
Daniel,

Thank you for the response. Am getting the below error (highlighted in yellow) when I run the query. Also, the thing is I need the first few pieces of the gremlin query to be retained as this was already being deployed in production system and just needs to be sorted out by retaining the structure of the JSON data which I will get based on it and make use of.

Also, if you could just help me out to sort the edge property on an output of both the vertices and edges, it could be helpful.

Original Query - g.V().has("LOCATION", textContains('PRTGMI01')).where(__.in().has('~label','Equip_Vrtx').count().is(0)).emit().repeat(__.bothE().bothV()).times(1).path().unfold().dedup()

gremlin> g.V().has("LOCATION",textContains('PRTGMI01')).not(__.in().has('~label','Equip_Vrtx')).union(identity().bothE().union(identity(),otherV())).dedup().order().by(coalesce(values('MOUNTING_POSITION_NUMBER'),constant(0)))
java.lang.String cannot be cast to java.lang.Integer
Type ':help' or ':h' for help.
Display stack trace? [yN]y
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
        at java.lang.Integer.compareTo(Integer.java:52)
        at java.util.Comparators$NaturalOrderComparator.compare(Comparators.java:52)
        at java.util.Comparators$NaturalOrderComparator.compare(Comparators.java:47)
        at org.apache.tinkerpop.gremlin.process.traversal.Order$1.compare(Order.java:33)
        at org.apache.tinkerpop.gremlin.util.function.MultiComparator.compare(MultiComparator.java:57)
        at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
        at java.util.TimSort.sort(TimSort.java:234)
        at java.util.Arrays.sort(Arrays.java:1512)
        at java.util.ArrayList.sort(ArrayList.java:1454)
        at java.util.Collections.sort(Collections.java:175)
        at org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSet.sort(TraverserSet.java:150)
        at org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep.barrierConsumer(OrderGlobalStep.java:68)
        at org.apache.tinkerpop.gremlin.process.traversal.step.util.CollectingBarrierStep.processNextStart(CollectingBarrierStep.java:113)
        at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143)
        at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.hasNext(DefaultTraversal.java:192)
        at org.apache.tinkerpop.gremlin.console.Console$_closure3.doCall(Console.groovy:234)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
        at org.codehaus.groovy.tools.shell.Groovysh.setLastResult(Groovysh.groovy:447)
        at org.codehaus.groovy.tools.shell.Groovysh.execute(Groovysh.groovy:191)
        at org.apache.tinkerpop.gremlin.console.GremlinGroovysh.super$3$execute(GremlinGroovysh.groovy)
        at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132)
        at org.apache.tinkerpop.gremlin.console.GremlinGroovysh.execute(GremlinGroovysh.groovy:72)
        at org.codehaus.groovy.tools.shell.Shell.leftShift(Shell.groovy:122)
        at org.codehaus.groovy.tools.shell.ShellRunner.work(ShellRunner.groovy:95)
        at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$work(InteractiveShellRunner.groovy)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:152)
        at org.codehaus.groovy.tools.shell.InteractiveShellRunner.work(InteractiveShellRunner.groovy:124)
        at org.codehaus.groovy.tools.shell.ShellRunner.run(ShellRunner.groovy:59)
        at org.codehaus.groovy.tools.shell.InteractiveShellRunner.super$2$run(InteractiveShellRunner.groovy)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuper0(ScriptBytecodeAdapter.java:152)
        at org.codehaus.groovy.tools.shell.InteractiveShellRunner.run(InteractiveShellRunner.groovy:83)
        at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232)
        at org.apache.tinkerpop.gremlin.console.Console.<init>(Console.groovy:166)
        at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:232)
        at org.apache.tinkerpop.gremlin.console.Console.main(Console.groovy:478)

Thanks,
Lalith

--------------------------------------------------------------------------------------------------------------------------------------------------------

Daniel Kuppitz

unread,
Sep 21, 2018, 10:41:40 AM9/21/18
to gremli...@googlegroups.com
Apparently, your property is of type String and the fallback value is of type Integer. Just make them the same type:

...order().by(coalesce(values('MOUNTING_POSITION_NUMBER'), constant(""))

Cheers,
Daniel


Lalith Kiran

unread,
Oct 2, 2018, 1:23:56 PM10/2/18
to Gremlin-users
Sorry, I was kind of occupied with some work. I have tried that and it appears to be working after some tweaking. Thank you Daniel for the assistance.

Also, I was trying to add another property 'EQUIPMENT_ID' in combination with 'MOUNTING_POSITION_NUMBER' to which am facing difficulties with. Since 'EQUIPMENT_ID' property exists in both vertices and edges, am finding it kind of difficult to get the 'EQUIPMENT_ID' from the edge to sort the output. Can you assist me on this too?

Query - g.V().has("LOCATION", textContains('PRTGMI01')).where(__.in().has('~label','Equip_Vrtx').count().is(0)).emit().repeat(__.bothE().bothV()).times(1).path().unfold().dedup().order().by(coalesce(values('MOUNTING_POSITION_NUMBER'),constant(""))

I need to sort the final output based on the combination of 'EQUIPMENT_ID' as well as 'MOUNTING_POSITION_NUMBER' that exists in the edges. Please assist.

Thanks,
Lalith

Daniel Kuppitz

unread,
Oct 2, 2018, 1:37:20 PM10/2/18
to gremli...@googlegroups.com
order() takes as many by() modulators as you want/need. The result is then ordered by the first by(), then - if 2 values are identical - by the second by() and so on.

Also, note that you really don't need the repeat() step, the full path tracking and the final unfold()'ing.

g.V().has('LOCATION', textContains('PRTGMI01')).
  not(__.in().has('~label','Equip_Vrtx')).
  union(identity(),
        bothE().union(identity(),
                      otherV())).
  dedup().
  order().
    by('EQUIPMENT_ID').
    by(coalesce(values('MOUNTING_POSITION_NUMBER'), constant(""))

Actually, you can get rid of path tracking altogether:

g.V().has('LOCATION', textContains('PRTGMI01')).
  not(__.in().has('~label','Equip_Vrtx')).
  union(identity(),
        outE().union(identity(), inV()),
        inE().union(identity(), outV())).
  dedup().
  order().
    by('EQUIPMENT_ID').
    by(coalesce(values('MOUNTING_POSITION_NUMBER'), constant(""))

Cheers,
Daniel



Lalith Kiran

unread,
Oct 2, 2018, 1:55:06 PM10/2/18
to Gremlin-users
Thank you for the quick reply Daniel.

As I already told you earlier, I have to retain the existing query as it is already being put in production as well as if I make any functional changes in the query, it could change the JSON format entirely which I get from REST API through Gremlin HTTP server.

So I had to retain the existing path query as well as add the added functionality of ordering to it. I have tried the query as you suggested and it seems to be working fine.

g.V().has('LOCATION',textContains('PRTGMI01')).
where(__.in().has('~label','Equip_Vrtx').count().is(0)).emit().
repeat(__.bothE().as('edge').bothV()).times(1).path().unfold().dedup().
order().by('EQUIPMENT_ID').by(coalesce(select('edge').by('MOUNTING_POSITION_NUMBER'),constant(""))).

Thanks again Daniel.

Regards,
Lalith

Daniel Kuppitz

unread,
Oct 2, 2018, 2:04:14 PM10/2/18
to gremli...@googlegroups.com
The format of the result of the query I provided is the same as in your query, it's just the execution that's a lot cheaper - it requires less memory and fewer traversers.

Cheers,
Daniel


Lalith Kiran

unread,
Oct 2, 2018, 2:04:50 PM10/2/18
to Gremlin-users
Daniel,

The below query seems to be ordering both the vertices as well as edges based on the EQUIPMENT_ID available in both the vertices and edges which shouldn't be the case. All am trying to do is to order the output of the path result based on the 'EQUIPMENT_ID' & 'MOUNTING_POSITION_NUMBER' properties that are available in the edges.

g.V().has('LOCATION',textContains('PRTGMI01')).
where(__.in().has('~label','Equip_Vrtx').count().is(0)).emit().
repeat(__.bothE().as('edge').bothV()).times(1).path().unfold().dedup().
order().by('EQUIPMENT_ID').by(coalesce(select('edge').by('MOUNTING_POSITION_NUMBER'),constant("")))

Thanks,
Lalith


On Tuesday, October 2, 2018 at 11:25:06 PM UTC+5:30, Lalith Kiran wrote:
Thank you for the quick reply Daniel.

As I already told you earlier, I have to retain the existing query as it is already being put in production as well as if I make any functional changes in the query, it could change the JSON format entirely which I get from REST API through Gremlin HTTP server.

So I had to retain the existing path query as well as add the added functionality of ordering to it. I have tried the query as you suggested and it seems to be working fine.

g.V().has('LOCATION',textContains('PRTGMI01')).
where(__.in().has('~label','Equip_Vrtx').count().is(0)).emit().
repeat(__.bothE().as('edge').bothV()).times(1).path().unfold().dedup().
order().by('EQUIPMENT_ID').by(coalesce(select('edge').by('MOUNTING_POSITION_NUMBER'),constant("")))

Daniel Kuppitz

unread,
Oct 2, 2018, 2:07:50 PM10/2/18
to gremli...@googlegroups.com
Well, since you want to keep the vertices in your result, what's the order criterion for vertices then?

Cheers,
Daniel


Lalith Kiran

unread,
Oct 2, 2018, 2:13:00 PM10/2/18
to Gremlin-users
The order should be based on the EQUIPMENT_ID and MOUNTING_POSITION_NUMBER properties available in the edges.

Regards,
Lalith

Daniel Kuppitz

unread,
Oct 2, 2018, 2:14:57 PM10/2/18
to gremli...@googlegroups.com
That doesn't really answer my question. The sort order for edges is clear, but what about the vertices? Perhaps provide a small sample graph and the expected result.

Cheers,
Daniel


Lalith Kiran

unread,
Oct 2, 2018, 2:27:20 PM10/2/18
to Gremlin-users
So the thing is, am not going to do any ordering on the vertices but doing the ordering based on the edge properties alone. The vertices will come in the order they are defined in the path and will be ordered based on the edges properties.

Does that answer your question?

Regards,
Lalith

Daniel Kuppitz

unread,
Oct 2, 2018, 2:35:06 PM10/2/18
to gremli...@googlegroups.com
No. When you unfold the paths, you disconnect the vertices from the edges - thus you only have a big list of unrelated elements. Hence, when you order this list, there has to be a criterion for each element. The statement "will come in the order they are defined in the path" kinda makes no sense as your result doesn't contain any paths. Perhaps you actually want to order the paths and then unfold them into a list of elements - but, I don't know... Again, a small sample would be helpful.

Cheers,
Daniel


Reply all
Reply to author
Forward
0 new messages