Skip to content

Commit 1f58ce9

Browse files
authored
Merge pull request #9243 from s1ck/align-type-signature-export-functions
Support reltype as String or List in stream procs
2 parents 3e211c8 + b875edc commit 1f58ce9

File tree

11 files changed

+93
-21
lines changed

11 files changed

+93
-21
lines changed

applications/graph-store-catalog/src/main/java/org/neo4j/gds/applications/graphstorecatalog/CatalogBusinessFacade.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ <T> Stream<T> streamRelationshipProperties(
189189
UserLogRegistryFactory userLogRegistryFactory,
190190
String graphName,
191191
List<String> relationshipProperties,
192-
List<String> relationshipTypes,
192+
Object relationshipTypes,
193193
Map<String, Object> configuration,
194194
boolean usesPropertyNameColumn,
195195
GraphStreamRelationshipPropertyOrPropertiesResultProducer<T> outputMarshaller
@@ -199,7 +199,7 @@ Stream<TopologyResult> streamRelationships(
199199
User user,
200200
DatabaseId databaseId,
201201
String graphName,
202-
List<String> relationshipTypes,
202+
Object relationshipTypes,
203203
Map<String, Object> configuration
204204
);
205205

applications/graph-store-catalog/src/main/java/org/neo4j/gds/applications/graphstorecatalog/CatalogConfigurationService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ GraphStreamNodePropertiesConfig parseGraphStreamNodePropertiesConfiguration(
245245
GraphStreamRelationshipPropertiesConfig parseGraphStreamRelationshipPropertiesConfiguration(
246246
GraphName graphName,
247247
List<String> relationshipProperties,
248-
List<String> relationshipTypes,
248+
Object relationshipTypes,
249249
Map<String, Object> rawConfiguration
250250
) {
251251
var cypherConfig = CypherMapWrapper.create(rawConfiguration);
@@ -264,7 +264,7 @@ GraphStreamRelationshipPropertiesConfig parseGraphStreamRelationshipPropertiesCo
264264

265265
GraphStreamRelationshipsConfig parseGraphStreamRelationshipsConfiguration(
266266
GraphName graphName,
267-
List<String> relationshipTypes,
267+
Object relationshipTypes,
268268
Map<String, Object> rawConfiguration
269269
) {
270270
var cypherConfig = CypherMapWrapper.create(rawConfiguration);

applications/graph-store-catalog/src/main/java/org/neo4j/gds/applications/graphstorecatalog/DefaultCatalogBusinessFacade.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ public <T> Stream<T> streamRelationshipProperties(
674674
UserLogRegistryFactory userLogRegistryFactory,
675675
String graphNameAsString,
676676
List<String> relationshipProperties,
677-
List<String> relationshipTypes,
677+
Object relationshipTypes,
678678
Map<String, Object> rawConfiguration,
679679
boolean usesPropertyNameColumn,
680680
GraphStreamRelationshipPropertyOrPropertiesResultProducer<T> outputMarshaller
@@ -707,7 +707,7 @@ public Stream<TopologyResult> streamRelationships(
707707
User user,
708708
DatabaseId databaseId,
709709
String graphNameAsString,
710-
List<String> relationshipTypes,
710+
Object relationshipTypes,
711711
Map<String, Object> rawConfiguration
712712
) {
713713
var graphName = graphNameValidationService.validate(graphNameAsString);

applications/graph-store-catalog/src/main/java/org/neo4j/gds/applications/graphstorecatalog/GraphStreamRelationshipPropertiesConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ default Collection<RelationshipType> validRelationshipTypes(GraphStore graphStor
8888
static GraphStreamRelationshipPropertiesConfig of(
8989
String graphName,
9090
List<String> relationshipProperties,
91-
List<String> relationshipTypes,
91+
Object relationshipTypes,
9292
CypherMapWrapper config
9393
) {
9494
return new GraphStreamRelationshipPropertiesConfigImpl(

applications/graph-store-catalog/src/main/java/org/neo4j/gds/applications/graphstorecatalog/GraphStreamRelationshipsConfig.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.neo4j.gds.api.GraphStore;
2626
import org.neo4j.gds.config.BaseConfig;
2727
import org.neo4j.gds.config.ConcurrencyConfig;
28+
import org.neo4j.gds.config.UserInputAsStringOrListOfString;
2829
import org.neo4j.gds.core.CypherMapWrapper;
2930

3031
import java.util.ArrayList;
@@ -43,10 +44,14 @@ public interface GraphStreamRelationshipsConfig extends BaseConfig, ConcurrencyC
4344
Optional<String> graphName();
4445

4546
@Configuration.Parameter
47+
@Configuration.ConvertWith(method = "org.neo4j.gds.applications.graphstorecatalog.GraphStreamRelationshipsConfig#parseRelationshipTypes")
4648
default List<String> relationshipTypes() {
4749
return Collections.singletonList(ElementProjection.PROJECT_ALL);
4850
}
4951

52+
static List<String> parseRelationshipTypes(Object userInput) {
53+
return UserInputAsStringOrListOfString.parse(userInput, "relationshipTypes");
54+
}
5055
@Configuration.Ignore
5156
default Collection<RelationshipType> relationshipTypeIdentifiers(GraphStore graphStore) {
5257
return relationshipTypes().contains(ElementProjection.PROJECT_ALL)
@@ -73,7 +78,7 @@ default void validate(GraphStore graphStore) {
7378

7479
static GraphStreamRelationshipsConfig of(
7580
String graphName,
76-
List<String> relationshipTypes,
81+
Object relationshipTypes,
7782
CypherMapWrapper config
7883
) {
7984
return new GraphStreamRelationshipsConfigImpl(

doc/modules/ROOT/pages/management-ops/graph-reads/graph-stream-relationships.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This is useful if we ran multiple algorithms in `mutate` mode and want to retrie
1717
----
1818
CALL gds.graph.relationships.stream(
1919
graphName: String,
20-
relationshipTypes: List of Strings,
20+
relationshipTypes: String or List of Strings,
2121
configuration: Map
2222
)
2323
YIELD
@@ -31,7 +31,7 @@ YIELD
3131
|===
3232
| Name | Type | Optional | Description
3333
| graphName | String | no | The name under which the graph is stored in the catalog.
34-
| relationshipTypes | List of Strings | yes | The relationship types to stream the relationship properties for graph.
34+
| relationshipTypes | String or List of Strings | yes | The relationship types to stream the relationship properties for graph.
3535
| configuration | Map | yes | Additional parameters to configure streamNodeProperties.
3636
|===
3737

@@ -59,7 +59,7 @@ YIELD
5959
CALL gds.graph.relationshipProperty.stream(
6060
graphName: String,
6161
relationshipProperty: String,
62-
relationshipTypes: List of Strings,
62+
relationshipTypes: String or List of Strings,
6363
configuration: Map
6464
)
6565
YIELD
@@ -75,7 +75,7 @@ YIELD
7575
| Name | Type | Optional | Description
7676
| graphName | String | no | The name under which the graph is stored in the catalog.
7777
| relationshipProperty | String | no | The relationship property in the graph to stream.
78-
| relationshipTypes | List of Strings | yes | The relationship types to stream the relationship properties for graph.
78+
| relationshipTypes | String or List of Strings | yes | The relationship types to stream the relationship properties for graph.
7979
| configuration | Map | yes | Additional parameters to configure streamNodeProperties.
8080
|===
8181

@@ -108,7 +108,7 @@ a|
108108
CALL gds.graph.relationshipProperties.stream(
109109
graphName: String,
110110
relationshipProperties: List of String,
111-
relationshipTypes: List of Strings,
111+
relationshipTypes: String or List of Strings,
112112
configuration: Map
113113
)
114114
YIELD
@@ -125,7 +125,7 @@ YIELD
125125
| Name | Type | Optional | Description
126126
| graphName | String | no | The name under which the graph is stored in the catalog.
127127
| relationshipProperties | List of String | no | The relationship properties in the graph to stream.
128-
| relationshipTypes | List of Strings | yes | The relationship types to stream the relationship properties for graph.
128+
| relationshipTypes | String or List of Strings | yes | The relationship types to stream the relationship properties for graph.
129129
| configuration | Map | yes | Additional parameters to configure streamNodeProperties.
130130
|===
131131

proc/catalog/src/main/java/org/neo4j/gds/catalog/GraphStreamRelationshipPropertiesProc.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class GraphStreamRelationshipPropertiesProc {
4646
public Stream<GraphStreamRelationshipPropertiesResult> streamRelationshipProperties(
4747
@Name(value = "graphName") String graphName,
4848
@Name(value = "relationshipProperties") List<String> relationshipProperties,
49-
@Name(value = "relationshipTypes", defaultValue = "['*']") List<String> relationshipTypes,
49+
@Name(value = "relationshipTypes", defaultValue = "['*']") Object relationshipTypes,
5050
@Name(value = "configuration", defaultValue = "{}") Map<String, Object> configuration
5151
) {
5252
return facade.catalog().streamRelationshipProperties(
@@ -85,7 +85,7 @@ public Stream<GraphStreamRelationshipPropertiesResult> deprecatedStreamRelations
8585
public Stream<GraphStreamRelationshipPropertyResult> streamRelationshipProperty(
8686
@Name(value = "graphName") String graphName,
8787
@Name(value = "relationshipProperty") String relationshipProperty,
88-
@Name(value = "relationshipTypes", defaultValue = "['*']") List<String> relationshipTypes,
88+
@Name(value = "relationshipTypes", defaultValue = "['*']") Object relationshipTypes,
8989
@Name(value = "configuration", defaultValue = "{}") Map<String, Object> configuration
9090
) {
9191
return facade.catalog().streamRelationshipProperty(

proc/catalog/src/main/java/org/neo4j/gds/catalog/GraphStreamRelationshipsProc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class GraphStreamRelationshipsProc {
4242
@Description(STREAM_RELATIONSHIPS_DESCRIPTION)
4343
public Stream<TopologyResult> streamRelationships(
4444
@Name(value = "graphName") String graphName,
45-
@Name(value = "relationshipTypes", defaultValue = "['*']") List<String> relationshipTypes,
45+
@Name(value = "relationshipTypes", defaultValue = "['*']") Object relationshipTypes,
4646
@Name(value = "configuration", defaultValue = "{}") Map<String, Object> configuration
4747
) {
4848
return facade.catalog().streamRelationships(graphName, relationshipTypes, configuration);

proc/catalog/src/test/java/org/neo4j/gds/catalog/GraphStreamRelationshipPropertiesProcTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,50 @@ void streamLoadedRelationshipProperties(String graphStreamQueryTemplate) {
138138
));
139139
}
140140

141+
@ParameterizedTest
142+
@ValueSource(strings = {"'REL1'", "['REL1']"})
143+
void streamRelationshipPropertyForTypesAsStringOrList(String stringOrList) {
144+
var query = formatWithLocale("""
145+
CALL gds.graph.relationshipProperty.stream(
146+
'%s',
147+
'relProp1',
148+
%s
149+
)
150+
YIELD sourceNodeId, targetNodeId, relationshipType, propertyValue
151+
RETURN sourceNodeId AS source, targetNodeId AS target, relationshipType, propertyValue
152+
""",
153+
TEST_GRAPH_SAME_PROPERTIES, stringOrList
154+
);
155+
156+
assertCypherResult(query, List.of(
157+
Map.of("source", nodeA, "target", nodeA, "relationshipType", "REL1", "propertyValue", 0D),
158+
Map.of("source", nodeB, "target", nodeB, "relationshipType", "REL1", "propertyValue", 1D)
159+
));
160+
}
161+
162+
@ParameterizedTest
163+
@ValueSource(strings = {"'REL1'", "['REL1']"})
164+
void streamRelationshipPropertiesForTypesAsStringOrList(String stringOrList) {
165+
var query = formatWithLocale("""
166+
CALL gds.graph.relationshipProperties.stream(
167+
'%s',
168+
['relProp1', 'relProp2'],
169+
%s
170+
)
171+
YIELD sourceNodeId, targetNodeId, relationshipType, relationshipProperty, propertyValue
172+
RETURN sourceNodeId AS source, targetNodeId AS target, relationshipType, relationshipProperty, propertyValue
173+
""",
174+
TEST_GRAPH_SAME_PROPERTIES, stringOrList
175+
);
176+
177+
assertCypherResult(query, List.of(
178+
Map.of("source", nodeA, "target", nodeA, "relationshipType", "REL1", "relationshipProperty", "relProp1", "propertyValue", 0D),
179+
Map.of("source", nodeA, "target", nodeA, "relationshipType", "REL1", "relationshipProperty", "relProp2", "propertyValue", 42D),
180+
Map.of("source", nodeB, "target", nodeB, "relationshipType", "REL1", "relationshipProperty", "relProp1", "propertyValue", 1D),
181+
Map.of("source", nodeB, "target", nodeB, "relationshipType", "REL1", "relationshipProperty", "relProp2", "propertyValue", 43D)
182+
));
183+
}
184+
141185
@Test
142186
void streamLoadedRelationshipPropertiesForType() {
143187
String graphStreamQuery = formatWithLocale(

proc/catalog/src/test/java/org/neo4j/gds/catalog/GraphStreamRelationshipsProcTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.junit.jupiter.params.ParameterizedTest;
2626
import org.junit.jupiter.params.provider.Arguments;
2727
import org.junit.jupiter.params.provider.MethodSource;
28+
import org.junit.jupiter.params.provider.ValueSource;
2829
import org.neo4j.gds.BaseProcTest;
2930
import org.neo4j.gds.GdsCypher;
3031
import org.neo4j.gds.api.DatabaseId;
@@ -40,6 +41,7 @@
4041
import java.util.stream.Stream;
4142

4243
import static org.assertj.core.api.Assertions.assertThat;
44+
import static org.neo4j.gds.utils.StringFormatting.formatWithLocale;
4345

4446
class GraphStreamRelationshipsProcTest extends BaseProcTest {
4547
@SuppressWarnings("unused")
@@ -89,6 +91,27 @@ void shouldStreamAllRelationships() {
8991
);
9092
}
9193

94+
@ParameterizedTest
95+
@ValueSource(strings = {"'REL1'", "['REL1']"})
96+
void streamRelationshipsForTypesAsStringOrList(String relationshipTypes) {
97+
var actualRelationships = new ArrayList<TopologyResult>();
98+
99+
runQueryWithRowConsumer(formatWithLocale("CALL gds.graph.relationships.stream('graph', %s)", relationshipTypes), row -> actualRelationships.add(
100+
relationship(
101+
row.getNumber("sourceNodeId").longValue(),
102+
row.getNumber("targetNodeId").longValue(),
103+
row.getString("relationshipType")
104+
)
105+
));
106+
107+
assertThat(actualRelationships).containsExactlyInAnyOrderElementsOf(
108+
List.of(
109+
relationship(idFunction.of("a"), idFunction.of("b"), "REL1"),
110+
relationship(idFunction.of("b"), idFunction.of("c"), "REL1")
111+
)
112+
);
113+
}
114+
92115
static Stream<Arguments> relTypesAndResultContainerFunction() {
93116
return Stream.of(
94117
Arguments.of(

0 commit comments

Comments
 (0)