Glide
Glide

Reputation: 21245

Why does Gremlin Query select/by errors out whereas querying by properties() returns fine?

For the queries below against the Tinkerpop's toy graph (graph = TinkerFactory.createModern()), why does the first query returns fine (with the expected no results) but the second query errors out?

Query 1:

g.V().hasLabel("person").has("name", "marko").properties("foo")

Query 2:

    gremlin> g.V().hasLabel("person").has("name", "marko").as("p").select("p").by("foo")
    org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep 
cannot be cast to org.apache.tinkerpop.gremlin.process.traversal.step.ByModulating

EDIT: Updated by to as - did not paste my original query correctly.

Upvotes: 0

Views: 813

Answers (1)

bechbd
bechbd

Reputation: 6341

First, there is an error in Query 2 it should be g.V().hasLabel("person").has("name", "marko").as("p").select("p").by("foo")

Even with that the query will return an error becasue the vertex 'p' does not have a property 'foo'. The reason this throws an error is that the by step is not an actual step in Gremlin it is a modulator on another step, in this case the select("p") step. In Query 2 you are trying to modulate an element (v1 in the modernGraph) by a non-existant property which results in an error.

In contrast Query 1 is trying to retrieve a property 'foo' from a map which is what the properties step returns. In groovy (the underlying language of Gremlin) when you try to pull a non-existent property from a map a null is returned.

Gremlin By Step

Gremlin Properties Step

Upvotes: 2

Related Questions