Re: Edge traveresal .hasId() not returning expected results

Boxuan Li

Hi Adam,

Thanks for reporting! This is a bug and I just created an issue for it: If you wanted to know more about this bug, feel free to post a follow-up on that issue.

JanusGraphStep is an implementation of TinkerPop GraphStep which contains some optimization. JanusGraph converts GraphStep to JanusGraphStep as long as it finds there is space to optimize. In the “g.E().hasId(xx)” example, if we strictly follow the execution order, JanusGraph would load all edges and then do an in-memory filtering. That’s where `JanusGraphStep` comes into play - it “folds” all `has` conditions (including `hasId` step) so that  index can be potentially utilized. Unfortunately, due to a bug that you found, g.E().hasId(xx) does not work as expected.

If you insert a dummy `map` step in-between like this:

g.E().map{t -> t.get()}.hasId(“4r6-39s-69zp-3c8”)

Then you will get the result you want. However, this is highly discouraged, as it will aggressively prevent JanusGraph from doing any optimization, and requires a full scan on all data entries.

Best regards,

On Nov 5, 2021, at 2:01 PM, Adam Crane via <> wrote:

Hey folks, I'm seeing strange results trying to use the hasId step on an edge traversal:

@ g.E("4r6-39s-69zp-3c8").toList 
res49: List[Edge] = List(e[4r6-39s-69zp-3c8][4240-RetrocomputerPurchaser->4328])

@ g.E().hasId("4r6-39s-69zp-3c8").toList 
res50: List[Edge] = List()

@ g.E("4r6-39s-69zp-3c8").traversal.profile().toList 
res51: java.util.List[org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics] = [Traversal Metrics
Step                                                               Count  Traversers       Time (ms)    % Dur
GraphStep(edge,[4r6-39s-69zp-3c8])                                     1           1           0.237   100.00
                                            >TOTAL                     -           -           0.237        -]

@ g.E().hasId("4r6-39s-69zp-3c8").traversal.profile().toList 
res52: java.util.List[org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics] = [Traversal Metrics
Step                                                               Count  Traversers       Time (ms)    % Dur
JanusGraphStep(edge,[4r6-39s-69zp-3c8])                                                        0.039   100.00
                                            >TOTAL                     -           -           0.039        -]

1) Why would these two traversals produce different results?
2) What's the difference between the GraphStep and JanusGraphStep representations of these traversals? They look the same otherwise via explain/profile.
3) Is there any working encoding of this query starting with an edge traversal g.E() that can produce the same result?

- Adam

Join to automatically receive all group messages.