Finding a place to call home

51 views
Skip to first unread message

Jeff Bonevich

unread,
Feb 16, 2022, 5:17:59 PM2/16/22
to ArangoDB
I am not totally new to graph databases (Neo4J about a decade ago) nor graph problems, but it's been a while, so forgive my ArangoDB noobie perspective.
I am trying to figure out how to determine what a place would have been called in the past.  Save I have a place called "G" in the following graph:
Untitled (1).jpg
In this graph, places are linked by edges that tell you when the place was founded from another place (so, G was founded in 600 from F).  I want to query what G was called in a given year: if I ask for the name of the place currently called 'G' in the year 450, the answer ought to be 'D' (because not only was G founded from F in 600, but F was founded from D in 500, while D was founded in 300).  I think I need to include a "root" node for path traversals to come back in a consistent form (ie always include place 'A' if the date is before 100).

I have been trying out AQL to answer the question, with some success, but am not sure this is the Right Way (tm) to go about it, so any pointers would be helpful.

FOR p IN places
    FILTER p.display_name == @name
    LET path = (
        FOR v, e IN 0..10 OUTBOUND p places_established_from
            PRUNE e != null AND e.established < @date
            RETURN v
    )
    RETURN path[-2]

It seems to do the trick but does not feel so natural nor efficient?

jeff

Kerry Hormann

unread,
May 17, 2022, 3:01:35 PM5/17/22
to ArangoDB
It looks like your PRUNE statement should do the job, but you need the last element, so wouldn't LAST() work (instead of calling a specific )?

    RETURN LAST(path)

Alternately, this might not work out, but if you have an attribute to SORT on (maybe e.established ASC, so you're desired hit is first), you could skip the LET PATH = (..) and just RETURN v
Reply all
Reply to author
Forward
0 new messages