Skip to content

Commit 5f2f224

Browse files
committed
Set missing config keys to NULL when forwarding from alpha
1 parent 040374b commit 5f2f224

3 files changed

Lines changed: 86 additions & 6 deletions

File tree

cypher-aggregation/src/main/java/org/neo4j/gds/projection/AlphaGraphAggregator.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class AlphaGraphAggregator extends GraphAggregator {
4343
@Override
4444
public void update(AnyValue[] input) throws ProcedureException {
4545
try {
46-
var nodesConfig = input[3];
46+
var nodesConfig = nodeConfigMap(input[3]);
4747
var relationshipsConfig = relationshipConfigMap(input[4]);
4848
AnyValue dataConfig = NoValue.NO_VALUE;
4949
dataConfig = mergeMaps(dataConfig, nodesConfig);
@@ -67,12 +67,36 @@ public void update(AnyValue[] input) throws ProcedureException {
6767
}
6868
}
6969

70+
private static AnyValue nodeConfigMap(AnyValue nodeConfig) {
71+
if (nodeConfig == NoValue.NO_VALUE) {
72+
return NoValue.NO_VALUE;
73+
}
74+
75+
var config = (MapValue) nodeConfig;
76+
77+
if (config.containsKey(SOURCE_NODE_LABELS) && !config.containsKey(TARGET_NODE_LABELS)) {
78+
config = config.updatedWith(TARGET_NODE_LABELS, NoValue.NO_VALUE);
79+
}
80+
if (config.containsKey(TARGET_NODE_LABELS) && !config.containsKey(SOURCE_NODE_LABELS)) {
81+
config = config.updatedWith(SOURCE_NODE_LABELS, NoValue.NO_VALUE);
82+
}
83+
84+
if (config.containsKey(SOURCE_NODE_PROPERTIES) && !config.containsKey(TARGET_NODE_PROPERTIES)) {
85+
config = config.updatedWith(TARGET_NODE_PROPERTIES, NoValue.NO_VALUE);
86+
}
87+
if (config.containsKey(TARGET_NODE_PROPERTIES) && !config.containsKey(SOURCE_NODE_PROPERTIES)) {
88+
config = config.updatedWith(SOURCE_NODE_PROPERTIES, NoValue.NO_VALUE);
89+
}
90+
91+
return config;
92+
}
93+
7094
private static AnyValue relationshipConfigMap(AnyValue relationshipConfig) {
7195
if (relationshipConfig == NoValue.NO_VALUE) {
7296
return NoValue.NO_VALUE;
7397
}
7498

75-
var config = ((MapValue) relationshipConfig);
99+
var config = (MapValue) relationshipConfig;
76100

77101
if (config.containsKey(ALPHA_RELATIONSHIP_PROPERTIES) && !config.containsKey(RELATIONSHIP_PROPERTIES)) {
78102
return config

cypher-aggregation/src/main/java/org/neo4j/gds/projection/GraphAggregator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@
5555

5656
abstract class GraphAggregator implements CompatUserAggregator {
5757

58-
private static final String SOURCE_NODE_PROPERTIES = "sourceNodeProperties";
59-
private static final String SOURCE_NODE_LABELS = "sourceNodeLabels";
60-
private static final String TARGET_NODE_PROPERTIES = "targetNodeProperties";
61-
private static final String TARGET_NODE_LABELS = "targetNodeLabels";
58+
static final String SOURCE_NODE_PROPERTIES = "sourceNodeProperties";
59+
static final String SOURCE_NODE_LABELS = "sourceNodeLabels";
60+
static final String TARGET_NODE_PROPERTIES = "targetNodeProperties";
61+
static final String TARGET_NODE_LABELS = "targetNodeLabels";
6262
static final String ALPHA_RELATIONSHIP_PROPERTIES = "properties";
6363
static final String RELATIONSHIP_PROPERTIES = "relationshipProperties";
6464
private static final String RELATIONSHIP_TYPE = "relationshipType";

cypher-aggregation/src/test/java/org/neo4j/gds/projection/CypherAggregationTest.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,62 @@ void testAlphaForwarding() {
799799
TestSupport.assertGraphEquals(g1, g2);
800800
}
801801

802+
@Test
803+
void testAlphaForwardingWithMissingTargetConfigKeys() {
804+
runQuery(
805+
"MATCH (s:B)-[r:REL]-(t:B) " +
806+
"RETURN gds.alpha.graph.project('g1', s, t," +
807+
" { sourceNodeLabels: labels(s)," +
808+
" targetNodeProperties: t { .prop1 } }," +
809+
" NULL," +
810+
" {}" +
811+
");"
812+
);
813+
814+
runQuery(
815+
"MATCH (s:B)-[r:REL]-(t:B) " +
816+
"RETURN gds.graph.project('g2', s, t," +
817+
" { sourceNodeLabels: labels(s), targetNodeLabels: NULL," +
818+
" sourceNodeProperties: NULL, targetNodeProperties: t { .prop1 } }" +
819+
");"
820+
);
821+
822+
assertThat(GraphStoreCatalog.exists("", db.databaseName(), "g1")).isTrue();
823+
assertThat(GraphStoreCatalog.exists("", db.databaseName(), "g2")).isTrue();
824+
var g1 = GraphStoreCatalog.get("", db.databaseName(), "g1").graphStore().getUnion();
825+
var g2 = GraphStoreCatalog.get("", db.databaseName(), "g2").graphStore().getUnion();
826+
827+
TestSupport.assertGraphEquals(g1, g2);
828+
}
829+
830+
@Test
831+
void testAlphaForwardingWithMissingSourceConfigKeys() {
832+
runQuery(
833+
"MATCH (s:B)-[r:REL]-(t:B) " +
834+
"RETURN gds.alpha.graph.project('g1', s, t," +
835+
" { targetNodeLabels: labels(s)," +
836+
" sourceNodeProperties: t { .prop1 } }," +
837+
" NULL," +
838+
" {}" +
839+
");"
840+
);
841+
842+
runQuery(
843+
"MATCH (s:B)-[r:REL]-(t:B) " +
844+
"RETURN gds.graph.project('g2', s, t," +
845+
" { targetNodeLabels: labels(s), sourceNodeLabels: NULL," +
846+
" targetNodeProperties: NULL, sourceNodeProperties: t { .prop1 } }" +
847+
");"
848+
);
849+
850+
assertThat(GraphStoreCatalog.exists("", db.databaseName(), "g1")).isTrue();
851+
assertThat(GraphStoreCatalog.exists("", db.databaseName(), "g2")).isTrue();
852+
var g1 = GraphStoreCatalog.get("", db.databaseName(), "g1").graphStore().getUnion();
853+
var g2 = GraphStoreCatalog.get("", db.databaseName(), "g2").graphStore().getUnion();
854+
855+
TestSupport.assertGraphEquals(g1, g2);
856+
}
857+
802858
@ParameterizedTest
803859
@CsvSource({"42, Long", "13.37, Double"})
804860
void testInvalidLabel(String label, String type) {

0 commit comments

Comments
 (0)