Comments (2)
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:
- Traverse inbound edges labeled
"tech"
to find vertices. - From those vertices, filter vertices with a
name
attribute equal to"lily"
. - Traverse inbound edges labeled
"friends"
from those filtered vertices. - 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'
assuminglily
is a vertex in your graph. Replace'vertices/lily'
with the actual vertex ID oflily
. - 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.
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 thetech
edge collection in an inbound direction relative to the@startVertex
. - From each
techVertex
, the query then finds vertices (friendVertex
) connected through thefriends
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)
- GCC 13.2.0 build devel error HOT 2
- Vulnerability runc CVE-2024-21626 in ArangoDB HOT 1
- Cluster RemoteNode slowdowns query by 50 times comparing to single instance HOT 3
- An integer field cannot be incremented HOT 2
- FATAL [c81f6] {general} failed to bind to endpoint 'http+tcp://[::]:8529'. Please check whether another instance is already running using this endpoint and review your endpoints configuration. HOT 1
- Guix package HOT 1
- After updating to version 3.11.7 of Arango BD, the service is constantly restarting HOT 2
- Graph traversal with cluster from list nodes very slow HOT 1
- GEO_CONTAINS produces false results (inconsistent right-hand rule) HOT 2
- Execution time inconsistent with the use of an index with sorting
- What next after Pregel removal?
- User with no access to _system can get/set server license HOT 1
- Follower getting 503 Error HOT 1
- Index not used if attribute has space in the name HOT 5
- Arangobench unreliable behavior HOT 2
- Using a different character to "/" in node ids. HOT 3
- Please make Docker image of v3.12.0 available HOT 2
- GPG key expired on 03/23/2024 HOT 6
- [Optimize graph traversal] How to skip startVertexs that exist in the previous graph traversal results. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arangodb.