Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit fee6aa9

Browse files
committed
3.4 consistent signature across algorithms (#836)
* use writeProperty consistently across algorithms * new and old keys * add write property to SCC * add write property to UnionFind * add write property to Label Propagation * override 3rd parameter of LPA so that it can be the same as all the other algos * some places I missed for SCC * update docs to reflect writeProperty changes
1 parent d847f82 commit fee6aa9

13 files changed

+233
-45
lines changed

algo/src/main/java/org/neo4j/graphalgo/LabelPropagationProc.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
public final class LabelPropagationProc {
5050

5151
public static final String CONFIG_WEIGHT_KEY = "weightProperty";
52+
public static final String CONFIG_WRITE_KEY = "writeProperty";
5253
public static final String CONFIG_PARTITION_KEY = "partitionProperty";
5354
public static final Integer DEFAULT_ITERATIONS = 1;
5455
public static final Boolean DEFAULT_WRITE = Boolean.TRUE;
@@ -73,23 +74,36 @@ public final class LabelPropagationProc {
7374
public Stream<LabelPropagationStats> labelPropagation(
7475
@Name(value = "label", defaultValue = "") String label,
7576
@Name(value = "relationship", defaultValue = "") String relationshipType,
76-
@Name(value = "direction", defaultValue = "OUTGOING") String directionName,
77-
@Name(value = "config", defaultValue = "{}") Map<String, Object> config) {
77+
@Name(value = "config", defaultValue="null") Object directionOrConfig,
78+
@Name(value = "deprecatedConfig", defaultValue = "{}") Map<String, Object> config) {
79+
Map<String, Object> rawConfig = config;
80+
if (directionOrConfig == null) {
81+
if (!config.isEmpty()) {
82+
directionOrConfig = "OUTGOING";
83+
}
84+
} else if (directionOrConfig instanceof Map) {
85+
rawConfig = (Map<String, Object>) directionOrConfig;
86+
}
7887

79-
final ProcedureConfiguration configuration = ProcedureConfiguration.create(config)
88+
final ProcedureConfiguration configuration = ProcedureConfiguration.create(rawConfig)
8089
.overrideNodeLabelOrQuery(label)
81-
.overrideRelationshipTypeOrQuery(relationshipType)
82-
.overrideDirection(directionName);
90+
.overrideRelationshipTypeOrQuery(relationshipType);
91+
92+
if(directionOrConfig instanceof String) {
93+
configuration.overrideDirection((String) directionOrConfig);
94+
}
8395

8496
final int iterations = configuration.getIterations(DEFAULT_ITERATIONS);
8597
final int batchSize = configuration.getBatchSize();
8698
final int concurrency = configuration.getConcurrency();
8799
final String partitionProperty = configuration.getString(CONFIG_PARTITION_KEY, DEFAULT_PARTITION_KEY);
100+
final String writeProperty = configuration.get(CONFIG_WRITE_KEY, CONFIG_PARTITION_KEY, DEFAULT_PARTITION_KEY);
88101
final String weightProperty = configuration.getString(CONFIG_WEIGHT_KEY, DEFAULT_WEIGHT_KEY);
89102

90103
LabelPropagationStats.Builder stats = new LabelPropagationStats.Builder()
91104
.iterations(iterations)
92105
.partitionProperty(partitionProperty)
106+
.writeProperty(writeProperty)
93107
.weightProperty(weightProperty);
94108

95109
GraphLoader graphLoader = graphLoader(configuration, partitionProperty, weightProperty, createPropertyMappings(partitionProperty, weightProperty));
@@ -109,9 +123,9 @@ public Stream<LabelPropagationStats> labelPropagation(
109123
}
110124

111125
final int[] labels = compute(direction, iterations, batchSize, concurrency, graph, stats);
112-
if (configuration.isWriteFlag(DEFAULT_WRITE) && partitionProperty != null) {
126+
if (configuration.isWriteFlag(DEFAULT_WRITE) && writeProperty != null) {
113127
stats.withWrite(true);
114-
write(concurrency, partitionProperty, graph, labels, stats);
128+
write(concurrency, writeProperty, graph, labels, stats);
115129
}
116130

117131
return Stream.of(stats.build(graph.nodeCount(), l -> (long) labels[(int) l]));

algo/src/main/java/org/neo4j/graphalgo/StronglyConnectedComponentsProc.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
*/
5252
public class StronglyConnectedComponentsProc {
5353

54-
public static final String CONFIG_WRITE_PROPERTY = "partitionProperty";
54+
public static final String CONFIG_WRITE_PROPERTY = "writeProperty";
55+
public static final String CONFIG_OLD_WRITE_PROPERTY = "partitionProperty";
5556
public static final String CONFIG_CLUSTER = "partition";
5657

5758
@Context
@@ -124,7 +125,7 @@ public Stream<SCCResult> sccTarjan(
124125
final int[] connectedComponents = tarjan.getConnectedComponents();
125126
if (configuration.isWriteFlag()) {
126127
builder.withWrite(true);
127-
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_CLUSTER);
128+
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_OLD_WRITE_PROPERTY, CONFIG_CLUSTER);
128129
builder.withPartitionProperty(partitionProperty);
129130

130131
builder.timeWrite(() -> {
@@ -179,7 +180,7 @@ public Stream<SCCResult> sccTunedTarjan(
179180

180181
if (configuration.isWriteFlag()) {
181182
builder.withWrite(true);
182-
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_CLUSTER);
183+
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_OLD_WRITE_PROPERTY, CONFIG_CLUSTER);
183184
builder.withPartitionProperty(partitionProperty);
184185

185186
builder.timeWrite(() -> Exporter
@@ -261,8 +262,8 @@ public Stream<SCCResult> sccIterativeTarjan(
261262

262263
if (configuration.isWriteFlag()) {
263264
builder.withWrite(true);
264-
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_CLUSTER);
265-
builder.withPartitionProperty(partitionProperty);
265+
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_OLD_WRITE_PROPERTY, CONFIG_CLUSTER);
266+
builder.withPartitionProperty(partitionProperty).withWriteProperty(partitionProperty);
266267

267268
builder.timeWrite(() -> write(configuration, graph, terminationFlag, tarjan, partitionProperty));
268269
}
@@ -382,7 +383,7 @@ public Stream<SCCResult> multistep(
382383
multistep.release();
383384
builder.timeWrite(() -> {
384385
builder.withWrite(true);
385-
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_CLUSTER);
386+
String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_OLD_WRITE_PROPERTY, CONFIG_CLUSTER);
386387
builder.withPartitionProperty(partitionProperty);
387388

388389
Exporter

algo/src/main/java/org/neo4j/graphalgo/impl/UnionFindProcExec.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
public final class UnionFindProcExec implements BiConsumer<String, Algorithm<?>> {
4646

4747
private static final String CONFIG_THRESHOLD = "threshold";
48-
private static final String CONFIG_CLUSTER_PROPERTY = "partitionProperty";
48+
private static final String CONFIG_CLUSTER_PROPERTY = "writeProperty";
49+
private static final String CONFIG_OLD_CLUSTER_PROPERTY = "partitionProperty";
4950
private static final String DEFAULT_CLUSTER_PROPERTY = "partition";
5051

5152

@@ -86,9 +87,9 @@ public static Stream<UnionFindResult> run(
8687
graph.release();
8788

8889
if (configuration.isWriteFlag()) {
89-
String writeProperty = configuration.get(CONFIG_CLUSTER_PROPERTY, DEFAULT_CLUSTER_PROPERTY);
90+
String writeProperty = configuration.get(CONFIG_CLUSTER_PROPERTY, CONFIG_OLD_CLUSTER_PROPERTY, DEFAULT_CLUSTER_PROPERTY);
9091
builder.withWrite(true);
91-
builder.withPartitionProperty(writeProperty);
92+
builder.withPartitionProperty(writeProperty).withWriteProperty(writeProperty);
9293

9394
uf.write(builder::timeWrite, graph, dssResult, configuration, writeProperty);
9495
}
@@ -119,7 +120,7 @@ public static class UnionFindResult {
119120
-1,
120121
-1,
121122
-1,
122-
false, null);
123+
false, null, null);
123124

124125
public final long loadMillis;
125126
public final long computeMillis;
@@ -140,9 +141,12 @@ public static class UnionFindResult {
140141
public final long p100;
141142
public final boolean write;
142143
public final String partitionProperty;
144+
public final String writeProperty;
143145

144146

145-
public UnionFindResult(long loadMillis, long computeMillis, long postProcessingMillis, long writeMillis, long nodes, long communityCount, long p100, long p99, long p95, long p90, long p75, long p50, long p25, long p10, long p5, long p1, boolean write, String partitionProperty) {
147+
public UnionFindResult(long loadMillis, long computeMillis, long postProcessingMillis, long writeMillis, long nodes, long communityCount,
148+
long p100, long p99, long p95, long p90, long p75, long p50, long p25, long p10, long p5, long p1, boolean write,
149+
String partitionProperty, String writeProperty) {
146150
this.loadMillis = loadMillis;
147151
this.computeMillis = computeMillis;
148152
this.writeMillis = writeMillis;
@@ -161,11 +165,13 @@ public UnionFindResult(long loadMillis, long computeMillis, long postProcessingM
161165
this.p1 = p1;
162166
this.write = write;
163167
this.partitionProperty = partitionProperty;
168+
this.writeProperty = writeProperty;
164169
}
165170
}
166171

167172
public static class Builder extends AbstractCommunityResultBuilder<UnionFindResult> {
168173
private String partitionProperty;
174+
private String writeProperty;
169175

170176
@Override
171177
protected UnionFindResult build(long loadMillis, long computeMillis, long writeMillis, long postProcessingMillis, long nodeCount, long communityCount, LongLongMap communitySizeMap, Histogram communityHistogram, boolean write) {
@@ -187,13 +193,20 @@ protected UnionFindResult build(long loadMillis, long computeMillis, long writeM
187193
communityHistogram.getValueAtPercentile(5),
188194
communityHistogram.getValueAtPercentile(1),
189195
write,
190-
partitionProperty
196+
partitionProperty,
197+
writeProperty
191198
);
192199
}
193200

194201
public Builder withPartitionProperty(String partitionProperty) {
195202
this.partitionProperty = partitionProperty;
196-
return null;
203+
return this;
204+
}
205+
206+
207+
public Builder withWriteProperty(String writeProperty) {
208+
this.writeProperty = writeProperty;
209+
return this;
197210
}
198211
}
199212

algo/src/main/java/org/neo4j/graphalgo/results/LabelPropagationStats.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class LabelPropagationStats {
4444
false,
4545
false,
4646
"<empty>",
47-
"<empty>");
47+
"<empty>", "<empty>");
4848

4949
public final long loadMillis;
5050
public final long computeMillis;
@@ -70,10 +70,11 @@ public class LabelPropagationStats {
7070
public final String weightProperty;
7171
public final boolean write;
7272
public final String partitionProperty;
73+
public final String writeProperty;
7374

7475
public LabelPropagationStats(long loadMillis, long computeMillis, long postProcessingMillis, long writeMillis, long nodes,
7576
long communityCount, long p100, long p99, long p95, long p90, long p75, long p50, long p25, long p10, long p5, long p1, long iterations, boolean write, boolean didConverge,
76-
String weightProperty, String partitionProperty) {
77+
String weightProperty, String partitionProperty, String writeProperty) {
7778
this.loadMillis = loadMillis;
7879
this.computeMillis = computeMillis;
7980
this.postProcessingMillis = postProcessingMillis;
@@ -95,6 +96,7 @@ public LabelPropagationStats(long loadMillis, long computeMillis, long postProce
9596
this.didConverge = didConverge;
9697
this.weightProperty = weightProperty;
9798
this.partitionProperty = partitionProperty;
99+
this.writeProperty = writeProperty;
98100
}
99101

100102

@@ -104,6 +106,7 @@ public static class Builder extends AbstractCommunityResultBuilder<LabelPropagat
104106
private boolean didConverge = false;
105107
private String weightProperty;
106108
private String partitionProperty;
109+
private String writeProperty;
107110

108111
public Builder iterations(final long iterations) {
109112
this.iterations = iterations;
@@ -124,6 +127,11 @@ public Builder partitionProperty(final String partitionProperty) {
124127
this.partitionProperty = partitionProperty;
125128
return this;
126129
}
130+
public Builder writeProperty(final String writeProperty) {
131+
this.writeProperty = writeProperty;
132+
return this;
133+
}
134+
127135

128136
@Override
129137
protected LabelPropagationStats build(long loadMillis, long computeMillis, long writeMillis, long postProcessingMillis, long nodeCount, long communityCount, LongLongMap communitySizeMap, Histogram communityHistogram, boolean write) {
@@ -148,7 +156,8 @@ protected LabelPropagationStats build(long loadMillis, long computeMillis, long
148156
write,
149157
didConverge,
150158
weightProperty,
151-
partitionProperty
159+
partitionProperty,
160+
writeProperty
152161
);
153162
}
154163

algo/src/main/java/org/neo4j/graphalgo/results/SCCResult.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class SCCResult {
2828

2929
public static SCCResult EMPTY = new SCCResult(
3030
0, 0, 0, 0,0, 0, -1,-1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0,
31-
false, null);
31+
false, null, null);
3232

3333
public final long loadMillis;
3434
public final long computeMillis;
@@ -51,10 +51,11 @@ public class SCCResult {
5151
public final long p100;
5252
public final boolean write;
5353
public final String partitionProperty;
54+
public final String writeProperty;
5455

5556
public SCCResult(long loadMillis, long computeMillis, long postProcessingMillis, long writeMillis, long nodes, long communityCount,
5657
long p100, long p99, long p95, long p90, long p75, long p50, long p25, long p10, long p5, long p1,
57-
long minSetSize, long maxSetSize, boolean write, String partitionProperty) {
58+
long minSetSize, long maxSetSize, boolean write, String partitionProperty, String writeProperty) {
5859
this.loadMillis = loadMillis;
5960
this.computeMillis = computeMillis;
6061
this.postProcessingMillis = postProcessingMillis;
@@ -75,6 +76,7 @@ public SCCResult(long loadMillis, long computeMillis, long postProcessingMillis,
7576
this.maxSetSize = maxSetSize;
7677
this.write = write;
7778
this.partitionProperty = partitionProperty;
79+
this.writeProperty = writeProperty;
7880
}
7981

8082
public static Builder builder() {
@@ -83,6 +85,7 @@ public static Builder builder() {
8385

8486
public static final class Builder extends AbstractCommunityResultBuilder<SCCResult> {
8587
private String partitionProperty;
88+
private String writeProperty;
8689

8790
@Override
8891
protected SCCResult build(long loadMillis, long computeMillis, long writeMillis, long postProcessingMillis, long nodeCount, long communityCount, LongLongMap communitySizeMap, Histogram communityHistogram, boolean write) {
@@ -106,14 +109,19 @@ protected SCCResult build(long loadMillis, long computeMillis, long writeMillis,
106109
communityHistogram.getMinNonZeroValue(),
107110
communityHistogram.getMaxValue(),
108111
write,
109-
partitionProperty
112+
partitionProperty, writeProperty
110113
);
111114
}
112115

113116
public Builder withPartitionProperty(String partitionProperty) {
114117
this.partitionProperty = partitionProperty;
115118
return this;
116119
}
120+
121+
public Builder withWriteProperty(String writeProperty) {
122+
this.writeProperty = writeProperty;
123+
return this;
124+
}
117125
}
118126

119127
}

core/src/main/java/org/neo4j/graphalgo/core/ProcedureConfiguration.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,17 @@ public <V> V get(String key, V defaultValue) {
387387
return (V) value;
388388
}
389389

390+
public <V> V get(String newKey, String oldKey, V defaultValue) {
391+
Object value = config.get(newKey);
392+
if (null == value) {
393+
value = config.get(oldKey);
394+
if(null == value) {
395+
return defaultValue;
396+
}
397+
}
398+
return (V) value;
399+
}
400+
390401
public static ProcedureConfiguration create(Map<String, Object> config) {
391402
return new ProcedureConfiguration(config);
392403
}
@@ -415,4 +426,6 @@ public DuplicateRelationshipsStrategy getDuplicateRelationshipsStrategy() {
415426
String strategy = get("duplicateRelationships", null);
416427
return strategy != null ? DuplicateRelationshipsStrategy.valueOf(strategy.toUpperCase()) : DuplicateRelationshipsStrategy.NONE;
417428
}
429+
430+
418431
}

doc/asciidoc/connected-components.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ include::scripts/connected-components.cypher[tag=cypher-loading]
209209
[source, cypher]
210210
----
211211
CALL algo.unionFind(label:String, relationship:String, {threshold:0.42,
212-
defaultValue:1.0, write: true, partitionProperty:'partition', weightProperty:'weight', graph:'heavy', concurrency:4})
212+
defaultValue:1.0, write: true, writeProperty:'partition', weightProperty:'weight', graph:'heavy', concurrency:4})
213213
YIELD nodes, setCount, loadMillis, computeMillis, writeMillis
214214
----
215215

@@ -221,7 +221,7 @@ YIELD nodes, setCount, loadMillis, computeMillis, writeMillis
221221
| relationship | string | null | yes | The relationship-type to load from the graph. If null, load all relationships
222222
| weightProperty | string | null | yes | The property name that contains weight. If null, treats the graph as unweighted. Must be numeric.
223223
| write | boolean | true | yes | Specifies if the result should be written back as a node property
224-
| partitionProperty | string | 'partition' | yes | The property name written back the ID of the partition particular node belongs to
224+
| writeProperty | string | 'partition' | yes | The property name written back the ID of the partition particular node belongs to
225225
| threshold | float | null | yes | The value of the weight above which the relationship is not thrown away
226226
| defaultValue | float | null | yes | The default value of the weight in case it is missing or invalid
227227
| concurrency | int | available CPUs | yes | The number of concurrent threads
@@ -252,7 +252,7 @@ YIELD nodes, setCount, loadMillis, computeMillis, writeMillis
252252
| p100 | double | The 100 percentile of community size.
253253

254254
| write | boolean | Specifies if the result was written back as a node property
255-
| partitionProperty | string | The property name written back to
255+
| writeProperty | string | The property name written back to
256256
|===
257257

258258

0 commit comments

Comments
 (0)