Lack of symmetry in queries with directed edges? ("Built-in query" issue?)

(Sorry for being a noob tainted with Neo4J thinking…)

This works on a graph with directed edges

SELECT * FROM vendor-(ISA)->descriptor WHERE from_id =="Ford"

I would have expected (with my Neo4J experience) that turning the query around should have worked:

SELECT * FROM descriptor<-(ISA)-vendor WHERE to_id == "manufacturer"
Encountered " "<" "< "" at line 1, column 25.
Was expecting one of:
    <EOF> 
    "limit" ...
    "order" ...
    "where" ...
    "-(" ...

Or I would have expected that leaving out the directionality of the edge should have worked too:

SELECT * FROM descriptor-(ISA)-vendor limit 3
Semantic Check Fails: The edge type ISA is not from descriptor to vendor!

I haven’t tried this out yet, but it seems that maybe if I define ISA without a directionality, then these queries would work (of course, without > or <)?

But I wonder how that would square with an undirected edge that still defines a FROM and TO? (I’ll experiment with this later.)

Or is this another Built-in Query restriction that I’m encountering?

Sorry for my further confusion.

1 Like

So the “>” is just syntactic sugar in V1 queries. For directional edges, you need to explicitly define a reverse edge in your schema, and navigate using that edge type. Or use undirected edges. See here and note the REVERSE_EDGE clause: https://docs.tigergraph.com/dev/gsql-ref/ddl-and-loading/defining-a-graph-schema#create-edge

1 Like

Thanks for the clarification.

If I’m understanding this correctly, Neo4J, the reverse relationship is implicit, whereas in TG, you have to make reverse relationships explicit.

Do you also have to make the reverse relationship explicit for undirected relationships?

I do find the syntactic sugar useful, as it helps reinforce the schema in my mind as I look over code.

The lack of syntactic sugar is why I dislike Gremlin, as there’s an extra cognitive step to translate from and to into directions.

You don’t need to specify for undirected relationships.

Internally it always attaches edges to the source vertex. In a directed edge, an edge-type can only appear in the associated “from” type[s]. In an undirected edge it can appear in both the “from” and the “to” type[s].

1 Like