Skip to content

Commit 2f31456

Browse files
Clique counting requires undirected
Co-authored-by: Alfred Clemedtson <alfred.clemedtson@neo4j.com>
1 parent 6f42548 commit 2f31456

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

procedures/facade-api/configs/community-configs/src/main/java/org/neo4j/gds/cliquecounting/CliqueCountingBaseConfig.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@
1919
*/
2020
package org.neo4j.gds.cliquecounting;
2121

22+
import org.neo4j.gds.NodeLabel;
23+
import org.neo4j.gds.RelationshipType;
2224
import org.neo4j.gds.annotation.Configuration;
25+
import org.neo4j.gds.api.GraphStore;
2326
import org.neo4j.gds.config.AlgoBaseConfig;
2427

28+
import java.util.Collection;
2529
import java.util.List;
30+
import java.util.Set;
31+
import java.util.stream.Collectors;
32+
33+
import static org.neo4j.gds.utils.StringFormatting.formatWithLocale;
2634

2735
@Configuration
2836
public interface CliqueCountingBaseConfig extends AlgoBaseConfig {
@@ -45,5 +53,21 @@ default CliqueCountingParameters toParameters() {
4553
);
4654
}
4755

56+
@Configuration.GraphStoreValidationCheck
57+
default void validateTargetRelIsUndirected(
58+
GraphStore graphStore,
59+
Collection<NodeLabel> ignored,
60+
Collection<RelationshipType> selectedRelationshipTypes
61+
) {
62+
if (!graphStore.schema().filterRelationshipTypes(Set.copyOf(selectedRelationshipTypes)).isUndirected()) {
63+
throw new IllegalArgumentException(formatWithLocale(
64+
"Clique counting requires relationship projections to be UNDIRECTED. " +
65+
"Selected relationships `%s` are not all undirected.",
66+
selectedRelationshipTypes.stream().map(RelationshipType::name).collect(Collectors.toSet())
67+
));
68+
}
69+
}
70+
71+
4872

4973
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.cliquecounting;
21+
22+
import org.junit.jupiter.api.Test;
23+
import org.neo4j.gds.NodeLabel;
24+
import org.neo4j.gds.RelationshipType;
25+
import org.neo4j.gds.api.GraphStore;
26+
import org.neo4j.gds.extension.GdlExtension;
27+
import org.neo4j.gds.extension.GdlGraph;
28+
import org.neo4j.gds.extension.Inject;
29+
import org.neo4j.gds.kcore.KCoreDecompositionBaseConfig;
30+
31+
import java.util.List;
32+
33+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
34+
import static org.mockito.ArgumentMatchers.any;
35+
import static org.mockito.ArgumentMatchers.anyList;
36+
import static org.mockito.Mockito.doCallRealMethod;
37+
import static org.mockito.Mockito.spy;
38+
39+
@GdlExtension
40+
class CliqueCountingBaseConfigTest {
41+
42+
@GdlGraph
43+
private static final String DB_CYPHER =
44+
"CREATE " +
45+
" (a:node)," +
46+
" (b:node)," +
47+
"(a)-[:R]->(b)";
48+
49+
50+
@Inject
51+
private GraphStore graphStore;
52+
53+
@Test
54+
void shouldThrowForDirected() {
55+
var mockConfig = spy(KCoreDecompositionBaseConfig.class);
56+
57+
doCallRealMethod().when(mockConfig).validateTargetRelIsUndirected(any(), anyList(), anyList());
58+
59+
assertThatThrownBy(() -> mockConfig.validateTargetRelIsUndirected(
60+
graphStore,
61+
List.of(NodeLabel.ALL_NODES),
62+
List.of(RelationshipType.of("R"))
63+
))
64+
.hasMessageContaining("Selected relationships `[R]` are not all undirected");
65+
}
66+
}
67+

0 commit comments

Comments
 (0)