From 08c22c62691380e3780231cb6b0bc81b8756705e Mon Sep 17 00:00:00 2001 From: Lasse Westh-Nielsen Date: Thu, 30 May 2024 15:09:27 +0200 Subject: [PATCH] migrate celf write --- ...alityAlgorithmsEstimateBusinessFacade.java | 17 ----- ...ntralityAlgorithmsWriteBusinessFacade.java | 44 ------------- .../specificfields/CELFSpecificFields.java | 42 ------------ .../BetweennessCentralityWriteStep.java | 4 +- .../algorithms/centrality/CelfWriteStep.java | 64 +++++++++++++++++++ ...lityAlgorithmsWriteModeBusinessFacade.java | 21 ++++++ .../ClosenessCentralityWriteStep.java | 4 +- .../centrality/DegreeCentralityWriteStep.java | 4 +- .../HarmonicCentralityWriteStep.java | 4 +- .../centrality/WriteToDatabase.java | 8 +-- .../influenceMaximization/CELFWriteProc.java | 6 +- .../influenceMaximization/CELFWriteSpec.java | 2 +- .../centrality}/CELFWriteResult.java | 14 +++- .../CelfResultBuilderForWriteMode.java | 61 ++++++++++++++++++ .../centrality/CentralityProcedureFacade.java | 64 ++++++++++++++----- .../CELFComputationalResultTransformer.java | 44 ------------- .../centrality/CentralityProcedureFacade.java | 26 -------- 17 files changed, 223 insertions(+), 206 deletions(-) delete mode 100644 algo/src/main/java/org/neo4j/gds/algorithms/centrality/specificfields/CELFSpecificFields.java create mode 100644 applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CelfWriteStep.java rename procedures/{facade/src/main/java/org/neo4j/gds/procedures/centrality/celf => algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality}/CELFWriteResult.java (82%) create mode 100644 procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CelfResultBuilderForWriteMode.java delete mode 100644 procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/CELFComputationalResultTransformer.java diff --git a/algo/src/main/java/org/neo4j/gds/algorithms/centrality/CentralityAlgorithmsEstimateBusinessFacade.java b/algo/src/main/java/org/neo4j/gds/algorithms/centrality/CentralityAlgorithmsEstimateBusinessFacade.java index 6f3ba0a828..e3a826056c 100644 --- a/algo/src/main/java/org/neo4j/gds/algorithms/centrality/CentralityAlgorithmsEstimateBusinessFacade.java +++ b/algo/src/main/java/org/neo4j/gds/algorithms/centrality/CentralityAlgorithmsEstimateBusinessFacade.java @@ -21,13 +21,9 @@ import org.neo4j.gds.algorithms.estimation.AlgorithmEstimator; import org.neo4j.gds.applications.algorithms.machinery.MemoryEstimateResult; -import org.neo4j.gds.influenceMaximization.CELFMemoryEstimateDefinition; -import org.neo4j.gds.influenceMaximization.InfluenceMaximizationBaseConfig; import org.neo4j.gds.pagerank.PageRankConfig; import org.neo4j.gds.pagerank.PageRankMemoryEstimateDefinition; -import java.util.Optional; - public class CentralityAlgorithmsEstimateBusinessFacade { private final AlgorithmEstimator algorithmEstimator; @@ -38,19 +34,6 @@ public CentralityAlgorithmsEstimateBusinessFacade( this.algorithmEstimator = algorithmEstimator; } - public MemoryEstimateResult celf( - Object graphNameOrConfiguration, - C configuration - ) { - - return algorithmEstimator.estimate( - graphNameOrConfiguration, - configuration, - Optional.empty(), - new CELFMemoryEstimateDefinition(configuration.toParameters()) - ); - } - public MemoryEstimateResult pageRank( Object graphNameOrConfiguration, C configuration diff --git a/algo/src/main/java/org/neo4j/gds/algorithms/centrality/CentralityAlgorithmsWriteBusinessFacade.java b/algo/src/main/java/org/neo4j/gds/algorithms/centrality/CentralityAlgorithmsWriteBusinessFacade.java index 2eb0b38c1b..7542236b6e 100644 --- a/algo/src/main/java/org/neo4j/gds/algorithms/centrality/CentralityAlgorithmsWriteBusinessFacade.java +++ b/algo/src/main/java/org/neo4j/gds/algorithms/centrality/CentralityAlgorithmsWriteBusinessFacade.java @@ -22,19 +22,15 @@ import org.jetbrains.annotations.NotNull; import org.neo4j.gds.algorithms.AlgorithmComputationResult; import org.neo4j.gds.algorithms.NodePropertyWriteResult; -import org.neo4j.gds.algorithms.centrality.specificfields.CELFSpecificFields; import org.neo4j.gds.algorithms.centrality.specificfields.CentralityStatisticsSpecificFields; import org.neo4j.gds.algorithms.centrality.specificfields.PageRankSpecificFields; import org.neo4j.gds.algorithms.runner.AlgorithmResultWithTiming; -import org.neo4j.gds.algorithms.runner.AlgorithmRunner; import org.neo4j.gds.algorithms.writeservices.WriteNodePropertyService; import org.neo4j.gds.api.ResultStore; import org.neo4j.gds.config.AlgoBaseConfig; import org.neo4j.gds.config.ArrowConnectionInfo; import org.neo4j.gds.core.concurrency.Concurrency; import org.neo4j.gds.core.concurrency.DefaultPool; -import org.neo4j.gds.influenceMaximization.CELFNodeProperties; -import org.neo4j.gds.influenceMaximization.InfluenceMaximizationWriteConfig; import org.neo4j.gds.pagerank.PageRankResult; import org.neo4j.gds.pagerank.PageRankWriteConfig; import org.neo4j.gds.result.CentralityStatistics; @@ -151,46 +147,6 @@ private NodePropertyWriteResult pageRankVariant( }).orElseGet(() -> NodePropertyWriteResult.empty(PageRankSpecificFields.EMPTY, configuration)); } - public NodePropertyWriteResult celf( - String graphName, - InfluenceMaximizationWriteConfig configuration - ) { - // 1. Run the algorithm and time the execution - var intermediateResult = AlgorithmRunner.runWithTiming( - () -> centralityAlgorithmsFacade.celf(graphName, configuration) - ); - var algorithmResult = intermediateResult.algorithmResult; - - var writeResultBuilder = NodePropertyWriteResult.builder() - .computeMillis(intermediateResult.computeMilliseconds) - .postProcessingMillis(0L) - .configuration(configuration); - - algorithmResult.result().ifPresentOrElse( - result -> { - var nodeCount = algorithmResult.graph().nodeCount(); - var nodeProperties = new CELFNodeProperties(result.seedSetNodes(), nodeCount); - var writeResult = writeNodePropertyService.write( - algorithmResult.graph(), - algorithmResult.graphStore(), - nodeProperties, - configuration.writeConcurrency(), - configuration.writeProperty(), - "CELFWrite", - configuration.arrowConnectionInfo(), - configuration.resolveResultStore(algorithmResult.resultStore()), - configuration.jobId() - ); - writeResultBuilder.writeMillis(writeResult.writeMilliseconds()); - writeResultBuilder.nodePropertiesWritten(writeResult.nodePropertiesWritten()); - writeResultBuilder.algorithmSpecificFields(new CELFSpecificFields(result.totalSpread(), nodeCount)); - }, - () -> writeResultBuilder.algorithmSpecificFields(CELFSpecificFields.EMPTY) - ); - - return writeResultBuilder.build(); - } - NodePropertyWriteResult writeToDatabase( AlgorithmComputationResult algorithmResult, CONFIG configuration, diff --git a/algo/src/main/java/org/neo4j/gds/algorithms/centrality/specificfields/CELFSpecificFields.java b/algo/src/main/java/org/neo4j/gds/algorithms/centrality/specificfields/CELFSpecificFields.java deleted file mode 100644 index 61e09ef3be..0000000000 --- a/algo/src/main/java/org/neo4j/gds/algorithms/centrality/specificfields/CELFSpecificFields.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) "Neo4j" - * Neo4j Sweden AB [http://neo4j.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.gds.algorithms.centrality.specificfields; - -public class CELFSpecificFields { - - private final double totalSpread; - private final long nodeCount; - public static CELFSpecificFields EMPTY =new CELFSpecificFields(0D,0); - - - public CELFSpecificFields(double totalSpread, long nodeCount){ - this.totalSpread=totalSpread; - this.nodeCount=nodeCount; - } - - public long nodeCount(){ - return nodeCount; - } - - public double totalSpread(){ - return totalSpread; - } - -} diff --git a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/BetweennessCentralityWriteStep.java b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/BetweennessCentralityWriteStep.java index cf3e0ddd27..58506fe548 100644 --- a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/BetweennessCentralityWriteStep.java +++ b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/BetweennessCentralityWriteStep.java @@ -54,8 +54,8 @@ public NodePropertiesWritten execute( configuration, configuration, BetweennessCentrality, - result, - jobId + jobId, + result.nodePropertyValues() ); } } diff --git a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CelfWriteStep.java b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CelfWriteStep.java new file mode 100644 index 0000000000..1ab01dcb32 --- /dev/null +++ b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CelfWriteStep.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.gds.applications.algorithms.centrality; + +import org.neo4j.gds.api.Graph; +import org.neo4j.gds.api.GraphStore; +import org.neo4j.gds.api.ResultStore; +import org.neo4j.gds.applications.algorithms.machinery.MutateOrWriteStep; +import org.neo4j.gds.applications.algorithms.metadata.NodePropertiesWritten; +import org.neo4j.gds.core.utils.progress.JobId; +import org.neo4j.gds.influenceMaximization.CELFNodeProperties; +import org.neo4j.gds.influenceMaximization.CELFResult; +import org.neo4j.gds.influenceMaximization.InfluenceMaximizationWriteConfig; + +import static org.neo4j.gds.applications.algorithms.metadata.LabelForProgressTracking.CELF; + +class CelfWriteStep implements MutateOrWriteStep { + private final WriteToDatabase writeToDatabase; + private final InfluenceMaximizationWriteConfig configuration; + + CelfWriteStep(WriteToDatabase writeToDatabase, InfluenceMaximizationWriteConfig configuration) { + this.writeToDatabase = writeToDatabase; + this.configuration = configuration; + } + + @Override + public NodePropertiesWritten execute( + Graph graph, + GraphStore graphStore, + ResultStore resultStore, + CELFResult result, + JobId jobId + ) { + var nodePropertyValues = new CELFNodeProperties(result.seedSetNodes(), graph.nodeCount()); + + return writeToDatabase.perform( + graph, + graphStore, + resultStore, + configuration, + configuration, + CELF, + jobId, + nodePropertyValues + ); + } +} diff --git a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithmsWriteModeBusinessFacade.java b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithmsWriteModeBusinessFacade.java index 0eed2ef7cd..6a8ac0ffbd 100644 --- a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithmsWriteModeBusinessFacade.java +++ b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/CentralityAlgorithmsWriteModeBusinessFacade.java @@ -31,11 +31,14 @@ import org.neo4j.gds.degree.DegreeCentralityWriteConfig; import org.neo4j.gds.harmonic.HarmonicCentralityWriteConfig; import org.neo4j.gds.harmonic.HarmonicResult; +import org.neo4j.gds.influenceMaximization.CELFResult; +import org.neo4j.gds.influenceMaximization.InfluenceMaximizationWriteConfig; import org.neo4j.gds.logging.Log; import java.util.Optional; import static org.neo4j.gds.applications.algorithms.metadata.LabelForProgressTracking.BetweennessCentrality; +import static org.neo4j.gds.applications.algorithms.metadata.LabelForProgressTracking.CELF; import static org.neo4j.gds.applications.algorithms.metadata.LabelForProgressTracking.ClosenessCentrality; import static org.neo4j.gds.applications.algorithms.metadata.LabelForProgressTracking.DegreeCentrality; import static org.neo4j.gds.applications.algorithms.metadata.LabelForProgressTracking.HarmonicCentrality; @@ -94,6 +97,24 @@ public RESULT betweennessCentrality( ); } + public RESULT celf( + GraphName graphName, + CONFIGURATION configuration, + ResultBuilder resultBuilder + ) { + var writeStep = new CelfWriteStep(writeToDatabase, configuration); + + return algorithmProcessingTemplate.processAlgorithm( + graphName, + configuration, + CELF, + () -> estimationFacade.celf(configuration), + graph -> centralityAlgorithms.celf(graph, configuration), + Optional.of(writeStep), + resultBuilder + ); + } + public RESULT closenessCentrality( GraphName graphName, ClosenessCentralityWriteConfig configuration, diff --git a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/ClosenessCentralityWriteStep.java b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/ClosenessCentralityWriteStep.java index 40956cd15f..8d93fa6f2a 100644 --- a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/ClosenessCentralityWriteStep.java +++ b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/ClosenessCentralityWriteStep.java @@ -54,8 +54,8 @@ public NodePropertiesWritten execute( configuration, configuration, ClosenessCentrality, - result, - jobId + jobId, + result.nodePropertyValues() ); } } diff --git a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/DegreeCentralityWriteStep.java b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/DegreeCentralityWriteStep.java index 86058b8480..fc62d7257a 100644 --- a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/DegreeCentralityWriteStep.java +++ b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/DegreeCentralityWriteStep.java @@ -54,8 +54,8 @@ public NodePropertiesWritten execute( configuration, configuration, DegreeCentrality, - result, - jobId + jobId, + result.nodePropertyValues() ); } } diff --git a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/HarmonicCentralityWriteStep.java b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/HarmonicCentralityWriteStep.java index b6edbefc5e..7b0be87e35 100644 --- a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/HarmonicCentralityWriteStep.java +++ b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/HarmonicCentralityWriteStep.java @@ -54,8 +54,8 @@ public NodePropertiesWritten execute( configuration, configuration, HarmonicCentrality, - result, - jobId + jobId, + result.nodePropertyValues() ); } } diff --git a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/WriteToDatabase.java b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/WriteToDatabase.java index af8fffb751..2df46e6a97 100644 --- a/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/WriteToDatabase.java +++ b/applications/algorithms/centrality/src/main/java/org/neo4j/gds/applications/algorithms/centrality/WriteToDatabase.java @@ -19,11 +19,11 @@ */ package org.neo4j.gds.applications.algorithms.centrality; -import org.neo4j.gds.algorithms.centrality.CentralityAlgorithmResult; import org.neo4j.gds.algorithms.writeservices.WriteNodePropertyService; import org.neo4j.gds.api.Graph; import org.neo4j.gds.api.GraphStore; import org.neo4j.gds.api.ResultStore; +import org.neo4j.gds.api.properties.nodes.NodePropertyValues; import org.neo4j.gds.applications.algorithms.metadata.LabelForProgressTracking; import org.neo4j.gds.applications.algorithms.metadata.NodePropertiesWritten; import org.neo4j.gds.config.WriteConfig; @@ -44,13 +44,13 @@ NodePropertiesWritten perform( WriteConfig writeConfiguration, WritePropertyConfig writePropertyConfiguration, LabelForProgressTracking label, - CentralityAlgorithmResult result, - JobId jobId + JobId jobId, + NodePropertyValues nodePropertyValues ) { var writeNodePropertyResult = writeNodePropertyService.write( graph, graphStore, - result.nodePropertyValues(), + nodePropertyValues, writeConfiguration.writeConcurrency(), writePropertyConfiguration.writeProperty(), label.value, diff --git a/proc/centrality/src/main/java/org/neo4j/gds/influenceMaximization/CELFWriteProc.java b/proc/centrality/src/main/java/org/neo4j/gds/influenceMaximization/CELFWriteProc.java index 686526cc0a..8de4d60703 100644 --- a/proc/centrality/src/main/java/org/neo4j/gds/influenceMaximization/CELFWriteProc.java +++ b/proc/centrality/src/main/java/org/neo4j/gds/influenceMaximization/CELFWriteProc.java @@ -20,7 +20,7 @@ package org.neo4j.gds.influenceMaximization; import org.neo4j.gds.procedures.GraphDataScienceProcedures; -import org.neo4j.gds.procedures.centrality.celf.CELFWriteResult; +import org.neo4j.gds.procedures.algorithms.centrality.CELFWriteResult; import org.neo4j.gds.applications.algorithms.machinery.MemoryEstimateResult; import org.neo4j.procedure.Context; import org.neo4j.procedure.Description; @@ -46,7 +46,7 @@ public Stream write( @Name(value = "graphName") String graphName, @Name(value = "configuration", defaultValue = "{}") Map configuration ) { - return facade.centrality().celfWrite(graphName, configuration); + return facade.algorithms().centrality().celfWrite(graphName, configuration); } @Procedure(name = "gds.influenceMaximization.celf.write.estimate", mode = READ) @@ -55,7 +55,7 @@ public Stream estimate( @Name(value = "graphNameOrConfiguration") Object graphNameOrConfiguration, @Name(value = "algoConfiguration") Map algoConfiguration ) { - return facade.centrality().celfWriteEstimate(graphNameOrConfiguration, algoConfiguration); + return facade.algorithms().centrality().celfWriteEstimate(graphNameOrConfiguration, algoConfiguration); } @Procedure( diff --git a/proc/centrality/src/main/java/org/neo4j/gds/influenceMaximization/CELFWriteSpec.java b/proc/centrality/src/main/java/org/neo4j/gds/influenceMaximization/CELFWriteSpec.java index ef84cd0e53..efd7ffb913 100644 --- a/proc/centrality/src/main/java/org/neo4j/gds/influenceMaximization/CELFWriteSpec.java +++ b/proc/centrality/src/main/java/org/neo4j/gds/influenceMaximization/CELFWriteSpec.java @@ -25,7 +25,7 @@ import org.neo4j.gds.executor.ExecutionContext; import org.neo4j.gds.executor.GdsCallable; import org.neo4j.gds.procedures.algorithms.configuration.NewConfigFunction; -import org.neo4j.gds.procedures.centrality.celf.CELFWriteResult; +import org.neo4j.gds.procedures.algorithms.centrality.CELFWriteResult; import java.util.stream.Stream; diff --git a/procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/celf/CELFWriteResult.java b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CELFWriteResult.java similarity index 82% rename from procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/celf/CELFWriteResult.java rename to procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CELFWriteResult.java index 1bf9664c65..5167292e66 100644 --- a/procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/celf/CELFWriteResult.java +++ b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CELFWriteResult.java @@ -17,8 +17,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.neo4j.gds.procedures.centrality.celf; +package org.neo4j.gds.procedures.algorithms.centrality; +import org.neo4j.gds.applications.algorithms.machinery.AlgorithmProcessingTimings; import org.neo4j.gds.result.AbstractResultBuilder; import java.util.Map; @@ -51,6 +52,17 @@ public static Builder builder() { return new Builder(); } + static CELFWriteResult emptyFrom(AlgorithmProcessingTimings timings, Map configurationMap) { + return new CELFWriteResult( + timings.mutateOrWriteMillis, + 0, + timings.computeMillis, + 0, + 0, + configurationMap + ); + } + public static class Builder extends AbstractResultBuilder { private double totalSpread; diff --git a/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CelfResultBuilderForWriteMode.java b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CelfResultBuilderForWriteMode.java new file mode 100644 index 0000000000..f1382f584d --- /dev/null +++ b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CelfResultBuilderForWriteMode.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.gds.procedures.algorithms.centrality; + +import org.neo4j.gds.api.Graph; +import org.neo4j.gds.api.GraphStore; +import org.neo4j.gds.applications.algorithms.machinery.AlgorithmProcessingTimings; +import org.neo4j.gds.applications.algorithms.machinery.ResultBuilder; +import org.neo4j.gds.applications.algorithms.metadata.NodePropertiesWritten; +import org.neo4j.gds.influenceMaximization.CELFResult; +import org.neo4j.gds.influenceMaximization.InfluenceMaximizationWriteConfig; + +import java.util.Optional; +import java.util.stream.Stream; + +class CelfResultBuilderForWriteMode implements ResultBuilder, NodePropertiesWritten> { + @Override + public Stream build( + Graph graph, + GraphStore graphStore, + InfluenceMaximizationWriteConfig configuration, + Optional result, + AlgorithmProcessingTimings timings, + Optional nodePropertiesWritten + ) { + if (result.isEmpty()) return Stream.of(CELFWriteResult.emptyFrom( + timings, + configuration.toMap() + )); + + var celfResult = result.get(); + + return Stream.of( + new CELFWriteResult( + timings.mutateOrWriteMillis, + nodePropertiesWritten.orElseThrow().value, + timings.computeMillis, + celfResult.totalSpread(), + graph.nodeCount(), + configuration.toMap() + ) + ); + } +} diff --git a/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CentralityProcedureFacade.java b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CentralityProcedureFacade.java index 377dc92395..767c2e28a8 100644 --- a/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CentralityProcedureFacade.java +++ b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/CentralityProcedureFacade.java @@ -41,6 +41,7 @@ import org.neo4j.gds.harmonic.HarmonicCentralityWriteConfig; import org.neo4j.gds.influenceMaximization.InfluenceMaximizationStatsConfig; import org.neo4j.gds.influenceMaximization.InfluenceMaximizationStreamConfig; +import org.neo4j.gds.influenceMaximization.InfluenceMaximizationWriteConfig; import org.neo4j.gds.procedures.algorithms.centrality.stubs.BetaClosenessCentralityMutateStub; import org.neo4j.gds.procedures.algorithms.centrality.stubs.BetweennessCentralityMutateStub; import org.neo4j.gds.procedures.algorithms.centrality.stubs.CelfMutateStub; @@ -171,6 +172,22 @@ public Stream alphaHarmonicCentralityStream( ); } + public Stream alphaHarmonicCentralityWrite( + String graphName, + Map configuration + ) { + var shouldComputeCentralityDistribution = procedureReturnColumns.contains("centralityDistribution"); + var resultBuilder = new AlphaHarmonicCentralityResultBuilderForWriteMode(shouldComputeCentralityDistribution); + + return writeModeRunner.runWriteModeAlgorithm( + graphName, + configuration, + DeprecatedTieredHarmonicCentralityWriteConfig::of, + writeMode()::harmonicCentrality, + resultBuilder + ); + } + public BetaClosenessCentralityMutateStub betaClosenessCentralityMutateStub() { return betaClosenessCentralityMutateStub; } @@ -356,6 +373,37 @@ public Stream celfStreamEstimate( return Stream.of(result); } + public Stream celfWrite( + String graphName, + Map configuration + ) { + var resultBuilder = new CelfResultBuilderForWriteMode(); + + return writeModeRunner.runWriteModeAlgorithm( + graphName, + configuration, + InfluenceMaximizationWriteConfig::of, + writeMode()::celf, + resultBuilder + ); + } + + public Stream celfWriteEstimate( + Object graphNameOrConfiguration, + Map algorithmConfiguration + ) { + var result = estimationModeRunner.runEstimation( + algorithmConfiguration, + InfluenceMaximizationWriteConfig::of, + configuration -> estimationMode().celf( + configuration, + graphNameOrConfiguration + ) + ); + + return Stream.of(result); + } + public ClosenessCentralityMutateStub closenessCentralityMutateStub() { return closenessCentralityMutateStub; } @@ -539,22 +587,6 @@ public Stream harmonicCentralityWrite(String graphName, M ); } - public Stream alphaHarmonicCentralityWrite( - String graphName, - Map configuration - ) { - var shouldComputeCentralityDistribution = procedureReturnColumns.contains("centralityDistribution"); - var resultBuilder = new AlphaHarmonicCentralityResultBuilderForWriteMode(shouldComputeCentralityDistribution); - - return writeModeRunner.runWriteModeAlgorithm( - graphName, - configuration, - DeprecatedTieredHarmonicCentralityWriteConfig::of, - writeMode()::harmonicCentrality, - resultBuilder - ); - } - private CentralityAlgorithmsEstimationModeBusinessFacade estimationMode() { return applicationsFacade.centrality().estimate(); } diff --git a/procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/CELFComputationalResultTransformer.java b/procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/CELFComputationalResultTransformer.java deleted file mode 100644 index f282bba5b2..0000000000 --- a/procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/CELFComputationalResultTransformer.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) "Neo4j" - * Neo4j Sweden AB [http://neo4j.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.gds.procedures.centrality; - -import org.neo4j.gds.algorithms.NodePropertyWriteResult; -import org.neo4j.gds.algorithms.centrality.specificfields.CELFSpecificFields; -import org.neo4j.gds.procedures.centrality.celf.CELFWriteResult; - -final class CELFComputationalResultTransformer { - - private CELFComputationalResultTransformer() {} - - static CELFWriteResult toWriteResult( - NodePropertyWriteResult mutateResult - ) { - return new CELFWriteResult( - mutateResult.writeMillis(), - mutateResult.nodePropertiesWritten(), - mutateResult.computeMillis(), - mutateResult.algorithmSpecificFields().totalSpread(), - mutateResult.algorithmSpecificFields().nodeCount(), - mutateResult.configuration().toMap() - ); - } - - -} diff --git a/procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/CentralityProcedureFacade.java b/procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/CentralityProcedureFacade.java index 7923cb1c40..5e27107844 100644 --- a/procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/CentralityProcedureFacade.java +++ b/procedures/facade/src/main/java/org/neo4j/gds/procedures/centrality/CentralityProcedureFacade.java @@ -26,14 +26,12 @@ import org.neo4j.gds.algorithms.centrality.CentralityAlgorithmsWriteBusinessFacade; import org.neo4j.gds.api.ProcedureReturnColumns; import org.neo4j.gds.applications.algorithms.machinery.MemoryEstimateResult; -import org.neo4j.gds.influenceMaximization.InfluenceMaximizationWriteConfig; import org.neo4j.gds.pagerank.PageRankMutateConfig; import org.neo4j.gds.pagerank.PageRankStatsConfig; import org.neo4j.gds.pagerank.PageRankStreamConfig; import org.neo4j.gds.pagerank.PageRankWriteConfig; import org.neo4j.gds.procedures.algorithms.centrality.CentralityStreamResult; import org.neo4j.gds.procedures.algorithms.configuration.ConfigurationCreator; -import org.neo4j.gds.procedures.centrality.celf.CELFWriteResult; import org.neo4j.gds.procedures.centrality.pagerank.PageRankComputationalResultTransformer; import org.neo4j.gds.procedures.centrality.pagerank.PageRankMutateResult; import org.neo4j.gds.procedures.centrality.pagerank.PageRankStatsResult; @@ -71,30 +69,6 @@ public CentralityProcedureFacade( this.estimateBusinessFacade = estimateBusinessFacade; } - public Stream celfWrite( - String graphName, - Map configuration - ) { - var config = configurationCreator.createConfiguration(configuration, InfluenceMaximizationWriteConfig::of); - - var writeResult = writeBusinessFacade.celf( - graphName, - config - ); - - return Stream.of(CELFComputationalResultTransformer.toWriteResult(writeResult)); - } - - public Stream celfWriteEstimate( - Object graphNameOrConfiguration, - Map configuration - ) { - var config = configurationCreator.createConfiguration(configuration, InfluenceMaximizationWriteConfig::of); - - return Stream.of(estimateBusinessFacade.celf(graphNameOrConfiguration, config)); - - } - public Stream pageRankStream( String graphName, Map configuration