diff --git a/procedures/facade/src/main/java/org/neo4j/gds/procedures/similarity/SimilarityProcedureFacade.java b/procedures/facade/src/main/java/org/neo4j/gds/procedures/similarity/SimilarityProcedureFacade.java index 1d6c57b6eb..693e48807b 100644 --- a/procedures/facade/src/main/java/org/neo4j/gds/procedures/similarity/SimilarityProcedureFacade.java +++ b/procedures/facade/src/main/java/org/neo4j/gds/procedures/similarity/SimilarityProcedureFacade.java @@ -24,12 +24,8 @@ import org.neo4j.gds.algorithms.similarity.SimilarityAlgorithmsStatsBusinessFacade; import org.neo4j.gds.algorithms.similarity.SimilarityAlgorithmsStreamBusinessFacade; import org.neo4j.gds.algorithms.similarity.SimilarityAlgorithmsWriteBusinessFacade; -import org.neo4j.gds.api.AlgorithmMetaDataSetter; import org.neo4j.gds.api.ProcedureReturnColumns; -import org.neo4j.gds.api.User; -import org.neo4j.gds.config.AlgoBaseConfig; -import org.neo4j.gds.core.CypherMapWrapper; -import org.neo4j.gds.procedures.configparser.ConfigurationParser; +import org.neo4j.gds.procedures.algorithms.ConfigurationCreator; import org.neo4j.gds.procedures.similarity.knn.KnnMutateResult; import org.neo4j.gds.procedures.similarity.knn.KnnStatsResult; import org.neo4j.gds.procedures.similarity.knn.KnnWriteResult; @@ -53,48 +49,40 @@ import org.neo4j.gds.similarity.nodesim.NodeSimilarityWriteConfig; import java.util.Map; -import java.util.function.Function; import java.util.stream.Stream; public class SimilarityProcedureFacade { - - private final ConfigurationParser configurationParser; - private final User user; + private final ConfigurationCreator configurationCreator; private final ProcedureReturnColumns procedureReturnColumns; + private final SimilarityAlgorithmsEstimateBusinessFacade estimateBusinessFacade; private final SimilarityAlgorithmsMutateBusinessFacade mutateBusinessFacade; private final SimilarityAlgorithmsStatsBusinessFacade statsBusinessFacade; private final SimilarityAlgorithmsStreamBusinessFacade streamBusinessFacade; private final SimilarityAlgorithmsWriteBusinessFacade writeBusinessFacade; - private final SimilarityAlgorithmsEstimateBusinessFacade estimateBusinessFacade; - private final AlgorithmMetaDataSetter algorithmMetaDataSetter; public SimilarityProcedureFacade( - ConfigurationParser configurationParser, - User user, + ConfigurationCreator configurationCreator, ProcedureReturnColumns procedureReturnColumns, + SimilarityAlgorithmsEstimateBusinessFacade estimateBusinessFacade, SimilarityAlgorithmsMutateBusinessFacade mutateBusinessFacade, SimilarityAlgorithmsStatsBusinessFacade statsBusinessFacade, SimilarityAlgorithmsStreamBusinessFacade streamBusinessFacade, - SimilarityAlgorithmsWriteBusinessFacade writeBusinessFacade, - SimilarityAlgorithmsEstimateBusinessFacade estimateBusinessFacade, - AlgorithmMetaDataSetter algorithmMetaDataSetter + SimilarityAlgorithmsWriteBusinessFacade writeBusinessFacade ) { - this.configurationParser = configurationParser; - this.user = user; + this.configurationCreator = configurationCreator; this.procedureReturnColumns = procedureReturnColumns; + this.estimateBusinessFacade = estimateBusinessFacade; this.mutateBusinessFacade = mutateBusinessFacade; this.statsBusinessFacade = statsBusinessFacade; this.streamBusinessFacade = streamBusinessFacade; this.writeBusinessFacade = writeBusinessFacade; - this.estimateBusinessFacade = estimateBusinessFacade; - this.algorithmMetaDataSetter = algorithmMetaDataSetter; } public Stream nodeSimilarityStream( String graphName, Map configuration ) { - var streamConfig = createStreamConfig(configuration, NodeSimilarityStreamConfig::of); + var streamConfig = configurationCreator.createConfigurationForStream(configuration, NodeSimilarityStreamConfig::of); var computationResult = streamBusinessFacade.nodeSimilarity( graphName, @@ -108,7 +96,7 @@ public Stream nodeSimilarityStats( String graphName, Map configuration ) { - var statsConfig = createConfig(configuration, NodeSimilarityStatsConfig::of); + var statsConfig = configurationCreator.createConfiguration(configuration, NodeSimilarityStatsConfig::of); var computationResult = statsBusinessFacade.nodeSimilarity( graphName, @@ -123,7 +111,7 @@ public Stream nodeSimilarityWrite( String graphName, Map configuration ) { - var statsConfig = createConfig(configuration, NodeSimilarityWriteConfig::of); + var statsConfig = configurationCreator.createConfiguration(configuration, NodeSimilarityWriteConfig::of); var computationResult = writeBusinessFacade.nodeSimilarity( graphName, @@ -138,7 +126,7 @@ public Stream nodeSimilarityMutate( String graphName, Map configuration ) { - var mutateConfig = createConfig(configuration, NodeSimilarityMutateConfig::of); + var mutateConfig = configurationCreator.createConfiguration(configuration, NodeSimilarityMutateConfig::of); var computationResult = mutateBusinessFacade.nodeSimilarity( graphName, @@ -154,7 +142,7 @@ public Stream nodeSimilarityEstimateStream( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, NodeSimilarityStreamConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, NodeSimilarityStreamConfig::of); return Stream.of(estimateBusinessFacade.nodeSimilarity(graphNameOrConfiguration, config)); } @@ -162,7 +150,7 @@ public Stream nodeSimilarityEstimateStats( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, NodeSimilarityStatsConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, NodeSimilarityStatsConfig::of); return Stream.of(estimateBusinessFacade.nodeSimilarity(graphNameOrConfiguration, config)); } @@ -170,7 +158,7 @@ public Stream nodeSimilarityEstimateMutate( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, NodeSimilarityMutateConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, NodeSimilarityMutateConfig::of); return Stream.of(estimateBusinessFacade.nodeSimilarity(graphNameOrConfiguration, config)); } @@ -178,7 +166,7 @@ public Stream nodeSimilarityEstimateWrite( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, NodeSimilarityWriteConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, NodeSimilarityWriteConfig::of); return Stream.of(estimateBusinessFacade.nodeSimilarity(graphNameOrConfiguration, config)); } @@ -187,7 +175,7 @@ public Stream filteredNodeSimilarityStream( String graphName, Map configuration ) { - var streamConfig = createStreamConfig(configuration, FilteredNodeSimilarityStreamConfig::of); + var streamConfig = configurationCreator.createConfigurationForStream(configuration, FilteredNodeSimilarityStreamConfig::of); var computationResult = streamBusinessFacade.filteredNodeSimilarity( graphName, @@ -201,7 +189,7 @@ public Stream filteredNodeSimilarityStats( String graphName, Map configuration ) { - var statsConfig = createConfig(configuration, FilteredNodeSimilarityStatsConfig::of); + var statsConfig = configurationCreator.createConfiguration(configuration, FilteredNodeSimilarityStatsConfig::of); var computationResult = statsBusinessFacade.filteredNodeSimilarity( graphName, @@ -216,7 +204,7 @@ public Stream filteredNodeSimilarityMutate( String graphName, Map configuration ) { - var mutateConfig = createConfig(configuration, FilteredNodeSimilarityMutateConfig::of); + var mutateConfig = configurationCreator.createConfiguration(configuration, FilteredNodeSimilarityMutateConfig::of); var computationResult = mutateBusinessFacade.filteredNodeSimilarity( graphName, @@ -231,7 +219,7 @@ public Stream filteredNodeSimilarityWrite( String graphName, Map configuration ) { - var writeConfig = createConfig(configuration, FilteredNodeSimilarityWriteConfig::of); + var writeConfig = configurationCreator.createConfiguration(configuration, FilteredNodeSimilarityWriteConfig::of); var computationResult = writeBusinessFacade.filteredNodeSimilarity( graphName, @@ -247,7 +235,7 @@ public Stream filteredNodeSimilarityEstimateStream( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, FilteredNodeSimilarityStreamConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, FilteredNodeSimilarityStreamConfig::of); return Stream.of(estimateBusinessFacade.filteredNodeSimilarity(graphNameOrConfiguration, config)); } @@ -255,7 +243,7 @@ public Stream filteredNodeSimilarityEstimateStats( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, FilteredNodeSimilarityStatsConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, FilteredNodeSimilarityStatsConfig::of); return Stream.of(estimateBusinessFacade.filteredNodeSimilarity(graphNameOrConfiguration, config)); } @@ -263,7 +251,7 @@ public Stream filteredNodeSimilarityEstimateMutate( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, FilteredNodeSimilarityMutateConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, FilteredNodeSimilarityMutateConfig::of); return Stream.of(estimateBusinessFacade.nodeSimilarity(graphNameOrConfiguration, config)); } @@ -271,7 +259,7 @@ public Stream filteredNodeSimilarityEstimateWrite( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, FilteredNodeSimilarityWriteConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, FilteredNodeSimilarityWriteConfig::of); return Stream.of(estimateBusinessFacade.nodeSimilarity(graphNameOrConfiguration, config)); } @@ -279,7 +267,7 @@ public Stream knnStream( String graphName, Map configuration ) { - var streamConfig = createStreamConfig(configuration, KnnStreamConfig::of); + var streamConfig = configurationCreator.createConfigurationForStream(configuration, KnnStreamConfig::of); var computationResult = streamBusinessFacade.knn( graphName, @@ -293,7 +281,7 @@ public Stream knnStats( String graphName, Map configuration ) { - var statsConfig = createConfig(configuration, KnnStatsConfig::of); + var statsConfig = configurationCreator.createConfiguration(configuration, KnnStatsConfig::of); var computationResult = statsBusinessFacade.knn( graphName, @@ -308,7 +296,7 @@ public Stream knnWrite( String graphName, Map configuration ) { - var writeConfig = createConfig(configuration, KnnWriteConfig::of); + var writeConfig = configurationCreator.createConfiguration(configuration, KnnWriteConfig::of); var computationResult = writeBusinessFacade.knn( graphName, @@ -323,7 +311,7 @@ public Stream knnMutate( String graphName, Map configuration ) { - var mutateConfig = createConfig(configuration, KnnMutateConfig::of); + var mutateConfig = configurationCreator.createConfiguration(configuration, KnnMutateConfig::of); var computationResult = mutateBusinessFacade.knn( graphName, @@ -339,7 +327,7 @@ public Stream knnStreamEstimate( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, KnnStreamConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, KnnStreamConfig::of); return Stream.of(estimateBusinessFacade.knn(graphNameOrConfiguration, config)); } @@ -347,7 +335,7 @@ public Stream knnStatsEstimate( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, KnnStatsConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, KnnStatsConfig::of); return Stream.of(estimateBusinessFacade.knn(graphNameOrConfiguration, config)); } @@ -355,7 +343,7 @@ public Stream knnWriteEstimate( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, KnnWriteConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, KnnWriteConfig::of); return Stream.of(estimateBusinessFacade.knn(graphNameOrConfiguration, config)); } @@ -363,7 +351,7 @@ public Stream knnMutateEstimate( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, KnnMutateConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, KnnMutateConfig::of); return Stream.of(estimateBusinessFacade.knn(graphNameOrConfiguration, config)); } @@ -371,7 +359,7 @@ public Stream filteredKnnStream( String graphName, Map configuration ) { - var streamConfig = createStreamConfig(configuration, FilteredKnnStreamConfig::of); + var streamConfig = configurationCreator.createConfigurationForStream(configuration, FilteredKnnStreamConfig::of); var computationResult = streamBusinessFacade.filteredKnn( graphName, @@ -385,7 +373,7 @@ public Stream filteredKnnStats( String graphName, Map configuration ) { - var statsConfig = createConfig(configuration, FilteredKnnStatsConfig::of); + var statsConfig = configurationCreator.createConfiguration(configuration, FilteredKnnStatsConfig::of); var computationResult = statsBusinessFacade.filteredKnn( graphName, @@ -400,7 +388,7 @@ public Stream filteredKnnMutate( String graphName, Map configuration ) { - var mutateConfig = createConfig(configuration, FilteredKnnMutateConfig::of); + var mutateConfig = configurationCreator.createConfiguration(configuration, FilteredKnnMutateConfig::of); var computationResult = mutateBusinessFacade.filteredKnn( graphName, @@ -415,7 +403,7 @@ public Stream filteredKnnWrite( String graphName, Map configuration ) { - var writeConfig = createConfig(configuration, FilteredKnnWriteConfig::of); + var writeConfig = configurationCreator.createConfiguration(configuration, FilteredKnnWriteConfig::of); var computationResult = writeBusinessFacade.filteredKnn( graphName, @@ -431,7 +419,7 @@ public Stream filteredKnnStreamEstimate( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, FilteredKnnStreamConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, FilteredKnnStreamConfig::of); return Stream.of(estimateBusinessFacade.filteredKnn(graphNameOrConfiguration, config)); } @@ -439,7 +427,7 @@ public Stream filteredKnnStatsEstimate( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, FilteredKnnStatsConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, FilteredKnnStatsConfig::of); return Stream.of(estimateBusinessFacade.filteredKnn(graphNameOrConfiguration, config)); } @@ -447,7 +435,7 @@ public Stream filteredKnnMutateEstimate( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, FilteredKnnMutateConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, FilteredKnnMutateConfig::of); return Stream.of(estimateBusinessFacade.filteredKnn(graphNameOrConfiguration, config)); } @@ -455,30 +443,7 @@ public Stream filteredKnnWriteEstimate( Object graphNameOrConfiguration, Map algoConfiguration ) { - var config = createConfig(algoConfiguration, FilteredKnnWriteConfig::of); + var config = configurationCreator.createConfiguration(algoConfiguration, FilteredKnnWriteConfig::of); return Stream.of(estimateBusinessFacade.filteredKnn(graphNameOrConfiguration, config)); } - - - // FIXME: the following two methods are duplicate, find a good place for them. - private C createStreamConfig( - Map configuration, - Function configCreator - ) { - return createConfig( - configuration, - configCreator.andThen(algorithmConfiguration -> { - algorithmMetaDataSetter.set(algorithmConfiguration); - return algorithmConfiguration; - }) - ); - } - - private C createConfig( - Map configuration, - Function configCreator - ) { - return configurationParser.produceConfig(configuration, configCreator, user.getUsername()); - } - //FIXME: here ends the fixme-block } diff --git a/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/SimilarityProcedureProvider.java b/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/SimilarityProcedureProvider.java index 65ee461293..9ef5f7f956 100644 --- a/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/SimilarityProcedureProvider.java +++ b/procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/SimilarityProcedureProvider.java @@ -41,6 +41,7 @@ import org.neo4j.gds.procedures.KernelTransactionAccessor; import org.neo4j.gds.procedures.TaskRegistryFactoryService; import org.neo4j.gds.procedures.TerminationFlagService; +import org.neo4j.gds.procedures.algorithms.ConfigurationCreator; import org.neo4j.gds.procedures.configparser.ConfigurationParser; import org.neo4j.gds.procedures.similarity.SimilarityProcedureFacade; import org.neo4j.gds.services.DatabaseIdAccessor; @@ -118,6 +119,7 @@ SimilarityProcedureFacade createSimilarityProcedureFacade(Context context) throw var relationshipExporterBuilder = exportBuildersProvider.relationshipExporterBuilder(exporterContext); var returnColumns = new ProcedureCallContextReturnColumns(context.procedureCallContext()); var user = userAccessor.getUser(context.securityContext()); + var configurationCreator = new ConfigurationCreator(configurationParser, algorithmMetaDataSetter, user); var taskRegistryFactory = taskRegistryFactoryService.getTaskRegistryFactory(databaseId, user); var terminationFlag = terminationFlagService.createTerminationFlag(kernelTransaction); var userLogRegistryFactory = userLogServices.getUserLogRegistryFactory(databaseId, user); @@ -178,15 +180,13 @@ SimilarityProcedureFacade createSimilarityProcedureFacade(Context context) throw // procedure facade return new SimilarityProcedureFacade( - configurationParser, - user, + configurationCreator, returnColumns, + estimateBusinessFacade, mutateBusinessFacade, statsBusinessFacade, streamBusinessFacade, - writeBusinessFacade, - estimateBusinessFacade, - algorithmMetaDataSetter + writeBusinessFacade ); } }