Skip to content

Commit 195a184

Browse files
committed
Move the nodeFilter to the procedure configuration
1 parent aa7dd1d commit 195a184

File tree

4 files changed

+69
-50
lines changed

4 files changed

+69
-50
lines changed

core/src/main/java/org/neo4j/gds/config/WriteLabelConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ public interface WriteLabelConfig extends BaseConfig, ConcurrencyConfig {
3333
static WriteLabelConfig of(Map<String, Object> rawConfig) {
3434
return new WriteLabelConfigImpl(CypherMapWrapper.create(rawConfig));
3535
}
36+
37+
String nodeFilter();
3638
}

proc/catalog/src/main/java/org/neo4j/gds/catalog/GraphWriteNodeLabelFilteredProc.java renamed to proc/catalog/src/main/java/org/neo4j/gds/catalog/GraphWriteNodeLabelProc.java

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,16 @@
4040

4141
import static org.neo4j.procedure.Mode.WRITE;
4242

43-
public class GraphWriteNodeLabelFilteredProc extends CatalogProc {
43+
public class GraphWriteNodeLabelProc extends CatalogProc {
4444

4545
@Context
4646
public NodeLabelExporterBuilder<? extends NodeLabelExporter> nodeLabelExporterBuilder;
4747

4848
@Procedure(name = "gds.alpha.graph.nodeLabel.writeFiltered", mode = WRITE)
4949
@Description("Writes the given node Label to an online Neo4j database.")
50-
public Stream<Result> writeNodeLabelFiltered(
50+
public Stream<WriteLabelResult> write(
5151
@Name(value = "graphName") String graphName,
5252
@Name(value = "nodeLabel") String nodeLabel,
53-
@Name(value = "nodePropertyFilter") String nodePropertyFilter,
5453
@Name(value = "configuration", defaultValue = "{}") Map<String, Object> configuration
5554
) throws ParseException {
5655

@@ -59,9 +58,9 @@ public Stream<Result> writeNodeLabelFiltered(
5958
var procedureConfig = WriteLabelConfig.of(configuration);
6059

6160
var graphStore = graphStoreFromCatalog(graphName).graphStore();
62-
var filter = ExpressionParser.parse(nodePropertyFilter, Map.of());
61+
var filter = ExpressionParser.parse(procedureConfig.nodeFilter(), Map.of());
6362

64-
Result.Builder resultBuilder = new Result.Builder(graphName, nodeLabel);
63+
WriteLabelResult.Builder resultBuilder = new WriteLabelResult.Builder(graphName, nodeLabel);
6564
try (ProgressTimer ignored = ProgressTimer.start(resultBuilder::withWriteMillis)) {
6665
var filteredNodes = NodesFilter.filterNodes(
6766
graphStore,
@@ -89,46 +88,4 @@ public Stream<Result> writeNodeLabelFiltered(
8988

9089
return Stream.of(resultBuilder.build());
9190
}
92-
93-
@SuppressWarnings("unused")
94-
public static class Result {
95-
public final long writeMillis;
96-
public final String graphName;
97-
public final String nodeLabel;
98-
public final long nodeLabelsWritten;
99-
100-
Result(long writeMillis, String graphName, String nodeLabel, long nodeLabelsWritten) {
101-
this.writeMillis = writeMillis;
102-
this.graphName = graphName;
103-
this.nodeLabel = nodeLabel;
104-
this.nodeLabelsWritten = nodeLabelsWritten;
105-
}
106-
107-
static class Builder {
108-
private final String graphName;
109-
private final String nodeLabel;
110-
private long nodeLabelsWritten;
111-
private long writeMillis;
112-
113-
Builder(String graphName, String nodeLabel) {
114-
this.graphName = graphName;
115-
this.nodeLabel = nodeLabel;
116-
}
117-
118-
Builder withWriteMillis(long writeMillis) {
119-
this.writeMillis = writeMillis;
120-
return this;
121-
}
122-
123-
Builder withNodeLabelsWritten(long propertiesWritten) {
124-
this.nodeLabelsWritten = propertiesWritten;
125-
return this;
126-
}
127-
128-
Result build() {
129-
return new Result(writeMillis, graphName, nodeLabel, nodeLabelsWritten);
130-
}
131-
}
132-
}
133-
13491
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.catalog;
21+
22+
public class WriteLabelResult {
23+
public final long writeMillis;
24+
public final String graphName;
25+
public final String nodeLabel;
26+
public final long nodeLabelsWritten;
27+
28+
WriteLabelResult(long writeMillis, String graphName, String nodeLabel, long nodeLabelsWritten) {
29+
this.writeMillis = writeMillis;
30+
this.graphName = graphName;
31+
this.nodeLabel = nodeLabel;
32+
this.nodeLabelsWritten = nodeLabelsWritten;
33+
}
34+
35+
static class Builder {
36+
private final String graphName;
37+
private final String nodeLabel;
38+
private long nodeLabelsWritten;
39+
private long writeMillis;
40+
41+
Builder(String graphName, String nodeLabel) {
42+
this.graphName = graphName;
43+
this.nodeLabel = nodeLabel;
44+
}
45+
46+
Builder withWriteMillis(long writeMillis) {
47+
this.writeMillis = writeMillis;
48+
return this;
49+
}
50+
51+
Builder withNodeLabelsWritten(long propertiesWritten) {
52+
this.nodeLabelsWritten = propertiesWritten;
53+
return this;
54+
}
55+
56+
WriteLabelResult build() {
57+
return new WriteLabelResult(writeMillis, graphName, nodeLabel, nodeLabelsWritten);
58+
}
59+
}
60+
}

proc/catalog/src/test/java/org/neo4j/gds/catalog/GraphWriteNodeLabelFilteredProcTest.java renamed to proc/catalog/src/test/java/org/neo4j/gds/catalog/GraphWriteNodeLabelProcTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import static org.assertj.core.api.Assertions.assertThat;
3232
import static org.assertj.core.api.InstanceOfAssertFactories.LONG;
3333

34-
class GraphWriteNodeLabelFilteredProcTest extends BaseProcTest {
34+
class GraphWriteNodeLabelProcTest extends BaseProcTest {
3535

3636
@Neo4jGraph(offsetIds = true)
3737
private static final String DB_CYPHER =
@@ -45,7 +45,7 @@ class GraphWriteNodeLabelFilteredProcTest extends BaseProcTest {
4545
void setUp() throws Exception {
4646
registerProcedures(
4747
GraphProjectProc.class,
48-
GraphWriteNodeLabelFilteredProc.class
48+
GraphWriteNodeLabelProc.class
4949
);
5050
}
5151

@@ -65,7 +65,7 @@ void writeFilteredNodeLabels() {
6565
);
6666

6767
runQuery(
68-
"CALL gds.alpha.graph.nodeLabel.writeFiltered('graph', 'TestLabel', 'n:A AND n.p > 1.0', {}) YIELD nodeLabelsWritten",
68+
"CALL gds.alpha.graph.nodeLabel.writeFiltered('graph', 'TestLabel', { nodeFilter: 'n:A AND n.p > 1.0' }) YIELD nodeLabelsWritten",
6969
result -> {
7070
assertThat(result.hasNext()).isTrue();
7171

0 commit comments

Comments
 (0)