diff --git a/algo/src/main/java/org/neo4j/graphalgo/LabelPropagationProc.java b/algo/src/main/java/org/neo4j/graphalgo/LabelPropagationProc.java index e686e513e..cea930857 100644 --- a/algo/src/main/java/org/neo4j/graphalgo/LabelPropagationProc.java +++ b/algo/src/main/java/org/neo4j/graphalgo/LabelPropagationProc.java @@ -49,6 +49,7 @@ public final class LabelPropagationProc { public static final String CONFIG_WEIGHT_KEY = "weightProperty"; + public static final String CONFIG_WRITE_KEY = "writeProperty"; public static final String CONFIG_PARTITION_KEY = "partitionProperty"; public static final Integer DEFAULT_ITERATIONS = 1; public static final Boolean DEFAULT_WRITE = Boolean.TRUE; @@ -73,23 +74,36 @@ public final class LabelPropagationProc { public Stream labelPropagation( @Name(value = "label", defaultValue = "") String label, @Name(value = "relationship", defaultValue = "") String relationshipType, - @Name(value = "direction", defaultValue = "OUTGOING") String directionName, - @Name(value = "config", defaultValue = "{}") Map config) { + @Name(value = "config", defaultValue="null") Object directionOrConfig, + @Name(value = "deprecatedConfig", defaultValue = "{}") Map config) { + Map rawConfig = config; + if (directionOrConfig == null) { + if (!config.isEmpty()) { + directionOrConfig = "OUTGOING"; + } + } else if (directionOrConfig instanceof Map) { + rawConfig = (Map) directionOrConfig; + } - final ProcedureConfiguration configuration = ProcedureConfiguration.create(config) + final ProcedureConfiguration configuration = ProcedureConfiguration.create(rawConfig) .overrideNodeLabelOrQuery(label) - .overrideRelationshipTypeOrQuery(relationshipType) - .overrideDirection(directionName); + .overrideRelationshipTypeOrQuery(relationshipType); + + if(directionOrConfig instanceof String) { + configuration.overrideDirection((String) directionOrConfig); + } final int iterations = configuration.getIterations(DEFAULT_ITERATIONS); final int batchSize = configuration.getBatchSize(); final int concurrency = configuration.getConcurrency(); final String partitionProperty = configuration.getString(CONFIG_PARTITION_KEY, DEFAULT_PARTITION_KEY); + final String writeProperty = configuration.get(CONFIG_WRITE_KEY, CONFIG_PARTITION_KEY, DEFAULT_PARTITION_KEY); final String weightProperty = configuration.getString(CONFIG_WEIGHT_KEY, DEFAULT_WEIGHT_KEY); LabelPropagationStats.Builder stats = new LabelPropagationStats.Builder() .iterations(iterations) .partitionProperty(partitionProperty) + .writeProperty(writeProperty) .weightProperty(weightProperty); GraphLoader graphLoader = graphLoader(configuration, partitionProperty, weightProperty, createPropertyMappings(partitionProperty, weightProperty)); @@ -109,9 +123,9 @@ public Stream labelPropagation( } final int[] labels = compute(direction, iterations, batchSize, concurrency, graph, stats); - if (configuration.isWriteFlag(DEFAULT_WRITE) && partitionProperty != null) { + if (configuration.isWriteFlag(DEFAULT_WRITE) && writeProperty != null) { stats.withWrite(true); - write(concurrency, partitionProperty, graph, labels, stats); + write(concurrency, writeProperty, graph, labels, stats); } return Stream.of(stats.build(graph.nodeCount(), l -> (long) labels[(int) l])); diff --git a/algo/src/main/java/org/neo4j/graphalgo/StronglyConnectedComponentsProc.java b/algo/src/main/java/org/neo4j/graphalgo/StronglyConnectedComponentsProc.java index 97b2bf27b..660d4a20c 100644 --- a/algo/src/main/java/org/neo4j/graphalgo/StronglyConnectedComponentsProc.java +++ b/algo/src/main/java/org/neo4j/graphalgo/StronglyConnectedComponentsProc.java @@ -51,7 +51,8 @@ */ public class StronglyConnectedComponentsProc { - public static final String CONFIG_WRITE_PROPERTY = "partitionProperty"; + public static final String CONFIG_WRITE_PROPERTY = "writeProperty"; + public static final String CONFIG_OLD_WRITE_PROPERTY = "partitionProperty"; public static final String CONFIG_CLUSTER = "partition"; @Context @@ -124,7 +125,7 @@ public Stream sccTarjan( final int[] connectedComponents = tarjan.getConnectedComponents(); if (configuration.isWriteFlag()) { builder.withWrite(true); - String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_CLUSTER); + String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_OLD_WRITE_PROPERTY, CONFIG_CLUSTER); builder.withPartitionProperty(partitionProperty); builder.timeWrite(() -> { @@ -179,7 +180,7 @@ public Stream sccTunedTarjan( if (configuration.isWriteFlag()) { builder.withWrite(true); - String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_CLUSTER); + String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_OLD_WRITE_PROPERTY, CONFIG_CLUSTER); builder.withPartitionProperty(partitionProperty); builder.timeWrite(() -> Exporter @@ -261,8 +262,8 @@ public Stream sccIterativeTarjan( if (configuration.isWriteFlag()) { builder.withWrite(true); - String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_CLUSTER); - builder.withPartitionProperty(partitionProperty); + String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_OLD_WRITE_PROPERTY, CONFIG_CLUSTER); + builder.withPartitionProperty(partitionProperty).withWriteProperty(partitionProperty); builder.timeWrite(() -> write(configuration, graph, terminationFlag, tarjan, partitionProperty)); } @@ -382,7 +383,7 @@ public Stream multistep( multistep.release(); builder.timeWrite(() -> { builder.withWrite(true); - String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_CLUSTER); + String partitionProperty = configuration.get(CONFIG_WRITE_PROPERTY, CONFIG_OLD_WRITE_PROPERTY, CONFIG_CLUSTER); builder.withPartitionProperty(partitionProperty); Exporter diff --git a/algo/src/main/java/org/neo4j/graphalgo/impl/UnionFindProcExec.java b/algo/src/main/java/org/neo4j/graphalgo/impl/UnionFindProcExec.java index c9c6360a3..6c92c848b 100644 --- a/algo/src/main/java/org/neo4j/graphalgo/impl/UnionFindProcExec.java +++ b/algo/src/main/java/org/neo4j/graphalgo/impl/UnionFindProcExec.java @@ -45,7 +45,8 @@ public final class UnionFindProcExec implements BiConsumer> { private static final String CONFIG_THRESHOLD = "threshold"; - private static final String CONFIG_CLUSTER_PROPERTY = "partitionProperty"; + private static final String CONFIG_CLUSTER_PROPERTY = "writeProperty"; + private static final String CONFIG_OLD_CLUSTER_PROPERTY = "partitionProperty"; private static final String DEFAULT_CLUSTER_PROPERTY = "partition"; @@ -86,9 +87,9 @@ public static Stream run( graph.release(); if (configuration.isWriteFlag()) { - String writeProperty = configuration.get(CONFIG_CLUSTER_PROPERTY, DEFAULT_CLUSTER_PROPERTY); + String writeProperty = configuration.get(CONFIG_CLUSTER_PROPERTY, CONFIG_OLD_CLUSTER_PROPERTY, DEFAULT_CLUSTER_PROPERTY); builder.withWrite(true); - builder.withPartitionProperty(writeProperty); + builder.withPartitionProperty(writeProperty).withWriteProperty(writeProperty); uf.write(builder::timeWrite, graph, dssResult, configuration, writeProperty); } @@ -119,7 +120,7 @@ public static class UnionFindResult { -1, -1, -1, - false, null); + false, null, null); public final long loadMillis; public final long computeMillis; @@ -140,9 +141,12 @@ public static class UnionFindResult { public final long p100; public final boolean write; public final String partitionProperty; + public final String writeProperty; - 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) { + 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, String writeProperty) { this.loadMillis = loadMillis; this.computeMillis = computeMillis; this.writeMillis = writeMillis; @@ -161,11 +165,13 @@ public UnionFindResult(long loadMillis, long computeMillis, long postProcessingM this.p1 = p1; this.write = write; this.partitionProperty = partitionProperty; + this.writeProperty = writeProperty; } } public static class Builder extends AbstractCommunityResultBuilder { private String partitionProperty; + private String writeProperty; @Override 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 communityHistogram.getValueAtPercentile(5), communityHistogram.getValueAtPercentile(1), write, - partitionProperty + partitionProperty, + writeProperty ); } public Builder withPartitionProperty(String partitionProperty) { this.partitionProperty = partitionProperty; - return null; + return this; + } + + + public Builder withWriteProperty(String writeProperty) { + this.writeProperty = writeProperty; + return this; } } diff --git a/algo/src/main/java/org/neo4j/graphalgo/results/LabelPropagationStats.java b/algo/src/main/java/org/neo4j/graphalgo/results/LabelPropagationStats.java index 13605194f..096f0078d 100644 --- a/algo/src/main/java/org/neo4j/graphalgo/results/LabelPropagationStats.java +++ b/algo/src/main/java/org/neo4j/graphalgo/results/LabelPropagationStats.java @@ -44,7 +44,7 @@ public class LabelPropagationStats { false, false, "", - ""); + "", ""); public final long loadMillis; public final long computeMillis; @@ -70,10 +70,11 @@ public class LabelPropagationStats { public final String weightProperty; public final boolean write; public final String partitionProperty; + public final String writeProperty; public LabelPropagationStats(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, long iterations, boolean write, boolean didConverge, - String weightProperty, String partitionProperty) { + String weightProperty, String partitionProperty, String writeProperty) { this.loadMillis = loadMillis; this.computeMillis = computeMillis; this.postProcessingMillis = postProcessingMillis; @@ -95,6 +96,7 @@ public LabelPropagationStats(long loadMillis, long computeMillis, long postProce this.didConverge = didConverge; this.weightProperty = weightProperty; this.partitionProperty = partitionProperty; + this.writeProperty = writeProperty; } @@ -104,6 +106,7 @@ public static class Builder extends AbstractCommunityResultBuilder { private String partitionProperty; + private String writeProperty; @Override protected SCCResult build(long loadMillis, long computeMillis, long writeMillis, long postProcessingMillis, long nodeCount, long communityCount, LongLongMap communitySizeMap, Histogram communityHistogram, boolean write) { @@ -106,7 +109,7 @@ protected SCCResult build(long loadMillis, long computeMillis, long writeMillis, communityHistogram.getMinNonZeroValue(), communityHistogram.getMaxValue(), write, - partitionProperty + partitionProperty, writeProperty ); } @@ -114,6 +117,11 @@ public Builder withPartitionProperty(String partitionProperty) { this.partitionProperty = partitionProperty; return this; } + + public Builder withWriteProperty(String writeProperty) { + this.writeProperty = writeProperty; + return this; + } } } diff --git a/core/src/main/java/org/neo4j/graphalgo/core/ProcedureConfiguration.java b/core/src/main/java/org/neo4j/graphalgo/core/ProcedureConfiguration.java index 2f97e5f57..3886541c8 100644 --- a/core/src/main/java/org/neo4j/graphalgo/core/ProcedureConfiguration.java +++ b/core/src/main/java/org/neo4j/graphalgo/core/ProcedureConfiguration.java @@ -387,6 +387,17 @@ public V get(String key, V defaultValue) { return (V) value; } + public V get(String newKey, String oldKey, V defaultValue) { + Object value = config.get(newKey); + if (null == value) { + value = config.get(oldKey); + if(null == value) { + return defaultValue; + } + } + return (V) value; + } + public static ProcedureConfiguration create(Map config) { return new ProcedureConfiguration(config); } @@ -415,4 +426,6 @@ public DuplicateRelationshipsStrategy getDuplicateRelationshipsStrategy() { String strategy = get("duplicateRelationships", null); return strategy != null ? DuplicateRelationshipsStrategy.valueOf(strategy.toUpperCase()) : DuplicateRelationshipsStrategy.NONE; } + + } diff --git a/doc/asciidoc/connected-components.adoc b/doc/asciidoc/connected-components.adoc index 3c4857dec..f51ba48fd 100644 --- a/doc/asciidoc/connected-components.adoc +++ b/doc/asciidoc/connected-components.adoc @@ -209,7 +209,7 @@ include::scripts/connected-components.cypher[tag=cypher-loading] [source, cypher] ---- CALL algo.unionFind(label:String, relationship:String, {threshold:0.42, - defaultValue:1.0, write: true, partitionProperty:'partition', weightProperty:'weight', graph:'heavy', concurrency:4}) + defaultValue:1.0, write: true, writeProperty:'partition', weightProperty:'weight', graph:'heavy', concurrency:4}) YIELD nodes, setCount, loadMillis, computeMillis, writeMillis ---- @@ -221,7 +221,7 @@ YIELD nodes, setCount, loadMillis, computeMillis, writeMillis | relationship | string | null | yes | The relationship-type to load from the graph. If null, load all relationships | weightProperty | string | null | yes | The property name that contains weight. If null, treats the graph as unweighted. Must be numeric. | write | boolean | true | yes | Specifies if the result should be written back as a node property -| partitionProperty | string | 'partition' | yes | The property name written back the ID of the partition particular node belongs to +| writeProperty | string | 'partition' | yes | The property name written back the ID of the partition particular node belongs to | threshold | float | null | yes | The value of the weight above which the relationship is not thrown away | defaultValue | float | null | yes | The default value of the weight in case it is missing or invalid | concurrency | int | available CPUs | yes | The number of concurrent threads @@ -252,7 +252,7 @@ YIELD nodes, setCount, loadMillis, computeMillis, writeMillis | p100 | double | The 100 percentile of community size. | write | boolean | Specifies if the result was written back as a node property -| partitionProperty | string | The property name written back to +| writeProperty | string | The property name written back to |=== diff --git a/doc/asciidoc/label-propagation.adoc b/doc/asciidoc/label-propagation.adoc index 8816c684f..2cf409bd3 100644 --- a/doc/asciidoc/label-propagation.adoc +++ b/doc/asciidoc/label-propagation.adoc @@ -160,8 +160,8 @@ include::scripts/label-propagation.cypher[tag=cypher-loading] [source, cypher] ---- CALL algo.labelPropagation(label:String, relationship:String, direction:String, {iterations:1, - weightProperty:'weight', partitionProperty:'partition', write:true, concurrency:4}) -YIELD nodes, iterations, didConverge, loadMillis, computeMillis, writeMillis, write, weightProperty, partitionProperty + weightProperty:'weight', writeProperty:'partition', write:true, concurrency:4}) +YIELD nodes, iterations, didConverge, loadMillis, computeMillis, writeMillis, write, weightProperty, writeProperty ---- .Parameters @@ -174,7 +174,8 @@ YIELD nodes, iterations, didConverge, loadMillis, computeMillis, writeMillis, wr | concurrency | int | available CPUs | yes | The number of concurrent threads | iterations | int | 1 | yes | The maximum number of iterations to run | weightProperty | string | 'weight' | yes | The property name of node and/or relationship that contain weight. Must be numeric. -| partitionProperty | string | 'partition' | yes | The property name written back to the partition of the graph in which the node reside. Can be used to define initial set of labels (must be a number) +| partitionProperty | string | 'partition' | yes | Used to define initial set of labels (must be a number) +| writeProperty | string | 'partition' | yes | The property name written back to the partition of the graph in which the node resides. | write | boolean | true | yes | Specifies if the result should be written back as a node property | graph | string | 'heavy' | yes | Use 'heavy' when describing the subset of the graph with label and relationship-type parameter. Use 'cypher' for describing the subset with cypher node-statement and relationship-statement |=== @@ -205,7 +206,7 @@ YIELD nodes, iterations, didConverge, loadMillis, computeMillis, writeMillis, wr | p100 | double | The 100 percentile of community size. | write | boolean | Specifies if the result was written back as a node property -| partitionProperty | string | The property name written back to +| writeProperty | string | The property name written back to | weightProperty | string | The property name that contains weight |=== @@ -214,7 +215,7 @@ YIELD nodes, iterations, didConverge, loadMillis, computeMillis, writeMillis, wr [source,cypher] ---- CALL algo.labelPropagation.stream(label:String, relationship:String, {iterations:1, - weightProperty:'weight', partitionProperty:'partition', concurrency:4, direction:'OUTGOING'}) + weightProperty:'weight', writeProperty:'partition', concurrency:4, direction:'OUTGOING'}) YIELD nodeId, label ---- @@ -228,7 +229,8 @@ YIELD nodeId, label | concurrency | int | available CPUs | yes | The number of concurrent threads | iterations | int | 1 | yes | The maximum number of iterations to run | weightProperty | string | 'weight' | yes | The property name of node and/or relationship that contain weight. Must be numeric. -| partitionProperty | string | 'partition' | yes | The property name written back to the partition of the graph in which the node reside. Can be used to define initial set of labels (must be a number) +| partitionProperty | string | 'partition' | yes | Used to define initial set of labels (must be a number) +| writeProperty | string | 'partition' | yes | The property name written back to the partition of the graph in which the node resides. | graph | string | 'heavy' | yes | Use 'heavy' when describing the subset of the graph with label and relationship-type parameter. Use 'cypher' for describing the subset with cypher node-statement and relationship-statement |=== diff --git a/doc/asciidoc/strongly-connected-components.adoc b/doc/asciidoc/strongly-connected-components.adoc index d1975acf3..cee378e51 100644 --- a/doc/asciidoc/strongly-connected-components.adoc +++ b/doc/asciidoc/strongly-connected-components.adoc @@ -129,7 +129,7 @@ include::scripts/strongly-connected-components.cypher[tag=cypher-loading] [source, cypher] ---- CALL algo.scc(label:String, relationship:String, - {write:true,partitionProperty:'partition',concurrency:4, graph:'heavy'}) + {write:true,writeProperty:'partition',concurrency:4, graph:'heavy'}) YIELD loadMillis, computeMillis, writeMillis, setCount, maxSetSize, minSetSize ---- @@ -140,7 +140,7 @@ YIELD loadMillis, computeMillis, writeMillis, setCount, maxSetSize, minSetSize | label | string | null | yes | The label to load from the graph. If null, load all nodes | relationship | string | null | yes | The relationship-type to load from the graph. If null, load all relationships | write | boolean | true | yes | Specifies if the result should be written back as a node property -| partitionProperty | string | 'partition' | yes | The property name written back to +| writeProperty | string | 'partition' | yes | The property name written back to | concurrency | int | available CPUs | yes | The number of concurrent threads | graph | string | 'heavy' | yes | Use 'heavy' when describing the subset of the graph with label and relationship-type parameter. Use 'cypher' for describing the subset with cypher node-statement and relationship-statement |=== @@ -169,7 +169,7 @@ YIELD loadMillis, computeMillis, writeMillis, setCount, maxSetSize, minSetSize | p100 | double | The 100 percentile of community size. | write | boolean | Specifies if the result was written back as a node property -| partitionProperty | string | The property name written back to +| writeProperty | string | The property name written back to |=== diff --git a/tests/src/test/java/org/neo4j/graphalgo/algo/LabelPropagationProcIntegrationTest.java b/tests/src/test/java/org/neo4j/graphalgo/algo/LabelPropagationProcIntegrationTest.java index 3b77c9ed3..7e4949e94 100644 --- a/tests/src/test/java/org/neo4j/graphalgo/algo/LabelPropagationProcIntegrationTest.java +++ b/tests/src/test/java/org/neo4j/graphalgo/algo/LabelPropagationProcIntegrationTest.java @@ -96,6 +96,33 @@ public void shouldUseDefaultValues() { assertEquals(1, row.getNumber("iterations").intValue()); assertEquals("weight", row.getString("weightProperty")); assertEquals("partition", row.getString("partitionProperty")); + assertEquals("partition", row.getString("writeProperty")); + assertTrue(row.getBoolean("write")); + }); + } + + @Test + public void explicitWriteProperty() { + String query = "CALL algo.labelPropagation(null, null, null, {writeProperty: 'lpa'})"; + + runQuery(query, row -> { + assertEquals(1, row.getNumber("iterations").intValue()); + assertEquals("weight", row.getString("weightProperty")); + assertEquals("partition", row.getString("partitionProperty")); + assertEquals("lpa", row.getString("writeProperty")); + assertTrue(row.getBoolean("write")); + }); + } + + @Test + public void explicitWritePropertyWithConfigAs3rdParameter() { + String query = "CALL algo.labelPropagation(null, null, {writeProperty: 'lpa'})"; + + runQuery(query, row -> { + assertEquals(1, row.getNumber("iterations").intValue()); + assertEquals("weight", row.getString("weightProperty")); + assertEquals("partition", row.getString("partitionProperty")); + assertEquals("lpa", row.getString("writeProperty")); assertTrue(row.getBoolean("write")); }); } diff --git a/tests/src/test/java/org/neo4j/graphalgo/algo/StronglyConnectedComponentsProcIntegrationTest.java b/tests/src/test/java/org/neo4j/graphalgo/algo/StronglyConnectedComponentsProcIntegrationTest.java index 546b8cb62..67e5a5f62 100644 --- a/tests/src/test/java/org/neo4j/graphalgo/algo/StronglyConnectedComponentsProcIntegrationTest.java +++ b/tests/src/test/java/org/neo4j/graphalgo/algo/StronglyConnectedComponentsProcIntegrationTest.java @@ -96,20 +96,31 @@ public static Collection data() { @Test public void testScc() throws Exception { - - db.execute("CALL algo.scc('Node', 'TYPE', {write:true, graph:'"+graphImpl+"'}) YIELD loadMillis, computeMillis, writeMillis, setCount, maxSetSize, minSetSize") + db.execute("CALL algo.scc('Node', 'TYPE', {write:true, graph:'"+graphImpl+"'}) YIELD loadMillis, computeMillis, writeMillis, setCount, maxSetSize, minSetSize, partitionProperty, writeProperty") .accept(row -> { + assertNotEquals(-1L, row.getNumber("computeMillis").longValue()); + assertNotEquals(-1L, row.getNumber("writeMillis").longValue()); + assertEquals(2, row.getNumber("setCount").longValue()); + assertEquals(2, row.getNumber("minSetSize").longValue()); + assertEquals(3, row.getNumber("maxSetSize").longValue()); + assertEquals("partition", row.getString("partitionProperty")); + assertEquals("partition", row.getString("writeProperty")); - System.out.println(row.getNumber("loadMillis").longValue()); - System.out.println(row.getNumber("computeMillis").longValue()); - System.out.println(row.getNumber("writeMillis").longValue()); - System.out.println(row.getNumber("setCount").longValue()); + return true; + }); + } + @Test + public void explicitWriteProperty() throws Exception { + db.execute("CALL algo.scc('Node', 'TYPE', {write:true, graph:'"+graphImpl+"', writeProperty: 'scc'}) YIELD loadMillis, computeMillis, writeMillis, setCount, maxSetSize, minSetSize, partitionProperty, writeProperty") + .accept(row -> { assertNotEquals(-1L, row.getNumber("computeMillis").longValue()); assertNotEquals(-1L, row.getNumber("writeMillis").longValue()); assertEquals(2, row.getNumber("setCount").longValue()); assertEquals(2, row.getNumber("minSetSize").longValue()); assertEquals(3, row.getNumber("maxSetSize").longValue()); + assertEquals("scc", row.getString("partitionProperty")); + assertEquals("scc", row.getString("writeProperty")); return true; }); diff --git a/tests/src/test/java/org/neo4j/graphalgo/algo/UnionFindProcIntegrationTest.java b/tests/src/test/java/org/neo4j/graphalgo/algo/UnionFindProcIntegrationTest.java index 2ee3cee0d..d9727e555 100644 --- a/tests/src/test/java/org/neo4j/graphalgo/algo/UnionFindProcIntegrationTest.java +++ b/tests/src/test/java/org/neo4j/graphalgo/algo/UnionFindProcIntegrationTest.java @@ -130,16 +130,33 @@ public void testUnionFindWithLabel() throws Exception { @Test public void testUnionFindWriteBack() throws Exception { - db.execute("CALL algo.unionFind('', 'TYPE', {write:true,graph:'"+graphImpl+"'}) YIELD setCount, communityCount, writeMillis, nodes") + db.execute("CALL algo.unionFind('', 'TYPE', {write:true,graph:'"+graphImpl+"'}) YIELD setCount, communityCount, writeMillis, nodes, partitionProperty, writeProperty") .accept((Result.ResultVisitor) row -> { assertNotEquals(-1L, row.getNumber("writeMillis")); assertNotEquals(-1L, row.getNumber("nodes")); assertEquals(3L, row.getNumber("communityCount")); assertEquals(3L, row.getNumber("setCount")); + assertEquals("partition", row.getString("partitionProperty")); + assertEquals("partition", row.getString("writeProperty")); return false; }); } + @Test + public void testUnionFindWriteBackExplicitWriteProperty() throws Exception { + db.execute("CALL algo.unionFind('', 'TYPE', {write:true,graph:'"+graphImpl+"', writeProperty:'unionFind'}) YIELD setCount, communityCount, writeMillis, nodes, partitionProperty, writeProperty") + .accept((Result.ResultVisitor) row -> { + assertNotEquals(-1L, row.getNumber("writeMillis")); + assertNotEquals(-1L, row.getNumber("nodes")); + assertEquals(3L, row.getNumber("communityCount")); + assertEquals(3L, row.getNumber("setCount")); + assertEquals("unionFind", row.getString("partitionProperty")); + assertEquals("unionFind", row.getString("writeProperty")); + return false; + }); + } + + @Test public void testUnionFindStream() throws Exception { final IntIntScatterMap map = new IntIntScatterMap(11); diff --git a/tests/src/test/java/org/neo4j/graphalgo/core/ProcedureConfigurationTest.java b/tests/src/test/java/org/neo4j/graphalgo/core/ProcedureConfigurationTest.java new file mode 100644 index 000000000..892ab32b9 --- /dev/null +++ b/tests/src/test/java/org/neo4j/graphalgo/core/ProcedureConfigurationTest.java @@ -0,0 +1,73 @@ +package org.neo4j.graphalgo.core; + +import org.junit.Test; +import org.neo4j.helpers.collection.MapUtil; + +import java.util.Collections; +import java.util.Map; + +import static org.junit.Assert.*; + +public class ProcedureConfigurationTest { + + @Test + public void useDefault() { + Map map = Collections.emptyMap(); + ProcedureConfiguration procedureConfiguration = new ProcedureConfiguration(map); + String value = procedureConfiguration.get("partitionProperty", "defaultValue"); + assertEquals("defaultValue", value); + } + + @Test + public void returnValueIfPresent() { + Map map = MapUtil.map("partitionProperty", "partition"); + ProcedureConfiguration procedureConfiguration = new ProcedureConfiguration(map); + String value = procedureConfiguration.get("partitionProperty", "defaultValue"); + assertEquals("partition", value); + } + + @Test + public void newKeyIfPresent() { + Map map = MapUtil.map("partitionProperty", "old", "writeProperty", "new"); + ProcedureConfiguration procedureConfiguration = new ProcedureConfiguration(map); + String value = procedureConfiguration.get("writeProperty", "partitionProperty", "defaultValue"); + assertEquals("new", value); + } + + @Test + public void oldKeyIfNewKeyNotPresent() { + Map map = MapUtil.map("partitionProperty", "old"); + ProcedureConfiguration procedureConfiguration = new ProcedureConfiguration(map); + String value = procedureConfiguration.get("writeProperty", "partitionProperty", "defaultValue"); + assertEquals("old", value); + } + + @Test + public void defaultIfNoKeysPresent() { + Map map = Collections.emptyMap(); + ProcedureConfiguration procedureConfiguration = new ProcedureConfiguration(map); + String value = procedureConfiguration.get("writeProperty", "partitionProperty", "defaultValue"); + assertEquals("defaultValue", value); + } + + @Test + public void defaultIfKeyMissing() { + Map map = Collections.emptyMap(); + ProcedureConfiguration procedureConfiguration = new ProcedureConfiguration(map); + assertEquals("defaultValue", procedureConfiguration.getString("writeProperty", "defaultValue")); + } + + @Test + public void defaultIfKeyPresentButNoValue() { + Map map = MapUtil.map("writeProperty", ""); + ProcedureConfiguration procedureConfiguration = new ProcedureConfiguration(map); + assertEquals("defaultValue", procedureConfiguration.getString("writeProperty", "defaultValue")); + } + + @Test + public void valueIfKeyPresent() { + Map map = MapUtil.map("writeProperty", "scc"); + ProcedureConfiguration procedureConfiguration = new ProcedureConfiguration(map); + assertEquals("scc", procedureConfiguration.getString("writeProperty", "defaultValue")); + } +} \ No newline at end of file