How to clear the data in NebulaGraph Space? - nebula-graph

NebulaGraph Database version: 3.0.1
Please advise how to delete the data of nodes and edges in the Nebula Graph space. I deleted the nodes by lookup and pipe symbol, but I want to know how to clear nodes and edges together.

You could DELETE vertex with the WITH EDGE option:
DELETE VERTEX <vid> [, <vid> ...] [WITH EDGE];
for instance:
DELETE VERTEX "player100" WITH EDGE;

Related

Project disconnected vertex with Gremlin/Tinkerpop

I am looking at a kryo file with the following vertices
# Tree Vertices
V(label=tree, properties={treeId:1, treeName:treeA})
V(label=tree, properties={treeId:2, treeName:treeB})
# Root Node Vertices
V(label=node, properties={treeId:1, nodeId:111, nodeType:root})
V(label=node, properties={treeId:2, nodeId:222, nodeType:root})
There are no edges between the vertices labeled as tree and the vertices labeled as node. There are further edges nodes connected to the root nodes but they are irrelevant to this question. I do not want to add any edges as this graph file gets vended to me and I am treating it as read-only.
Now I want to join/project the treeNames into a traversal over the root nodes.
g.V()
.hasLabel('node').has('nodeType', 'root')
.project('nodeId', 'treeId', 'treeName') # return nodeId, treeId, treeName for each root node
.by(values('nodeId'))
.by(values('treeId'))
.by(""" # pseudo-sqlish gremlin to clarify my intent
select treeName
from V().hasLabel('tree')
.where(values('treeid'), eq($thisNode.values('treeId'))
"""
)
In SQL terms I'd say: I want to run a subquery (fully independent sub traversal starting from scratch) and then join it with my outer traversal on a given property. And again: No edge between trees and roots.
WITH
trees as (SELECT treeId, treeName FROM vertices v WHERE v.label = 'tree'),
roots as (SELECT nodeId, treeId FROM vertices v where v.label = 'node')
SELECT roots.nodeId, roots.treeId, trees.treeName
FROM roots
JOIN trees ON (roots.treeId, trees.treeId)
So I am looking for a way to perform a projection based on another traversal + one of the returned vertex properties
How abusive is this?
How to do it?
You can do it by starting a new traversal inside the project like this:
g.V().hasLabel('node').
has('nodeType', 'root').as('root').
project('nodeId', 'treeId', 'treeName').
by(values('nodeId')).
by(values('treeId')).
by(coalesce(
V().hasLabel('tree').where(eq('root')).
by('treeId').
values('treeName'),
constant('tree not exist')
))
see the example here: https://gremlify.com/bybp7s9mdia
How abusive is this: Very.
starting a sub-query for each node vertex can be very 'heavy' performance-wise.
and it's missing all of the advantages of graph DB if your graph schema doesn't fit your requirement

How get both the vertices and edge value in neptune db

I am new to Neptune DB, I have created vertices and connected two vertices with edges and I have given some properties to both the edge and value
I want to retrieve both the edge and vertices properties values
Can someone provide me a sample query for this?
Thanks in advance.
Eg:
Vertices: p1, P2, p3
Edges E1-connecting P1 and P2, E2- connecting P2 and P3
Vertices property: name
Edge property: relation
Now I need to take out name and relation for all the vertices connected to P1
path step is what you are looking for. Using the by modulator you can select properties in a round-robin fashion, i.e. vertex-edge.
Start by locating p1 vertex:
g.V().hasLabel("testV").has("name","p1")
Repeat traversal along edges with "relation" property:
.repeat(outE("testE").has("relation").inV()).until(__.not(outE("testE")))
Get the traversal path (or tree), and select "name" for vertices, and "relation" for edges using the by modulator:
.path().by("name").by("relation")
To see results in arrays of strings:
.local(unfold().fold())
Note that this traversal doesn't handle cycles, but that's another question.
If you need only first level neighbors, you can take a different approach:
g.V().hasLabel("testV").has("name","p2").bothE()
.project("relation","name")
.by(values("relation"))
.by(otherV().values("name"))

Self-loop edges working with OrientDB Graphs

I tried to create a self-loops edge in a OrientDB Graph through Java API.
graph.addEdge("class:hasChild",
graph.getVerticesOfClass(domain).iterator().next(),
graph.getVerticesOfClass(range).iterator().next(),
"hasChild");
From Orient Studio, I saw in SCHEMA that it creates the edge "hasChild" with 0 records.
When I displayed the graph with select from V, I didn't see the edge "hasChild", but it allow me to create it manually.
Why is this happening?
I need to create it by Java API
Try this:
Vertex v1 = graph.getVerticesOfClass(domain).iterator().next();
Vertex v2 = graph.getVerticesOfClass(range).iterator().next();
v1.addEdge("hasChild", v2);

How to get all Graph Nodes in ArangoDB without Start-Node

Like in OrientDB, for get the All Graph Only use 'Select From v'
So far, I have use AQL in ArangoDB with start node:
for v,e,p IN 2 ANY 'user/188802' graph 'a' return p
And now I want to get all graph nodes in ArangoDB without the start node?
Graphs are a grouping of Edge collections. Each Edge collection references _from and _to documents which are stored in Document collections.
The graph traversal queries expect you to have a starting position and it returns the results for that single starting position.
It is possible to identify all possible starting positions, and then run graph traversals over those positions.
You'll need to know the names of the document collections that make up your graph, you can insert them into an AQL query like this:
FOR vertex IN UNION(
(FOR v IN document_collection_1 RETURN v._id),
(FOR v IN document_collection_2 RETURN v._id),
(FOR v IN document_collection_3 RETURN v._id)
)
FOR v, e IN 1..5 OUTBOUND vertex GRAPH 'my_graph_name' OPTIONS { uniqueVertices: true }
RETURN DISTINCT [
{
_from: e._from,
_to: e._to
}
]
Remember that in ArangoDB it is possible for a document collection to be bound to more than one graph, so you'll need to ensure you identify all document collections that are part of the graph.
This query will then extract an array of objects that contain all links defined in the graph. This query focuses only on vertices with edges that are part of the graph. If the vertex has no edge on it, it won't appear in the output as it is not part of the graph.

Add a one to many edge - Tinkerpop (3.0.1)

How can I add an edge from one vertex to many vertices in one call? I know I can call the usual addEdge with a single vertex but I'd like to avoid having to call gremlin server for each edge I need to add as there may be a quite a few.
This works in version 3.2.3 but the V method is not available in version 3.0.1 so looking to replicate it another way.
// Get vertices I want to add edge to
g.V().has("id",within(["2","3","4"])).as("toV").
// Now get the vertex I want to add edge from
V("1").as("fromV").
// And add an edge between them
addE("likes").from("fromV").to("toV")
Here's the docs from TinkerPop 3.0.1 on the addEdge step, and you can find an example there for the syntax that you can use in Titan 1.0. You can test this out in the Gremlin Console.
graph = TitanFactory.open('inmemory'); g = graph.traversal()
g.addV('name', '1').addV('name', '2').addV('name', '3').addV('name', '4')
g.withSideEffect('a', g.V().has('name', within('2', '3', '4')).toList()).
V().has('name', '1').addOutE('likes', 'a')

Resources