diff --git a/algo/src/main/java/org/neo4j/gds/algorithms/community/CommunityAlgorithmsWriteBusinessFacade.java b/algo/src/main/java/org/neo4j/gds/algorithms/community/CommunityAlgorithmsWriteBusinessFacade.java index a5ab99bca2..a82de7d265 100644 --- a/algo/src/main/java/org/neo4j/gds/algorithms/community/CommunityAlgorithmsWriteBusinessFacade.java +++ b/algo/src/main/java/org/neo4j/gds/algorithms/community/CommunityAlgorithmsWriteBusinessFacade.java @@ -27,6 +27,7 @@ import org.neo4j.gds.algorithms.KmeansSpecificFields; import org.neo4j.gds.algorithms.LabelPropagationSpecificFields; import org.neo4j.gds.algorithms.LeidenSpecificFields; +import org.neo4j.gds.algorithms.LocalClusteringCoefficientSpecificFields; import org.neo4j.gds.algorithms.LouvainSpecificFields; import org.neo4j.gds.algorithms.ModularityOptimizationSpecificFields; import org.neo4j.gds.algorithms.NodePropertyWriteResult; @@ -53,6 +54,7 @@ import org.neo4j.gds.result.StatisticsComputationInstructions; import org.neo4j.gds.scc.SccAlphaWriteConfig; import org.neo4j.gds.scc.SccWriteConfig; +import org.neo4j.gds.triangle.LocalClusteringCoefficientWriteConfig; import org.neo4j.gds.triangle.TriangleCountWriteConfig; import org.neo4j.gds.wcc.WccWriteConfig; @@ -545,6 +547,36 @@ public NodePropertyWriteResult triangleCount( ); } + public NodePropertyWriteResult localClusteringCoefficient( + String graphName, + LocalClusteringCoefficientWriteConfig config, + User user, + DatabaseId databaseId + ) { + + // 1. Run the algorithm and time the execution + var intermediateResult = runWithTiming( + () -> communityAlgorithmsFacade.localClusteringCoefficient(graphName, config, user, databaseId) + ); + var algorithmResult = intermediateResult.algorithmResult; + + return writeToDatabase( + algorithmResult, + config, + (result, configuration) -> NodePropertyValuesAdapter.adapt(result.localClusteringCoefficients()), + (result) -> new LocalClusteringCoefficientSpecificFields( + result.localClusteringCoefficients().size(), + result.averageClusteringCoefficient() + ), + intermediateResult.computeMilliseconds, + () -> LocalClusteringCoefficientSpecificFields.EMPTY, + "LocalClusteringCoefficientWrite", + config.writeConcurrency(), + config.writeProperty(), + config.arrowConnectionInfo() + ); + } + NodePropertyWriteResult writeToDatabase( AlgorithmComputationResult algorithmResult, diff --git a/proc/community/src/main/java/org/neo4j/gds/triangle/LocalClusteringCoefficientWriteProc.java b/proc/community/src/main/java/org/neo4j/gds/triangle/LocalClusteringCoefficientWriteProc.java index 402f09bb4e..bbf1da7807 100644 --- a/proc/community/src/main/java/org/neo4j/gds/triangle/LocalClusteringCoefficientWriteProc.java +++ b/proc/community/src/main/java/org/neo4j/gds/triangle/LocalClusteringCoefficientWriteProc.java @@ -20,10 +20,7 @@ package org.neo4j.gds.triangle; import org.neo4j.gds.BaseProc; -import org.neo4j.gds.core.write.NodePropertyExporterBuilder; -import org.neo4j.gds.executor.ExecutionContext; -import org.neo4j.gds.executor.MemoryEstimationExecutor; -import org.neo4j.gds.executor.ProcedureExecutor; +import org.neo4j.gds.procedures.GraphDataScience; import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientWriteResult; import org.neo4j.gds.results.MemoryEstimateResult; import org.neo4j.procedure.Context; @@ -41,7 +38,7 @@ public class LocalClusteringCoefficientWriteProc extends BaseProc { @Context - public NodePropertyExporterBuilder nodePropertyExporterBuilder; + public GraphDataScience facade; @Procedure(value = "gds.localClusteringCoefficient.write", mode = WRITE) @Description(DESCRIPTION) @@ -49,10 +46,8 @@ public Stream write( @Name(value = "graphName") String graphName, @Name(value = "configuration", defaultValue = "{}") Map configuration ) { - return new ProcedureExecutor<>( - new LocalClusteringCoefficientWriteSpec(), - executionContext() - ).compute(graphName, configuration); + return facade.community().localClusteringCoefficientWrite(graphName, configuration); + } @Procedure(value = "gds.localClusteringCoefficient.write.estimate", mode = READ) @@ -61,15 +56,7 @@ public Stream estimate( @Name(value = "graphNameOrConfiguration") Object graphNameOrConfiguration, @Name(value = "algoConfiguration") Map algoConfiguration ) { - return new MemoryEstimationExecutor<>( - new LocalClusteringCoefficientWriteSpec(), - executionContext(), - transactionContext() - ).computeEstimate(graphNameOrConfiguration, algoConfiguration); + return facade.community().localClusteringCoefficientEstimateWrite(graphNameOrConfiguration, algoConfiguration); } - @Override - public ExecutionContext executionContext() { - return super.executionContext().withNodePropertyExporterBuilder(nodePropertyExporterBuilder); - } } diff --git a/procedures/facade/src/main/java/org/neo4j/gds/procedures/community/CommunityProcedureFacade.java b/procedures/facade/src/main/java/org/neo4j/gds/procedures/community/CommunityProcedureFacade.java index 2199bcd5ea..a50293c0de 100644 --- a/procedures/facade/src/main/java/org/neo4j/gds/procedures/community/CommunityProcedureFacade.java +++ b/procedures/facade/src/main/java/org/neo4j/gds/procedures/community/CommunityProcedureFacade.java @@ -104,6 +104,7 @@ import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientMutateResult; import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientStatsResult; import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientStreamResult; +import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientWriteResult; import org.neo4j.gds.procedures.community.triangleCount.TriangleCountMutateResult; import org.neo4j.gds.procedures.community.triangleCount.TriangleCountStatsResult; import org.neo4j.gds.procedures.community.triangleCount.TriangleCountStreamResult; @@ -121,6 +122,7 @@ import org.neo4j.gds.triangle.LocalClusteringCoefficientMutateConfig; import org.neo4j.gds.triangle.LocalClusteringCoefficientStatsConfig; import org.neo4j.gds.triangle.LocalClusteringCoefficientStreamConfig; +import org.neo4j.gds.triangle.LocalClusteringCoefficientWriteConfig; import org.neo4j.gds.triangle.TriangleCountMutateConfig; import org.neo4j.gds.triangle.TriangleCountStatsConfig; import org.neo4j.gds.triangle.TriangleCountStreamConfig; @@ -1068,6 +1070,21 @@ public Stream localClusteringCoefficientS return Stream.of(LCCComputationResultTransformer.toStatsResult(computationResult, statsConfig)); } + public Stream localClusteringCoefficientWrite( + String graphName, + Map configuration + ) { + var writeConfig = createConfig(configuration, LocalClusteringCoefficientWriteConfig::of); + + var computationResult = writeBusinessFacade.localClusteringCoefficient( + graphName, + writeConfig, + user, + databaseId + ); + + return Stream.of(LCCComputationResultTransformer.toWriteResult(computationResult)); + } public Stream localClusteringCoefficientEstimateMutate( Object graphNameOrConfiguration, @@ -1077,6 +1094,14 @@ public Stream localClusteringCoefficientEstimateMutate( return Stream.of(estimateBusinessFacade.localClusteringCoefficient(graphNameOrConfiguration, config)); } + public Stream localClusteringCoefficientEstimateWrite( + Object graphNameOrConfiguration, + Map algoConfiguration + ) { + var config = createConfig(algoConfiguration, LocalClusteringCoefficientWriteConfig::of); + return Stream.of(estimateBusinessFacade.localClusteringCoefficient(graphNameOrConfiguration, config)); + } + public Stream localClusteringCoefficientEstimateStats( Object graphNameOrConfiguration, Map algoConfiguration diff --git a/procedures/facade/src/main/java/org/neo4j/gds/procedures/community/LCCComputationResultTransformer.java b/procedures/facade/src/main/java/org/neo4j/gds/procedures/community/LCCComputationResultTransformer.java index cb3bd8a8d6..bb6f5a8500 100644 --- a/procedures/facade/src/main/java/org/neo4j/gds/procedures/community/LCCComputationResultTransformer.java +++ b/procedures/facade/src/main/java/org/neo4j/gds/procedures/community/LCCComputationResultTransformer.java @@ -21,11 +21,13 @@ import org.neo4j.gds.algorithms.LocalClusteringCoefficientSpecificFields; import org.neo4j.gds.algorithms.NodePropertyMutateResult; +import org.neo4j.gds.algorithms.NodePropertyWriteResult; import org.neo4j.gds.algorithms.StatsResult; import org.neo4j.gds.algorithms.StreamComputationResult; import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientMutateResult; import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientStatsResult; import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientStreamResult; +import org.neo4j.gds.procedures.community.triangle.LocalClusteringCoefficientWriteResult; import org.neo4j.gds.triangle.LocalClusteringCoefficientMutateConfig; import org.neo4j.gds.triangle.LocalClusteringCoefficientResult; import org.neo4j.gds.triangle.LocalClusteringCoefficientStatsConfig; @@ -77,4 +79,19 @@ static LocalClusteringCoefficientStatsResult toStatsResult( ); } + static LocalClusteringCoefficientWriteResult toWriteResult( + NodePropertyWriteResult computationResult + ) { + return new LocalClusteringCoefficientWriteResult( + computationResult.algorithmSpecificFields().averageClusteringCoefficient(), + computationResult.algorithmSpecificFields().nodeCount(), + computationResult.preProcessingMillis(), + computationResult.computeMillis(), + computationResult.writeMillis(), + computationResult.nodePropertiesWritten(), + computationResult.configuration().toMap() + ); + } + + } diff --git a/procedures/facade/src/main/java/org/neo4j/gds/procedures/community/triangle/LocalClusteringCoefficientWriteResult.java b/procedures/facade/src/main/java/org/neo4j/gds/procedures/community/triangle/LocalClusteringCoefficientWriteResult.java index 24ab7f2140..118357ad13 100644 --- a/procedures/facade/src/main/java/org/neo4j/gds/procedures/community/triangle/LocalClusteringCoefficientWriteResult.java +++ b/procedures/facade/src/main/java/org/neo4j/gds/procedures/community/triangle/LocalClusteringCoefficientWriteResult.java @@ -29,7 +29,7 @@ public final class LocalClusteringCoefficientWriteResult extends LocalClustering public long writeMillis; public long nodePropertiesWritten; - private LocalClusteringCoefficientWriteResult( + public LocalClusteringCoefficientWriteResult( double averageClusteringCoefficient, long nodeCount, long preProcessingMillis,