Skip to content

Commit 3e3ee83

Browse files
authored
Gh-512: Document delete elements operation (#518)
* add docs on delete elements * add version * remove javadoc link
1 parent 1d257e7 commit 3e3ee83

File tree

3 files changed

+1168
-880
lines changed

3 files changed

+1168
-880
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
# Delete Elements Operation
2+
3+
In Gaffer 2.3.0 a DeleteElements operation was added to allow users
4+
to delete specific elements from their graph instance.
5+
6+
!!! warning
7+
Deleting elements is not reversible. Use of this operation should be
8+
limited and users should run test a Operation Chain which extracts any elements
9+
to be deleted prior to running any delete operations.
10+
11+
We will use the following graph to demonstrate how to delete elements from a
12+
Gaffer graph.
13+
14+
```mermaid
15+
graph LR
16+
A(["Person
17+
18+
ID: John"])
19+
--
20+
"Created
21+
weight: 0.2"
22+
-->
23+
B(["Software
24+
25+
ID: 1"])
26+
A
27+
--
28+
"Created
29+
weight: 0.6"
30+
-->
31+
C(["Software
32+
33+
ID: 2"])
34+
```
35+
36+
To delete elements from a graph, users can simply add a `DeleteElements.Builder` to their
37+
Operation Chain. This will take as its input the output of any operations run prior to it.
38+
39+
40+
!!! example ""
41+
If a user gets the edge between John and Software 2 in a query and follows this
42+
up with a delete, then this edge will be removed leaving the three entities and a single edge.
43+
44+
=== "Java"
45+
46+
```java
47+
final OperationChain<Void> deleteElementsChain = new OperationChain.Builder()
48+
.first(new GetElements.Builder()
49+
.input(new EdgeSeed("John", "2", DirectedType.EITHER))
50+
.view(new View.Builder().edge("created").build())
51+
.build())
52+
.then(new DeleteElements())
53+
.build();
54+
55+
graph.execute(deleteElementsChain, new User());
56+
```
57+
58+
=== "JSON"
59+
60+
```json
61+
{
62+
"class" : "OperationChain",
63+
"operations" : [{
64+
"class": "GetElements",
65+
"input": [{
66+
"class": "EdgeSeed",
67+
"source": "John",
68+
"destination": "2",
69+
"directedType": "EITHER"
70+
}],
71+
"view": {
72+
"edges": "created"
73+
}
74+
},
75+
{
76+
"class" : "DeleteElements"
77+
}]
78+
}
79+
```
80+
81+
=== "Python"
82+
83+
```python
84+
g.OperationChain(
85+
operations=[
86+
g.GetElements(
87+
input = [g.EdgeSeed(source="John", destination="2", directedType="Either")]
88+
view = g.ElementDefinition(group = "created")
89+
),
90+
g.DeleteElements()
91+
]
92+
)
93+
```
94+
95+
Results:
96+
```JSON
97+
Entity[vertex="John",group="person"]
98+
Edge[source="John",destination="1",directed=true,matchedVertex=SOURCE,group="created",properties=Properties[weight=<java.lang.Float>0.2]]
99+
Entity[vertex="1",group="software"]
100+
Entity[vertex="2",group="software"]
101+
```
102+
103+
If a user wishes to remove an entity and its associated edges, this is done by
104+
querying for that entity with no filters.
105+
106+
!!! example ""
107+
If a user gets the John entity in a query and follows this up with a delete,
108+
then the John entity is removed and so are the edges for John -created-> 1
109+
and John-created-> 2.
110+
111+
=== "Java"
112+
113+
```java
114+
final OperationChain<Void> deleteElementsChain = new OperationChain.Builder()
115+
.first(new GetElements.Builder()
116+
.input(new EntitySeed("John"))
117+
.build())
118+
.then(new DeleteElements())
119+
.build();
120+
121+
graph.execute(deleteElementsChain, new User());
122+
```
123+
124+
=== "JSON"
125+
126+
```json
127+
{
128+
"class" : "OperationChain",
129+
"operations" : [{
130+
"class": "GetElements",
131+
"input": [{
132+
"class": "EntitySeed",
133+
"vertex": "John"
134+
}]
135+
},
136+
{
137+
"class" : "DeleteElements"
138+
}
139+
]
140+
}
141+
```
142+
143+
=== "Python"
144+
145+
```python
146+
g.OperationChain(
147+
operations=[
148+
g.GetElements(
149+
input = [g.EntitySeed(vertex="John")]
150+
),
151+
g.DeleteElements()
152+
]
153+
)
154+
```
155+
156+
Results:
157+
```JSON
158+
Entity[vertex="1",group="software"]
159+
Entity[vertex="2",group="software"]
160+
```
161+
162+
If a user wishes to remove an entity but leave any associated, this is done by
163+
querying for that entity with a filter.
164+
165+
!!! example ""
166+
If a user gets the John entity in a query but uses a `View` that filters for just entities, then the
167+
delete will leave the associated edges and only delete the John entity.
168+
169+
=== "Java"
170+
171+
```java
172+
final OperationChain<Void> deleteElementsChain = new OperationChain.Builder()
173+
.first(new GetElements.Builder()
174+
.input(new EntitySeed("John"))
175+
.view(new View.Builder().entity("person").build())
176+
.build())
177+
.then(new DeleteElements())
178+
.build();
179+
180+
graph.execute(deleteElementsChain, new User());
181+
```
182+
183+
=== "JSON"
184+
185+
```json
186+
{
187+
"class" : "OperationChain",
188+
"operations" : [{
189+
"class": "GetElements",
190+
"input": [{
191+
"class": "EntitySeed",
192+
"vertex": "John"
193+
}],
194+
"view": {
195+
"entities": "person"
196+
}
197+
},
198+
{
199+
"class" : "DeleteElements"
200+
}
201+
]
202+
}
203+
```
204+
205+
=== "Python"
206+
207+
```python
208+
g.OperationChain(
209+
operations=[
210+
g.GetElements(
211+
input = [g.EdgeSeed(source="John", destination="2", directedType="Either")]
212+
view = g.ElementDefinition(group = "person")
213+
),
214+
g.DeleteElements()
215+
]
216+
)
217+
```
218+
219+
Results:
220+
```JSON
221+
Edge[source="John",destination="1",directed=true,matchedVertex=SOURCE,group="created",properties=Properties[weight=<java.lang.Float>0.2]]
222+
Edge[source="John",destination="2",directed=true,matchedVertex=SOURCE,group="created",properties=Properties[weight=<java.lang.Float>0.6]]
223+
Entity[vertex="1",group="software"]
224+
Entity[vertex="2",group="software"]
225+
```

0 commit comments

Comments
 (0)