From 0c1077223dfb84990f799c6ff97ddd4ff3dd9d02 Mon Sep 17 00:00:00 2001 From: ioannispan Date: Thu, 29 Aug 2024 14:10:09 +0200 Subject: [PATCH] Remove MutateStubConfigurationValidationDecorator.java --- .../gds/pagerank/PageRankMutateConfig.java | 14 +- .../gds/pagerank/PageRankStatsConfig.java | 15 +- .../gds/pagerank/PageRankStreamConfig.java | 14 +- .../gds/pagerank/PageRankWriteConfig.java | 13 +- .../ConfigurationParsersForMutateMode.java | 6 +- .../gds/pagerank/EigenVectorMutateSpec.java | 7 +- .../gds/pagerank/EigenVectorStatsSpec.java | 7 +- .../gds/pagerank/EigenVectorStreamSpec.java | 7 +- .../gds/pagerank/EigenVectorWriteSpec.java | 7 +- .../gds/pagerank/PageRankMutateSpec.java | 2 +- .../neo4j/gds/pagerank/PageRankStatsSpec.java | 4 +- .../gds/pagerank/PageRankStreamSpec.java | 4 +- .../neo4j/gds/pagerank/PageRankWriteSpec.java | 4 +- .../centrality/CentralityProcedureFacade.java | 51 +++---- ...eStubConfigurationValidationDecorator.java | 74 ---------- .../centrality/stubs/PageRankMutateStub.java | 15 +- ...bConfigurationValidationDecoratorTest.java | 134 ------------------ 17 files changed, 102 insertions(+), 276 deletions(-) delete mode 100644 procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/MutateStubConfigurationValidationDecorator.java delete mode 100644 procedures/algorithms-facade/src/test/java/org/neo4j/gds/procedures/algorithms/centrality/MutateStubConfigurationValidationDecoratorTest.java diff --git a/algo/src/main/java/org/neo4j/gds/pagerank/PageRankMutateConfig.java b/algo/src/main/java/org/neo4j/gds/pagerank/PageRankMutateConfig.java index 71b2d2d8e7..1d30e005aa 100644 --- a/algo/src/main/java/org/neo4j/gds/pagerank/PageRankMutateConfig.java +++ b/algo/src/main/java/org/neo4j/gds/pagerank/PageRankMutateConfig.java @@ -26,7 +26,19 @@ @Configuration public interface PageRankMutateConfig extends PageRankConfig, MutateNodePropertyConfig { - static PageRankMutateConfig of(CypherMapWrapper userInput) { + private static PageRankMutateConfig of(CypherMapWrapper userInput, boolean checkDampingFactor) { + if (checkDampingFactor && userInput.containsKey("dampingFactor")) { + throw new IllegalArgumentException("Unexpected configuration key: dampingFactor"); + } + return new PageRankMutateConfigImpl(userInput); } + + static PageRankMutateConfig configWithDampingFactor(CypherMapWrapper userInput) { + return of(userInput, false); + } + + static PageRankMutateConfig configWithoutDampingFactor(CypherMapWrapper userInput) { + return of(userInput, true); + } } diff --git a/algo/src/main/java/org/neo4j/gds/pagerank/PageRankStatsConfig.java b/algo/src/main/java/org/neo4j/gds/pagerank/PageRankStatsConfig.java index 1fb0e13706..d8b8111b61 100644 --- a/algo/src/main/java/org/neo4j/gds/pagerank/PageRankStatsConfig.java +++ b/algo/src/main/java/org/neo4j/gds/pagerank/PageRankStatsConfig.java @@ -25,7 +25,20 @@ @Configuration public interface PageRankStatsConfig extends PageRankConfig { - static PageRankStatsConfig of(CypherMapWrapper userInput) { + private static PageRankStatsConfig of(CypherMapWrapper userInput, boolean checkDampingFactor) { + if (checkDampingFactor && userInput.containsKey("dampingFactor")) { + throw new IllegalArgumentException("Unexpected configuration key: dampingFactor"); + } return new PageRankStatsConfigImpl(userInput); } + + static PageRankStatsConfig configWithDampingFactor(CypherMapWrapper userInput) { + return of(userInput, false); + } + + static PageRankStatsConfig configWithoutDampingFactor(CypherMapWrapper userInput) { + return of(userInput, true); + } + + } diff --git a/algo/src/main/java/org/neo4j/gds/pagerank/PageRankStreamConfig.java b/algo/src/main/java/org/neo4j/gds/pagerank/PageRankStreamConfig.java index 7956b5fed6..1e89175550 100644 --- a/algo/src/main/java/org/neo4j/gds/pagerank/PageRankStreamConfig.java +++ b/algo/src/main/java/org/neo4j/gds/pagerank/PageRankStreamConfig.java @@ -25,7 +25,19 @@ @Configuration public interface PageRankStreamConfig extends PageRankConfig { - static PageRankStreamConfig of(CypherMapWrapper userInput) { + private static PageRankStreamConfig of(CypherMapWrapper userInput, boolean checkDampingFactor) { + if (checkDampingFactor && userInput.containsKey("dampingFactor")) { + throw new IllegalArgumentException("Unexpected configuration key: dampingFactor"); + } + return new PageRankStreamConfigImpl(userInput); } + + static PageRankStreamConfig configWithDampingFactor(CypherMapWrapper userInput) { + return of(userInput, false); + } + + static PageRankStreamConfig configWithoutDampingFactor(CypherMapWrapper userInput) { + return of(userInput, true); + } } diff --git a/algo/src/main/java/org/neo4j/gds/pagerank/PageRankWriteConfig.java b/algo/src/main/java/org/neo4j/gds/pagerank/PageRankWriteConfig.java index aff8436cf6..8fbec11dbe 100644 --- a/algo/src/main/java/org/neo4j/gds/pagerank/PageRankWriteConfig.java +++ b/algo/src/main/java/org/neo4j/gds/pagerank/PageRankWriteConfig.java @@ -26,7 +26,18 @@ @Configuration public interface PageRankWriteConfig extends PageRankConfig, WritePropertyConfig { - static PageRankWriteConfig of(CypherMapWrapper userInput) { + private static PageRankWriteConfig of(CypherMapWrapper userInput, boolean checkDampingFactor) { + if (checkDampingFactor && userInput.containsKey("dampingFactor")) { + throw new IllegalArgumentException("Unexpected configuration key: dampingFactor"); + } return new PageRankWriteConfigImpl(userInput); } + + static PageRankWriteConfig configWithDampingFactor(CypherMapWrapper userInput) { + return of(userInput, false); + } + + static PageRankWriteConfig configWithoutDampingFactor(CypherMapWrapper userInput) { + return of(userInput, true); + } } diff --git a/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/ConfigurationParsersForMutateMode.java b/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/ConfigurationParsersForMutateMode.java index 6df84e1c0e..5341c158b5 100644 --- a/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/ConfigurationParsersForMutateMode.java +++ b/pipeline/src/main/java/org/neo4j/gds/ml/pipeline/ConfigurationParsersForMutateMode.java @@ -79,7 +79,7 @@ public Function lookup(Algorithm algorithm) { return switch (algorithm) { case AllShortestPaths -> null; case ApproximateMaximumKCut -> ApproxMaxKCutMutateConfig::of; - case ArticleRank -> PageRankMutateConfig::of; + case ArticleRank -> PageRankMutateConfig::configWithDampingFactor; case ArticulationPoints -> ArticulationPointsMutateConfig::of; case AStar -> ShortestPathAStarMutateConfig::of; case BellmanFord -> AllShortestPathsBellmanFordMutateConfig::of; @@ -94,7 +94,7 @@ public Function lookup(Algorithm algorithm) { case DeltaStepping -> AllShortestPathsDeltaMutateConfig::of; case DFS -> DfsMutateConfig::of; case Dijkstra -> ShortestPathDijkstraMutateConfig::of; - case EigenVector -> PageRankMutateConfig::of; + case EigenVector -> PageRankMutateConfig::configWithoutDampingFactor; case FastRP -> FastRPMutateConfig::of; case FilteredKNN -> FilteredKnnMutateConfig::of; case FilteredNodeSimilarity -> FilteredNodeSimilarityMutateConfig::of; @@ -118,7 +118,7 @@ public Function lookup(Algorithm algorithm) { case ModularityOptimization -> ModularityOptimizationMutateConfig::of; case NodeSimilarity -> NodeSimilarityMutateConfig::of; case Node2Vec -> Node2VecMutateConfig::of; - case PageRank -> PageRankMutateConfig::of; + case PageRank -> PageRankMutateConfig::configWithDampingFactor; case RandomWalk -> null; case ScaleProperties -> ScalePropertiesMutateConfig::of; case SCC -> SccMutateConfig::of; diff --git a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorMutateSpec.java b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorMutateSpec.java index 50050f95ea..29c5d0a7aa 100644 --- a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorMutateSpec.java +++ b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorMutateSpec.java @@ -40,12 +40,7 @@ public PageRankAlgorithmFactory algorithmFactory(Execution } @Override public NewConfigFunction newConfigFunction() { - return (___, config) -> { - if (config.containsKey("dampingFactor")) { - throw new IllegalArgumentException("Unexpected configuration key: dampingFactor"); - } - return PageRankMutateConfig.of(config); - }; + return (___, config) -> PageRankMutateConfig.configWithoutDampingFactor(config); } diff --git a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorStatsSpec.java b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorStatsSpec.java index 6c66d97d91..0fd614c13d 100644 --- a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorStatsSpec.java +++ b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorStatsSpec.java @@ -40,12 +40,7 @@ public PageRankAlgorithmFactory algorithmFactory(ExecutionC } @Override public NewConfigFunction newConfigFunction() { - return (___, config) -> { - if (config.containsKey("dampingFactor")) { - throw new IllegalArgumentException("Unexpected configuration key: dampingFactor"); - } - return PageRankStatsConfig.of(config); - }; + return (___, config) -> PageRankStatsConfig.configWithoutDampingFactor(config); } diff --git a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorStreamSpec.java b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorStreamSpec.java index f88ca2ec3f..bb636ae8da 100644 --- a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorStreamSpec.java +++ b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorStreamSpec.java @@ -41,11 +41,6 @@ public PageRankAlgorithmFactory algorithmFactory(Execution @Override public NewConfigFunction newConfigFunction() { - return (___, config) -> { - if (config.containsKey("dampingFactor")) { - throw new IllegalArgumentException("Unexpected configuration key: dampingFactor"); - } - return PageRankStreamConfig.of(config); - }; + return (___, config) -> PageRankStreamConfig.configWithoutDampingFactor(config); } } diff --git a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorWriteSpec.java b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorWriteSpec.java index e55e365f74..707a3f3cc3 100644 --- a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorWriteSpec.java +++ b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/EigenVectorWriteSpec.java @@ -41,12 +41,7 @@ public PageRankAlgorithmFactory algorithmFactory(ExecutionC @Override public NewConfigFunction newConfigFunction() { - return (___, config) -> { - if (config.containsKey("dampingFactor")) { - throw new IllegalArgumentException("Unexpected configuration key: dampingFactor"); - } - return PageRankWriteConfig.of(config); - }; + return (___, config) -> PageRankWriteConfig.configWithoutDampingFactor(config); } } diff --git a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankMutateSpec.java b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankMutateSpec.java index 8e4acf6e5e..3a7c536bd2 100644 --- a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankMutateSpec.java +++ b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankMutateSpec.java @@ -47,7 +47,7 @@ public PageRankAlgorithmFactory algorithmFactory(Execution @Override public NewConfigFunction newConfigFunction() { - return (___,config) -> PageRankMutateConfig.of(config); + return (___,config) -> PageRankMutateConfig.configWithDampingFactor(config); } @Override diff --git a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankStatsSpec.java b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankStatsSpec.java index 39e5d28150..1f9d148870 100644 --- a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankStatsSpec.java +++ b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankStatsSpec.java @@ -24,8 +24,8 @@ import org.neo4j.gds.executor.ComputationResultConsumer; 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.algorithms.centrality.PageRankStatsResult; +import org.neo4j.gds.procedures.algorithms.configuration.NewConfigFunction; import java.util.stream.Stream; @@ -47,7 +47,7 @@ public PageRankAlgorithmFactory algorithmFactory(ExecutionC @Override public NewConfigFunction newConfigFunction() { - return (___,config) -> PageRankStatsConfig.of(config); + return (___,config) -> PageRankStatsConfig.configWithDampingFactor(config); } @Override diff --git a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankStreamSpec.java b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankStreamSpec.java index 7f9a750ac8..5a749ad47d 100644 --- a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankStreamSpec.java +++ b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankStreamSpec.java @@ -24,8 +24,8 @@ import org.neo4j.gds.executor.ComputationResultConsumer; 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.algorithms.centrality.CentralityStreamResult; +import org.neo4j.gds.procedures.algorithms.configuration.NewConfigFunction; import java.util.stream.Stream; @@ -47,7 +47,7 @@ public PageRankAlgorithmFactory algorithmFactory(Execution @Override public NewConfigFunction newConfigFunction() { - return (___,config) -> PageRankStreamConfig.of(config); + return (___,config) -> PageRankStreamConfig.configWithDampingFactor(config); } @Override diff --git a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankWriteSpec.java b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankWriteSpec.java index 995a8e4ad5..7a4c50965e 100644 --- a/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankWriteSpec.java +++ b/proc/centrality/src/main/java/org/neo4j/gds/pagerank/PageRankWriteSpec.java @@ -24,8 +24,8 @@ import org.neo4j.gds.executor.ComputationResultConsumer; 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.algorithms.centrality.PageRankWriteResult; +import org.neo4j.gds.procedures.algorithms.configuration.NewConfigFunction; import java.util.stream.Stream; @@ -47,7 +47,7 @@ public PageRankAlgorithmFactory algorithmFactory(ExecutionC @Override public NewConfigFunction newConfigFunction() { - return (___,config) -> PageRankWriteConfig.of(config); + return (___,config) -> PageRankWriteConfig.configWithDampingFactor(config); } @Override 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 197f996c29..2f0b88166b 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 @@ -143,7 +143,8 @@ public static CentralityProcedureFacade create( genericStub, estimationModeBusinessFacade, procedureReturnColumns, - mutateModeBusinessFacade::articleRank + mutateModeBusinessFacade::articleRank, + PageRankMutateConfig::configWithDampingFactor ); var betaClosenessCentralityMutateStub = new BetaClosenessCentralityMutateStub( @@ -180,14 +181,12 @@ public static CentralityProcedureFacade create( procedureReturnColumns ); - var eigenVectorMutateStub = new MutateStubConfigurationValidationDecorator<>( - new PageRankMutateStub( + var eigenVectorMutateStub = new PageRankMutateStub( genericStub, estimationModeBusinessFacade, procedureReturnColumns, - mutateModeBusinessFacade::eigenVector - ), - "dampingFactor" + mutateModeBusinessFacade::eigenVector, + PageRankMutateConfig::configWithoutDampingFactor ); var harmonicCentralityMutateStub = new HarmonicCentralityMutateStub( @@ -201,7 +200,9 @@ public static CentralityProcedureFacade create( genericStub, estimationModeBusinessFacade, procedureReturnColumns, - mutateModeBusinessFacade::pageRank + mutateModeBusinessFacade::pageRank, + PageRankMutateConfig::configWithDampingFactor + ); var articulationPointsMutateStub = new ArticulationPointsMutateStub( @@ -273,7 +274,7 @@ public Stream articleRankStats(String graphName, Map articleRankStatsEstimate( ) { var result = estimationMode.runEstimation( algorithmConfiguration, - PageRankStatsConfig::of, + PageRankStatsConfig::configWithDampingFactor, configuration -> estimationModeBusinessFacade.pageRank(configuration, graphNameOrConfiguration) ); @@ -298,7 +299,7 @@ public Stream articleRankStream(String graphName, Map articleRankStreamEstimate( ) { var result = estimationMode.runEstimation( algorithmConfiguration, - PageRankStreamConfig::of, + PageRankStreamConfig::configWithDampingFactor, configuration -> estimationModeBusinessFacade.pageRank(configuration, graphNameOrConfiguration) ); @@ -326,7 +327,7 @@ public Stream articleRankWrite( return algorithmExecutionScaffolding.runAlgorithm( graphName, configuration, - PageRankWriteConfig::of, + PageRankWriteConfig::configWithDampingFactor, writeModeBusinessFacade::articleRank, resultBuilder ); @@ -338,7 +339,7 @@ public Stream articleRankWriteEstimate( ) { var result = estimationMode.runEstimation( algorithmConfiguration, - PageRankWriteConfig::of, + PageRankWriteConfig::configWithDampingFactor, configuration -> estimationModeBusinessFacade.pageRank(configuration, graphNameOrConfiguration) ); @@ -853,7 +854,7 @@ public Stream eigenvectorStats(String graphName, Map eigenvectorStatsEstimate( var result = estimationMode.runEstimation( algorithmConfiguration, - PageRankStatsConfig::of, + PageRankStatsConfig::configWithoutDampingFactor, configuration -> estimationModeBusinessFacade.pageRank(configuration, graphNameOrConfiguration) ); @@ -882,7 +883,7 @@ public Stream eigenvectorStream(String graphName, Map eigenvectorStreamEstimate( var result = estimationMode.runEstimation( algorithmConfiguration, - PageRankStreamConfig::of, + PageRankStreamConfig::configWithoutDampingFactor, configuration -> estimationModeBusinessFacade.pageRank(configuration, graphNameOrConfiguration) ); @@ -912,7 +913,7 @@ public Stream eigenvectorWrite(String graphName, Map eigenvectorWriteEstimate( var result = estimationMode.runEstimation( algorithmConfiguration, - PageRankWriteConfig::of, + PageRankWriteConfig::configWithoutDampingFactor, configuration -> estimationModeBusinessFacade.pageRank(configuration, graphNameOrConfiguration) ); @@ -989,7 +990,7 @@ public Stream pageRankStats(String graphName, Map pageRankStatsEstimate( ) { var result = estimationMode.runEstimation( algorithmConfiguration, - PageRankStatsConfig::of, + PageRankStatsConfig::configWithDampingFactor, configuration -> estimationModeBusinessFacade.pageRank(configuration, graphNameOrConfiguration) ); @@ -1014,7 +1015,7 @@ public Stream pageRankStream(String graphName, Map pageRankStreamEstimate( ) { var result = estimationMode.runEstimation( algorithmConfiguration, - PageRankStreamConfig::of, + PageRankStreamConfig::configWithDampingFactor, configuration -> estimationModeBusinessFacade.pageRank(configuration, graphNameOrConfiguration) ); @@ -1040,7 +1041,7 @@ public Stream pageRankWrite(String graphName, Map pageRankWriteEstimate( ) { var result = estimationMode.runEstimation( algorithmConfiguration, - PageRankWriteConfig::of, + PageRankWriteConfig::configWithDampingFactor, configuration -> estimationModeBusinessFacade.pageRank(configuration, graphNameOrConfiguration) ); diff --git a/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/MutateStubConfigurationValidationDecorator.java b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/MutateStubConfigurationValidationDecorator.java deleted file mode 100644 index d4287e8f76..0000000000 --- a/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/MutateStubConfigurationValidationDecorator.java +++ /dev/null @@ -1,74 +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.algorithms.centrality; - -import org.neo4j.gds.applications.algorithms.machinery.MemoryEstimateResult; -import org.neo4j.gds.mem.MemoryEstimation; -import org.neo4j.gds.procedures.algorithms.stubs.MutateStub; - -import java.util.Map; -import java.util.stream.Stream; - -/** - * A decorator that validates a property before delegating - */ -class MutateStubConfigurationValidationDecorator implements MutateStub { - private final MutateStub delegate; - private final String key; - - MutateStubConfigurationValidationDecorator(MutateStub delegate, String key) { - this.delegate = delegate; - this.key = key; - } - - @Override - public CONFIGURATION parseConfiguration(Map configuration) { - validate(configuration); - - return delegate.parseConfiguration(configuration); - } - - @Override - public MemoryEstimation getMemoryEstimation(String username, Map configuration) { - validate(configuration); - - return delegate.getMemoryEstimation(username, configuration); - } - - @Override - public Stream estimate(Object graphName, Map configuration) { - validate(configuration); - - return delegate.estimate(graphName, configuration); - } - - @Override - public Stream execute(String graphName, Map configuration) { - validate(configuration); - - return delegate.execute(graphName, configuration); - } - - private void validate(Map configuration) { - if (configuration.containsKey(key)) { - throw new IllegalArgumentException("Unexpected configuration key: " + key); - } - } -} diff --git a/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/stubs/PageRankMutateStub.java b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/stubs/PageRankMutateStub.java index 11d083d565..de2655c873 100644 --- a/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/stubs/PageRankMutateStub.java +++ b/procedures/algorithms-facade/src/main/java/org/neo4j/gds/procedures/algorithms/centrality/stubs/PageRankMutateStub.java @@ -23,6 +23,7 @@ import org.neo4j.gds.applications.algorithms.centrality.CentralityAlgorithmsEstimationModeBusinessFacade; import org.neo4j.gds.applications.algorithms.machinery.MemoryEstimateResult; import org.neo4j.gds.applications.algorithms.metadata.NodePropertiesWritten; +import org.neo4j.gds.core.CypherMapWrapper; import org.neo4j.gds.mem.MemoryEstimation; import org.neo4j.gds.pagerank.PageRankMutateConfig; import org.neo4j.gds.pagerank.PageRankResult; @@ -32,6 +33,7 @@ import org.neo4j.gds.procedures.algorithms.stubs.MutateStub; import java.util.Map; +import java.util.function.Function; import java.util.stream.Stream; public class PageRankMutateStub implements MutateStub { @@ -39,22 +41,25 @@ public class PageRankMutateStub implements MutateStub handle; + private final Function configProducer; public PageRankMutateStub( GenericStub genericStub, CentralityAlgorithmsEstimationModeBusinessFacade estimationModeBusinessFacade, ProcedureReturnColumns procedureReturnColumns, - AlgorithmHandle handle + AlgorithmHandle handle, + Function configProducer ) { this.genericStub = genericStub; this.estimationModeBusinessFacade = estimationModeBusinessFacade; this.procedureReturnColumns = procedureReturnColumns; this.handle = handle; + this.configProducer = configProducer; } @Override public PageRankMutateConfig parseConfiguration(Map configuration) { - return genericStub.parseConfiguration(PageRankMutateConfig::of, configuration); + return genericStub.parseConfiguration(configProducer, configuration); } @Override @@ -62,7 +67,7 @@ public MemoryEstimation getMemoryEstimation(String username, Map return genericStub.getMemoryEstimation( username, configuration, - PageRankMutateConfig::of, + configProducer, __ -> estimationModeBusinessFacade.pageRank() ); } @@ -72,7 +77,7 @@ public Stream estimate(Object graphName, Map estimationModeBusinessFacade.pageRank() ); } @@ -88,7 +93,7 @@ public Stream execute( return genericStub.execute( graphNameAsString, rawConfiguration, - PageRankMutateConfig::of, + configProducer, handle, resultBuilder ); diff --git a/procedures/algorithms-facade/src/test/java/org/neo4j/gds/procedures/algorithms/centrality/MutateStubConfigurationValidationDecoratorTest.java b/procedures/algorithms-facade/src/test/java/org/neo4j/gds/procedures/algorithms/centrality/MutateStubConfigurationValidationDecoratorTest.java deleted file mode 100644 index 590bb769c9..0000000000 --- a/procedures/algorithms-facade/src/test/java/org/neo4j/gds/procedures/algorithms/centrality/MutateStubConfigurationValidationDecoratorTest.java +++ /dev/null @@ -1,134 +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.algorithms.centrality; - -import org.junit.jupiter.api.Test; -import org.neo4j.gds.applications.algorithms.machinery.MemoryEstimateResult; -import org.neo4j.gds.mem.MemoryEstimation; - -import java.util.Map; -import java.util.stream.Stream; - -import static java.util.Collections.emptyMap; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class MutateStubConfigurationValidationDecoratorTest { - @Test - void shouldFailToParseConfigurationWhenKeyIsPresent() { - var decorator = new MutateStubConfigurationValidationDecorator<>(null, "some key"); - - try { - decorator.parseConfiguration(Map.of("some key", "some value")); - - fail(); - } catch (IllegalArgumentException e) { - assertThat(e).hasMessage("Unexpected configuration key: some key"); - } - } - - @Test - void shouldAllowParsingConfigurationWhenKeyNotPresent() { - var stub = mock(ExampleMutateStub.class); - var decorator = new MutateStubConfigurationValidationDecorator<>(stub, "some key"); - - when(stub.parseConfiguration(emptyMap())).thenReturn("some configuration"); - var configuration = decorator.parseConfiguration(emptyMap()); - - assertThat(configuration).isEqualTo("some configuration"); - } - - @Test - void shouldFailToGetMemoryEstimationWhenKeyIsPresent() { - var decorator = new MutateStubConfigurationValidationDecorator<>(null, "some key"); - - try { - decorator.getMemoryEstimation("some user", Map.of("some key", "some value")); - - fail(); - } catch (IllegalArgumentException e) { - assertThat(e).hasMessage("Unexpected configuration key: some key"); - } - } - - @Test - void shouldAllowGettingMemoryEstimationWhenKeyNotPresent() { - var stub = mock(ExampleMutateStub.class); - var decorator = new MutateStubConfigurationValidationDecorator<>(stub, "some key"); - - var memoryEstimation = mock(MemoryEstimation.class); - when(stub.getMemoryEstimation("some user", emptyMap())).thenReturn(memoryEstimation); - var actualMemoryEstimation = decorator.getMemoryEstimation("some user", emptyMap()); - - assertThat(actualMemoryEstimation).isSameAs(memoryEstimation); - } - - @Test - void shouldFailToEstimateWhenKeyIsPresent() { - var decorator = new MutateStubConfigurationValidationDecorator<>(null, "some key"); - - try { - decorator.estimate("some graph", Map.of("some key", "some value")); - - fail(); - } catch (IllegalArgumentException e) { - assertThat(e).hasMessage("Unexpected configuration key: some key"); - } - } - - @Test - void shouldAllowEstimatingWhenKeyNotPresent() { - var stub = mock(ExampleMutateStub.class); - var decorator = new MutateStubConfigurationValidationDecorator<>(stub, "some key"); - - var result = Stream.of(mock(MemoryEstimateResult.class)); - when(stub.estimate("some graph", emptyMap())).thenReturn(result); - var actualResult = decorator.estimate("some graph", emptyMap()); - - assertThat(actualResult).isSameAs(result); - } - - @Test - void shouldFailToExecuteWhenKeyIsPresent() { - var decorator = new MutateStubConfigurationValidationDecorator<>(null, "some key"); - - try { - decorator.execute("some graph", Map.of("some key", "some value")); - - fail(); - } catch (IllegalArgumentException e) { - assertThat(e).hasMessage("Unexpected configuration key: some key"); - } - } - - @Test - void shouldAllowExecutingWhenKeyNotPresent() { - var stub = mock(ExampleMutateStub.class); - var decorator = new MutateStubConfigurationValidationDecorator<>(stub, "some key"); - - var result = Stream.of(mock(Void.class)); - when(stub.execute("some graph", emptyMap())).thenReturn(result); - var actualResult = decorator.execute("some graph", emptyMap()); - - assertThat(actualResult).isSameAs(result); - } -}