Skip to content

Commit 5d510a4

Browse files
Remove NodePropertyWriter.java as a copy
1 parent e4c68fe commit 5d510a4

File tree

10 files changed

+93
-310
lines changed

10 files changed

+93
-310
lines changed

applications/algorithms/machinery/src/main/java/org/neo4j/gds/applications/algorithms/machinery/Neo4jDatabaseNodePropertyWriter.java

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020
package org.neo4j.gds.applications.algorithms.machinery;
2121

22-
import org.apache.commons.lang3.mutable.MutableLong;
2322
import org.neo4j.gds.api.Graph;
2423
import org.neo4j.gds.api.GraphStore;
2524
import org.neo4j.gds.api.PropertyState;
@@ -46,7 +45,6 @@
4645
import java.util.Map;
4746
import java.util.Optional;
4847
import java.util.function.Predicate;
49-
import java.util.stream.Collectors;
5048

5149
import static org.neo4j.gds.utils.StringFormatting.formatWithLocale;
5250

@@ -102,7 +100,13 @@ static NodePropertiesWritten writeNodeProperties(
102100
Log log
103101
) {
104102

105-
var propertiesWritten = new MutableLong();
103+
104+
validatePropertiesCanBeWritten(
105+
graphStore.capabilities().writeMode(),
106+
graph.schema().nodeSchema().unionProperties(),
107+
nodeProperties,
108+
resultStore.isPresent()
109+
);
106110

107111
var progressTracker = createProgressTracker(
108112
taskRegistryFactory,
@@ -111,16 +115,6 @@ static NodePropertiesWritten writeNodeProperties(
111115
procedureName,
112116
log
113117
);
114-
var writeMode = graphStore.capabilities().writeMode();
115-
var nodePropertySchema = graph.schema().nodeSchema().unionProperties();
116-
117-
118-
validatePropertiesCanBeWritten(
119-
writeMode,
120-
nodePropertySchema,
121-
nodeProperties,
122-
resultStore.isPresent()
123-
);
124118

125119
var exporter = nodePropertyExporterBuilder
126120
.withIdMap(graph)
@@ -133,15 +127,13 @@ static NodePropertiesWritten writeNodeProperties(
133127

134128
try {
135129
exporter.write(nodeProperties);
136-
propertiesWritten.setValue(exporter.propertiesWritten());
130+
return new NodePropertiesWritten(exporter.propertiesWritten());
137131
} catch (Exception e) {
138132
progressTracker.endSubTaskWithFailure();
139133
throw e;
140134
} finally {
141135
progressTracker.release();
142136
}
143-
144-
return new NodePropertiesWritten(propertiesWritten.getValue());
145137
}
146138

147139
private static ProgressTracker createProgressTracker(
@@ -190,7 +182,7 @@ private static void validatePropertiesCanBeWritten(
190182
propertySchemas.get(nodeProperty.key()).state()
191183
)
192184
)
193-
.collect(Collectors.toList());
185+
.toList();
194186

195187
if (!unexpectedProperties.isEmpty()) {
196188
throw new IllegalStateException(
@@ -204,22 +196,21 @@ private static void validatePropertiesCanBeWritten(
204196
}
205197

206198
private static Predicate<PropertyState> expectedPropertyStateForWriteMode(Capabilities.WriteMode writeMode) {
207-
switch (writeMode) {
208-
case LOCAL:
199+
return switch (writeMode) {
200+
case LOCAL ->
209201
// We need to allow persistent and transient as for example algorithms that support seeding will reuse a
210202
// mutated (transient) property to write back properties that are in fact backed by a database
211-
return state -> state == PropertyState.PERSISTENT || state == PropertyState.TRANSIENT;
212-
case REMOTE:
203+
state -> state == PropertyState.PERSISTENT || state == PropertyState.TRANSIENT;
204+
case REMOTE ->
213205
// We allow transient properties for the same reason as above
214-
return state -> state == PropertyState.REMOTE || state == PropertyState.TRANSIENT;
215-
default:
216-
throw new IllegalStateException(
217-
formatWithLocale(
218-
"Graph with write mode `%s` cannot write back to a database",
219-
writeMode
220-
)
221-
);
222-
}
206+
state -> state == PropertyState.REMOTE || state == PropertyState.TRANSIENT;
207+
default -> throw new IllegalStateException(
208+
formatWithLocale(
209+
"Graph with write mode `%s` cannot write back to a database",
210+
writeMode
211+
)
212+
);
213+
};
223214
}
224215

225216
}

applications/algorithms/machinery/src/main/java/org/neo4j/gds/applications/algorithms/machinery/NodePropertyWriter.java

Lines changed: 0 additions & 189 deletions
This file was deleted.

applications/algorithms/machinery/src/main/java/org/neo4j/gds/applications/algorithms/machinery/WriteNodePropertyService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ public NodePropertiesWritten perform(
7676
WriteConfig writeConfiguration,
7777
Label label,
7878
JobId jobId,
79-
List<NodePropertyRecord> nodePropertes
79+
List<NodePropertyRecord> nodeProperties
8080
) {
8181
return Neo4jDatabaseNodePropertyWriter.writeNodeProperties(
8282
writeContext.nodePropertyExporterBuilder(),
8383
requestScopedDependencies.taskRegistryFactory(),
8484
graph,
8585
graphStore,
8686
writeConfiguration.writeConcurrency(),
87-
nodePropertes,
87+
nodeProperties,
8888
label.asString(),
8989
writeConfiguration.resolveResultStore(resultStore),
9090
jobId,

proc/machine-learning/src/test/java/org/neo4j/gds/ml/pipeline/node/classification/NodeClassificationPipelineAddStepProcsTest.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.junit.jupiter.api.Test;
2525
import org.neo4j.gds.BaseProcTest;
2626
import org.neo4j.gds.api.User;
27+
import org.neo4j.gds.applications.algorithms.machinery.RequestScopedDependencies;
28+
import org.neo4j.gds.applications.algorithms.machinery.WriteContext;
2729
import org.neo4j.gds.core.utils.logging.GdsLoggers;
2830
import org.neo4j.gds.core.utils.progress.tasks.LoggerForProgressTracking;
2931
import org.neo4j.gds.logging.Log;
@@ -46,6 +48,13 @@
4648
class NodeClassificationPipelineAddStepProcsTest extends BaseProcTest {
4749
@BeforeEach
4850
void setUp() {
51+
52+
var requestScopedDependencies = RequestScopedDependencies.builder()
53+
.user(new User(getUsername(), false))
54+
.build();
55+
56+
var writeContext = WriteContext.builder().build();
57+
4958
LocalPipelinesProcedureFacade.create(
5059
new GdsLoggers(Log.noOpLog(), LoggerForProgressTracking.noOpLog()),
5160
null,
@@ -57,13 +66,8 @@ void setUp() {
5766
null,
5867
null,
5968
null,
60-
null,
61-
null,
62-
null,
63-
null,
64-
null,
65-
null,
66-
new User(getUsername(), false),
69+
requestScopedDependencies,
70+
writeContext,
6771
null,
6872
null,
6973
null,
@@ -321,6 +325,12 @@ void shouldThrowIfAddingFeatureToANonPipeline() {
321325
}
322326

323327
private GraphDataScienceProcedures buildFacade() {
328+
var requestScopedDependencies = RequestScopedDependencies.builder()
329+
.user(new User(getUsername(), false))
330+
.build();
331+
332+
var writeContext = WriteContext.builder().build();
333+
324334
return new GraphDataScienceProceduresBuilder(Log.noOpLog())
325335
.with(LocalPipelinesProcedureFacade.create(
326336
new GdsLoggers(Log.noOpLog(), LoggerForProgressTracking.noOpLog()),
@@ -333,13 +343,8 @@ private GraphDataScienceProcedures buildFacade() {
333343
null,
334344
null,
335345
null,
336-
null,
337-
null,
338-
null,
339-
null,
340-
null,
341-
null,
342-
new User(getUsername(), false),
346+
requestScopedDependencies,
347+
writeContext,
343348
null,
344349
null,
345350
null,

0 commit comments

Comments
 (0)