Skip to content

Commit

Permalink
roll out request scoped dependencies parameter object through layers …
Browse files Browse the repository at this point in the history
…for WCC
  • Loading branch information
lassewesth committed Nov 15, 2023
1 parent 909feda commit ad57a48
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.gds.algorithms.community;

import org.neo4j.gds.algorithms.AlgorithmComputationResult;
import org.neo4j.gds.algorithms.RequestScopedDependencies;
import org.neo4j.gds.algorithms.runner.AlgorithmRunner;
import org.neo4j.gds.api.DatabaseId;
import org.neo4j.gds.api.User;
Expand Down Expand Up @@ -80,20 +81,16 @@ public CommunityAlgorithmsFacade(
}

AlgorithmComputationResult<DisjointSetStruct> wcc(
RequestScopedDependencies requestScopedDependencies,
String graphName,
WccBaseConfig config,
User user,
DatabaseId databaseId,
TerminationFlag terminationFlag
WccBaseConfig config
) {
return algorithmRunner.run(
requestScopedDependencies,
graphName,
config,
config.relationshipWeightProperty(),
new WccAlgorithmFactory<>(),
user,
databaseId,
terminationFlag
new WccAlgorithmFactory<>()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.neo4j.gds.algorithms.AlgorithmComputationResult;
import org.neo4j.gds.algorithms.NodePropertyMutateResult;
import org.neo4j.gds.algorithms.RequestScopedDependencies;
import org.neo4j.gds.algorithms.community.specificfields.ApproxMaxKCutSpecificFields;
import org.neo4j.gds.algorithms.community.specificfields.CommunityStatisticsSpecificFields;
import org.neo4j.gds.algorithms.community.specificfields.K1ColoringSpecificFields;
Expand Down Expand Up @@ -80,16 +81,14 @@ public CommunityAlgorithmsMutateBusinessFacade(
}

public NodePropertyMutateResult<StandardCommunityStatisticsSpecificFields> wcc(
RequestScopedDependencies requestScopedDependencies,
String graphName,
WccMutateConfig configuration,
User user,
DatabaseId databaseId,
TerminationFlag terminationFlag,
StatisticsComputationInstructions statisticsComputationInstructions
) {
// 1. Run the algorithm and time the execution
var intermediateResult = runWithTiming(
() -> communityAlgorithmsFacade.wcc(graphName, configuration, user, databaseId, terminationFlag)
() -> communityAlgorithmsFacade.wcc(requestScopedDependencies, graphName, configuration)
);
var algorithmResult = intermediateResult.algorithmResult;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.gds.algorithms.community;

import org.neo4j.gds.algorithms.AlgorithmComputationResult;
import org.neo4j.gds.algorithms.RequestScopedDependencies;
import org.neo4j.gds.algorithms.community.specificfields.CommunityStatisticsSpecificFields;
import org.neo4j.gds.algorithms.community.specificfields.K1ColoringSpecificFields;
import org.neo4j.gds.algorithms.community.specificfields.KCoreSpecificFields;
Expand Down Expand Up @@ -68,16 +69,14 @@ public CommunityAlgorithmsStatsBusinessFacade(CommunityAlgorithmsFacade communit
}

public StatsResult<StandardCommunityStatisticsSpecificFields> wcc(
RequestScopedDependencies requestScopedDependencies,
String graphName,
WccStatsConfig configuration,
User user,
DatabaseId databaseId,
TerminationFlag terminationFlag,
StatisticsComputationInstructions statisticsComputationInstructions
) {
// 1. Run the algorithm and time the execution
var intermediateResult = AlgorithmRunner.runWithTiming(
() -> communityAlgorithmsFacade.wcc(graphName, configuration, user, databaseId, terminationFlag)
() -> communityAlgorithmsFacade.wcc(requestScopedDependencies, graphName, configuration)
);
var algorithmResult = intermediateResult.algorithmResult;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.gds.algorithms.community;

import org.neo4j.gds.algorithms.AlgorithmComputationResult;
import org.neo4j.gds.algorithms.RequestScopedDependencies;
import org.neo4j.gds.algorithms.StreamComputationResult;
import org.neo4j.gds.api.DatabaseId;
import org.neo4j.gds.api.User;
Expand Down Expand Up @@ -61,19 +62,14 @@ public CommunityAlgorithmsStreamBusinessFacade(CommunityAlgorithmsFacade communi
}

public StreamComputationResult<DisjointSetStruct> wcc(
RequestScopedDependencies requestScopedDependencies,
String graphName,
WccBaseConfig config,
User user,
DatabaseId databaseId,
TerminationFlag terminationFlag
WccBaseConfig config
) {

var result = this.communityAlgorithmsFacade.wcc(
requestScopedDependencies,
graphName,
config,
user,
databaseId,
terminationFlag
config
);

return createStreamComputationResult(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.neo4j.gds.algorithms.AlgorithmComputationResult;
import org.neo4j.gds.algorithms.NodePropertyWriteResult;
import org.neo4j.gds.algorithms.RequestScopedDependencies;
import org.neo4j.gds.algorithms.community.specificfields.AlphaSccSpecificFields;
import org.neo4j.gds.algorithms.community.specificfields.CommunityStatisticsSpecificFields;
import org.neo4j.gds.algorithms.community.specificfields.K1ColoringSpecificFields;
Expand Down Expand Up @@ -83,17 +84,15 @@ public CommunityAlgorithmsWriteBusinessFacade(
}

public NodePropertyWriteResult<StandardCommunityStatisticsSpecificFields> wcc(
RequestScopedDependencies requestScopedDependencies,
String graphName,
WccWriteConfig configuration,
User user,
DatabaseId databaseId,
TerminationFlag terminationFlag,
StatisticsComputationInstructions statisticsComputationInstructions
) {

// 1. Run the algorithm and time the execution
var intermediateResult = AlgorithmRunner.runWithTiming(
() -> communityAlgorithmsFacade.wcc(graphName, configuration, user, databaseId, terminationFlag)
() -> communityAlgorithmsFacade.wcc(requestScopedDependencies, graphName, configuration)
);
var algorithmResult = intermediateResult.algorithmResult;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.neo4j.gds.algorithms.AlgorithmMemoryValidationService;
import org.neo4j.gds.algorithms.RequestScopedDependencies;
import org.neo4j.gds.algorithms.runner.AlgorithmRunner;
import org.neo4j.gds.api.Graph;
import org.neo4j.gds.api.GraphStore;
Expand Down Expand Up @@ -110,11 +111,9 @@ void wcc() {

// when
var wccComputationResult = algorithmsBusinessFacade.wcc(
RequestScopedDependencies.builder().with(TerminationFlag.RUNNING_TRUE).build(),
"meh",
config,
null,
null,
TerminationFlag.RUNNING_TRUE
config
);

//then
Expand Down Expand Up @@ -149,7 +148,9 @@ void wccOnEmptyGraph() {
);

// when
var wccComputationResult = algorithmsBusinessFacade.wcc("meh", mock(WccBaseConfig.class), null, null, null);
var wccComputationResult = algorithmsBusinessFacade.wcc(
RequestScopedDependencies.builder().build(), "meh", mock(WccBaseConfig.class)
);

//then
assertThat(wccComputationResult.result()).isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.neo4j.gds.Orientation;
import org.neo4j.gds.TestProcedureRunner;
import org.neo4j.gds.algorithms.AlgorithmMemoryValidationService;
import org.neo4j.gds.algorithms.RequestScopedDependencies;
import org.neo4j.gds.algorithms.community.CommunityAlgorithmsFacade;
import org.neo4j.gds.algorithms.community.CommunityAlgorithmsStreamBusinessFacade;
import org.neo4j.gds.algorithms.runner.AlgorithmRunner;
Expand Down Expand Up @@ -213,10 +214,12 @@ void shouldRegisterTaskWithCorrectJobId() {
new CommunityProcedureFacade(
ConfigurationParser.EMPTY,
mock(AlgorithmMetaDataSetter.class),
new User(getUsername(), false),
DatabaseId.of(db.databaseName()),
RequestScopedDependencies.builder()
.with(DatabaseId.of(db.databaseName()))
.with(TerminationFlag.RUNNING_TRUE)
.with(new User(getUsername(), false))
.build(),
ProcedureReturnColumns.EMPTY,
TerminationFlag.RUNNING_TRUE,
null,
null,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.neo4j.gds.TestProcedureRunner;
import org.neo4j.gds.TestSupport;
import org.neo4j.gds.algorithms.AlgorithmMemoryValidationService;
import org.neo4j.gds.algorithms.RequestScopedDependencies;
import org.neo4j.gds.algorithms.community.CommunityAlgorithmsFacade;
import org.neo4j.gds.algorithms.community.CommunityAlgorithmsMutateBusinessFacade;
import org.neo4j.gds.algorithms.mutateservices.MutateNodePropertyService;
Expand Down Expand Up @@ -337,10 +338,12 @@ void testWriteBackGraphMutationOnFilteredGraph() {
new CommunityProcedureFacade(
ConfigurationParser.EMPTY,
null,
new User(getUsername(), false),
DatabaseId.of(db.databaseName()),
RequestScopedDependencies.builder()
.with(DatabaseId.of(db.databaseName()))
.with(TerminationFlag.RUNNING_TRUE)
.with(new User(getUsername(), false))
.build(),
ProcedureReturnColumns.EMPTY,
TerminationFlag.RUNNING_TRUE,
null,
algorithmsMutateBusinessFacade,
null,
Expand Down Expand Up @@ -463,10 +466,12 @@ void testMutateFailsOnExistingToken() {
new CommunityProcedureFacade(
ConfigurationParser.EMPTY,
null,
new User(getUsername(), false),
DatabaseId.of(db.databaseName()),
RequestScopedDependencies.builder()
.with(DatabaseId.of(db.databaseName()))
.with(TerminationFlag.RUNNING_TRUE)
.with(new User(getUsername(), false))
.build(),
ProcedureReturnColumns.EMPTY,
TerminationFlag.RUNNING_TRUE,
null,
algorithmsMutateBusinessFacade,
null,
Expand Down Expand Up @@ -544,11 +549,12 @@ void testRunOnEmptyGraph() {
new CommunityProcedureFacade(
ConfigurationParser.EMPTY,
null,
new User(getUsername(), false),
DatabaseId.of(db.databaseName()),
RequestScopedDependencies.builder()
.with(DatabaseId.of(db.databaseName()))
.with(new User(getUsername(), false))
.build(),
ProcedureReturnColumns.EMPTY,
null,
null,
algorithmsMutateBusinessFacade,
null,
null,
Expand Down Expand Up @@ -628,10 +634,12 @@ private GraphStore runMutation(String graphName, Map<String, Object> config) {
new CommunityProcedureFacade(
ConfigurationParser.EMPTY,
null,
new User(getUsername(), false),
DatabaseId.of(db.databaseName()),
RequestScopedDependencies.builder()
.with(DatabaseId.of(db.databaseName()))
.with(TerminationFlag.RUNNING_TRUE)
.with(new User(getUsername(), false))
.build(),
ProcedureReturnColumns.EMPTY,
TerminationFlag.RUNNING_TRUE,
null,
algorithmsMutateBusinessFacade,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.neo4j.gds.TestProcedureRunner;
import org.neo4j.gds.TestSupport;
import org.neo4j.gds.algorithms.AlgorithmMemoryValidationService;
import org.neo4j.gds.algorithms.RequestScopedDependencies;
import org.neo4j.gds.algorithms.community.CommunityAlgorithmsEstimateBusinessFacade;
import org.neo4j.gds.algorithms.community.CommunityAlgorithmsFacade;
import org.neo4j.gds.algorithms.community.CommunityAlgorithmsMutateBusinessFacade;
Expand Down Expand Up @@ -586,10 +587,12 @@ private GraphDataScience createFacade() {
new CommunityProcedureFacade(
ConfigurationParser.EMPTY,
null,
new User(getUsername(), false),
DatabaseId.of(db.databaseName()),
RequestScopedDependencies.builder()
.with(DatabaseId.of(db.databaseName()))
.with(TerminationFlag.RUNNING_TRUE)
.with(new User(getUsername(), false))
.build(),
ProcedureReturnColumns.EMPTY,
TerminationFlag.RUNNING_TRUE,
mock(CommunityAlgorithmsEstimateBusinessFacade.class),
algorithmsMutateBusinessFacade,
mock(CommunityAlgorithmsStatsBusinessFacade.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.neo4j.gds.TestProcedureRunner;
import org.neo4j.gds.TestSupport;
import org.neo4j.gds.algorithms.AlgorithmMemoryValidationService;
import org.neo4j.gds.algorithms.RequestScopedDependencies;
import org.neo4j.gds.algorithms.community.CommunityAlgorithmsFacade;
import org.neo4j.gds.algorithms.community.CommunityAlgorithmsMutateBusinessFacade;
import org.neo4j.gds.algorithms.mutateservices.MutateNodePropertyService;
Expand Down Expand Up @@ -367,10 +368,12 @@ void testWriteBackGraphMutationOnFilteredGraph() {
new CommunityProcedureFacade(
ConfigurationParser.EMPTY,
null,
new User(getUsername(), false),
DatabaseId.of(db.databaseName()),
RequestScopedDependencies.builder()
.with(DatabaseId.of(db.databaseName()))
.with(TerminationFlag.RUNNING_TRUE)
.with(new User(getUsername(), false))
.build(),
ProcedureReturnColumns.EMPTY,
TerminationFlag.RUNNING_TRUE,
null,
algorithmsMutateBusinessFacade,
null,
Expand Down Expand Up @@ -497,10 +500,12 @@ void testMutateFailsOnExistingToken() {
new CommunityProcedureFacade(
ConfigurationParser.EMPTY,
null,
new User(getUsername(), false),
DatabaseId.of(db.databaseName()),
RequestScopedDependencies.builder()
.with(DatabaseId.of(db.databaseName()))
.with(TerminationFlag.RUNNING_TRUE)
.with(new User(getUsername(), false))
.build(),
ProcedureReturnColumns.EMPTY,
TerminationFlag.RUNNING_TRUE,
null,
algorithmsBusinessFacade,
null,
Expand Down Expand Up @@ -576,11 +581,12 @@ void testRunOnEmptyGraph() {
new CommunityProcedureFacade(
ConfigurationParser.EMPTY,
null,
new User(getUsername(), false),
DatabaseId.of(db.databaseName()),
RequestScopedDependencies.builder()
.with(DatabaseId.of(db.databaseName()))
.with(new User(getUsername(), false))
.build(),
ProcedureReturnColumns.EMPTY,
null,
null,
algorithmsBusinessFacade,
null,
null,
Expand Down Expand Up @@ -661,10 +667,12 @@ private GraphStore runMutation(String graphName, Map<String, Object> additionalC
new CommunityProcedureFacade(
ConfigurationParser.EMPTY,
null,
new User(getUsername(), false),
DatabaseId.of(db.databaseName()),
RequestScopedDependencies.builder()
.with(DatabaseId.of(db.databaseName()))
.with(TerminationFlag.RUNNING_TRUE)
.with(new User(getUsername(), false))
.build(),
ProcedureReturnColumns.EMPTY,
TerminationFlag.RUNNING_TRUE,
null,
algorithmsBusinessFacade,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.neo4j.gds.TestProcedureRunner;
import org.neo4j.gds.TestSupport;
import org.neo4j.gds.algorithms.AlgorithmMemoryValidationService;
import org.neo4j.gds.algorithms.RequestScopedDependencies;
import org.neo4j.gds.algorithms.community.CommunityAlgorithmsFacade;
import org.neo4j.gds.algorithms.community.CommunityAlgorithmsStatsBusinessFacade;
import org.neo4j.gds.algorithms.runner.AlgorithmRunner;
Expand Down Expand Up @@ -289,12 +290,13 @@ private GraphDataScience createFacade() {
new CommunityProcedureFacade(
ConfigurationParser.EMPTY,
null,
new User(getUsername(), false),
DatabaseId.of(db.databaseName()),
RequestScopedDependencies.builder()
.with(DatabaseId.of(db.databaseName()))
.with(new User(getUsername(), false))
.build(),
ProcedureReturnColumns.EMPTY,
null,
null,
null,
statsBusinessFacade,
null,
null
Expand Down
Loading

0 comments on commit ad57a48

Please sign in to comment.