Giter Club home page Giter Club logo

Comments (2)

dongma avatar dongma commented on June 15, 2024 1

To write an AQL statement that mirrors the functionality of g.inE("tech").otherV().has('name', 'lily').inE('friends').otherV(), you'll need to use a combination of graph traversal operations and filtering in ArangoDB. This Gremlin-like query essentially performs the following steps:

  1. Traverse inbound edges labeled "tech" to find vertices.
  2. From those vertices, filter vertices with a name attribute equal to "lily".
  3. Traverse inbound edges labeled "friends" from those filtered vertices.
  4. Return the vertices connected by the "friends" edges.

The equivalent operation in AQL, assuming you have a named graph, might look something like this:

FOR v, e, p IN 1..2 ANY 'vertices/lily' GRAPH 'yourGraphName'
  FILTER p.edges[0].label == 'tech' AND v.name == 'lily' AND p.edges[1].label == 'friends'
  RETURN DISTINCT v

This query does the following in AQL:

  • Starts the traversal with ANY 'vertices/lily' assuming lily is a vertex in your graph. Replace 'vertices/lily' with the actual vertex ID of lily.
  • Uses 1..2 to specify the depth of the traversal, which here means starting from the vertices connected by "tech" edges and moving to their "friends" connected vertices.
  • Filters the paths (p) to ensure that the first set of edges (p.edges[0]) has the label 'tech', the vertex has a name 'lily', and the second set of edges (p.edges[1]) has the label 'friends'.
  • Returns distinct vertices (v) found following these criteria.

Keep in mind that in ArangoDB, edges don't have labels like in some other graph databases or Gremlin syntax. Instead, they are typically represented by edge collections or by specific attributes within edge documents. So, you'll need to adjust the conditions (p.edges[0].label == 'tech' and p.edges[1].label == 'friends') based on your actual edge schema—label should be replaced with the actual attribute name that you use to differentiate edge types.

Also, this example assumes lily is directly connected to both "tech" and "friends" edges as per the Gremlin-like query instructions. You should adjust the vertex identifier and graph name ('yourGraphName') to suit your specific dataset.

from arangodb.

dongma avatar dongma commented on June 15, 2024

When the statement has different direction,such as "g.inE("tech").otherV().inE('friends').otherV()",below is the equivalent AQL:

To achieve a traversal in ArangoDB AQL that is functionally equivalent to the Gremlin query g.inE("tech").otherV().outE('friends').otherV(), you need to use ArangoDB's graph traversal capabilities. The Gremlin query essentially traverses from a set of vertices through incoming edges labeled "tech", to their opposing vertices, and then through outgoing edges labeled "friends" to their destination vertices.

A similar traversal can be expressed in AQL using the GRAPH_TRAVERSAL() or the specific FOR ... IN ... graph traversal syntax. Since ArangoDB uses named graphs and does not directly operate on edge types in the traversal syntax, you need to specify the direction of the traversal and the collections (edge and vertex collections) involved. Assuming you have a named graph and the edge collections are named accordingly to represent "tech" and "friends" relationships, here's how you could construct the query:

FOR techVertex IN 1..1 INBOUND @startVertex tech
  FOR friendVertex IN 1..1 OUTBOUND techVertex._id friends
    RETURN friendVertex

In this example:

  • Replace @startVertex with the ID of the vertex you want to start the traversal from.
  • The traversal starts by finding vertices (techVertex) that are connected through the tech edge collection in an inbound direction relative to the @startVertex.
  • From each techVertex, the query then finds vertices (friendVertex) connected through the friends edge collection in an outbound direction.
  • The result (friendVertex) is returned.

Please adjust the edge collection names (tech and friends) according to your graph's schema. If you're working with a named graph, you may instead use the GRAPH keyword followed by the graph's name to specify traversals.

Keep in mind that the performance and efficiency of the query can be affected by the graph's structure, the number of vertices and edges, and the indexing of the edge collections. This AQL example assumes a simplistic relationship structure for demonstration purposes.

from arangodb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.