File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
main/java/org/neo4j/gds/beta/undirected
test/java/org/neo4j/gds/beta/undirected Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 2121
2222import org .neo4j .gds .MutateComputationResultConsumer ;
2323import org .neo4j .gds .RelationshipType ;
24+ import org .neo4j .gds .api .schema .Direction ;
2425import org .neo4j .gds .config .ElementTypeValidator ;
2526import org .neo4j .gds .core .loading .SingleTypeRelationshipImportResult ;
2627import org .neo4j .gds .executor .AlgorithmSpec ;
3637import org .neo4j .gds .results .StandardMutateResult ;
3738
3839import java .util .List ;
40+ import java .util .Locale ;
3941import java .util .Map ;
4042import java .util .stream .Stream ;
4143
@@ -93,6 +95,21 @@ public List<AfterLoadValidation<ToUndirectedConfig>> afterLoadValidations() {
9395 (graphStore , graphProjectConfig , config ) -> {
9496 var relationshipType = RelationshipType .of (config .relationshipType ());
9597 ElementTypeValidator .validateTypes (graphStore , List .of (relationshipType ), "`relationshipType`" );
98+ },
99+ (graphStore , graphProjectConfig , config ) -> {
100+ var relationshipType = RelationshipType .of (config .relationshipType ());
101+ Direction direction = graphStore
102+ .schema ()
103+ .relationshipSchema ()
104+ .get (relationshipType )
105+ .direction ();
106+ if (direction == Direction .UNDIRECTED ) {
107+ throw new UnsupportedOperationException (String .format (
108+ Locale .US ,
109+ "The specified relationship type `%s` is already undirected." ,
110+ relationshipType .name
111+ ));
112+ }
96113 }
97114 );
98115 }
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ class ToUndirectedProcTest extends BaseProcTest {
4646
4747 @ Neo4jGraph
4848 public static final String DB = "CREATE " +
49- "(a:A) " +
49+ " (a:A) " +
5050 ",(b:B) " +
5151 ",(c:C) " +
5252 ",(a)-[:REL {prop1: 1.0}]->(b)" +
@@ -66,6 +66,16 @@ void setup() throws Exception {
6666 .withRelationshipProperty ("prop1" )
6767 .yields ()
6868 );
69+
70+ runQuery (GdsCypher .call ("undirected_graph" )
71+ .graphProject ()
72+ .withNodeLabel ("A" )
73+ .withNodeLabel ("B" )
74+ .withNodeLabel ("C" )
75+ .withRelationshipType ("REL" , Orientation .UNDIRECTED )
76+ .withRelationshipProperty ("prop1" )
77+ .yields ()
78+ );
6979 }
7080
7181 @ Test
@@ -113,6 +123,15 @@ void shouldFailIfRelationshipTypeDoesNotExists() {
113123 assertEquals (expectedMessage , throwable .getMessage ());
114124 }
115125
126+ @ Test
127+ void shouldFailIfRelationshipTypeIsAlreadyUndirected () {
128+ String query = "CALL gds.beta.graph.relationships.toUndirected('undirected_graph', {relationshipType: 'REL', mutateRelationshipType: 'REL2'})" ;
129+
130+ Throwable throwable = rootCause (assertThrows (QueryExecutionException .class , () -> runQuery (query )));
131+ assertEquals (UnsupportedOperationException .class , throwable .getClass ());
132+ assertEquals ("The specified relationship type `REL` is already undirected." , throwable .getMessage ());
133+ }
134+
116135 @ Test
117136 void memoryEstimation () {
118137 String query = "CALL gds.beta.graph.relationships.toUndirected.estimate('graph', {relationshipType: 'REL', mutateRelationshipType: 'REL2'})" ;
You can’t perform that action at this time.
0 commit comments