Skip to content

Commit 2f5e978

Browse files
Mats-SXFlorentinD
andcommitted
Return proper DeletionResult when deleting non-exisitng relationship types
Co-authored-by: Florentin Dörre <florentin.dorre@neotechnology.com>
1 parent 4346eda commit 2f5e978

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

core/src/main/java/org/neo4j/gds/core/loading/CSRGraphStore.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,7 @@ public DeletionResult deleteRelationships(RelationshipType relationshipType) {
448448
return DeletionResult.of(builder ->
449449
updateGraphStore(graphStore -> {
450450
var removedTopology = graphStore.relationships.remove(relationshipType);
451-
if (removedTopology != null) {
452-
builder.deletedRelationships(removedTopology.elementCount());
453-
}
451+
builder.deletedRelationships(removedTopology == null ? 0 : removedTopology.elementCount());
454452

455453
var removedProperties = graphStore.relationshipProperties.remove(relationshipType);
456454

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.core.loading;
21+
22+
import org.junit.jupiter.api.Test;
23+
import org.neo4j.gds.RelationshipType;
24+
import org.neo4j.gds.gdl.GdlFactory;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
class CSRGraphStoreTest {
29+
30+
@Test
31+
void deleteAdditionalRelationshipTypes() {
32+
GdlFactory factory = GdlFactory.of("(b)-[:REL {x: 1}]->(a), (b)-[:REL]->(c)");
33+
var graphStore = factory.build();
34+
35+
var del1 = graphStore.deleteRelationships(RelationshipType.of("REL"));
36+
37+
assertThat(del1.deletedRelationships()).isEqualTo(2);
38+
assertThat(del1.deletedProperties()).containsEntry("x", 2L).hasSize(1);
39+
40+
var del2 = graphStore.deleteRelationships(RelationshipType.of("REL"));
41+
42+
assertThat(del2.deletedRelationships()).isEqualTo(0);
43+
assertThat(del2.deletedProperties()).isEmpty();
44+
}
45+
46+
}

0 commit comments

Comments
 (0)