Skip to content

Commit 1d02761

Browse files
authored
Merge pull request #5184 from soerenreichardt/arrow-export-array-properties
Export array node properties via Flight
2 parents dd1f8ed + 121c6e9 commit 1d02761

File tree

15 files changed

+242
-51
lines changed

15 files changed

+242
-51
lines changed

algo/src/main/java/org/neo4j/gds/louvain/Louvain.java

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.neo4j.gds.api.Graph;
2626
import org.neo4j.gds.api.IdMap;
2727
import org.neo4j.gds.api.RelationshipIterator;
28-
import org.neo4j.gds.api.properties.nodes.LongNodePropertyValues;
2928
import org.neo4j.gds.api.properties.nodes.NodePropertyValues;
3029
import org.neo4j.gds.beta.modularity.ImmutableModularityOptimizationStreamConfig;
3130
import org.neo4j.gds.beta.modularity.ModularityOptimization;
@@ -35,12 +34,11 @@
3534
import org.neo4j.gds.core.concurrency.ParallelUtil;
3635
import org.neo4j.gds.core.loading.construction.GraphFactory;
3736
import org.neo4j.gds.core.loading.construction.RelationshipsBuilder;
37+
import org.neo4j.gds.core.utils.OriginalIdNodePropertyValues;
3838
import org.neo4j.gds.core.utils.paged.HugeLongArray;
3939
import org.neo4j.gds.core.utils.partition.Partition;
4040
import org.neo4j.gds.core.utils.partition.PartitionUtils;
4141
import org.neo4j.gds.core.utils.progress.tasks.ProgressTracker;
42-
import org.neo4j.values.storable.Value;
43-
import org.neo4j.values.storable.Values;
4442

4543
import java.util.Optional;
4644
import java.util.OptionalLong;
@@ -98,7 +96,13 @@ public Louvain compute() {
9896
long maxCommunityId = buildDendrogram(workingGraph, ranLevels, modularityOptimization);
9997

10098
workingGraph = summarizeGraph(workingGraph, modularityOptimization, maxCommunityId);
101-
nextSeedingValues = new OriginalIdNodePropertyValues(workingGraph);
99+
nextSeedingValues = new OriginalIdNodePropertyValues(workingGraph) {
100+
@Override
101+
public OptionalLong getMaxLongPropertyValue() {
102+
// We want to use the maxSeedCommunity with value 0 in all subsequent iterations
103+
return OptionalLong.empty();
104+
}
105+
};
102106

103107
if (workingGraph.nodeCount() == oldNodeCount
104108
|| workingGraph.nodeCount() == 1
@@ -269,34 +273,6 @@ public void release() {
269273
this.rootGraph.releaseTopology();
270274
}
271275

272-
static class OriginalIdNodePropertyValues implements LongNodePropertyValues {
273-
private final Graph graph;
274-
275-
public OriginalIdNodePropertyValues(Graph graph) {
276-
this.graph = graph;
277-
}
278-
279-
@Override
280-
public long longValue(long nodeId) {
281-
return graph.toOriginalNodeId(nodeId);
282-
}
283-
284-
@Override
285-
public Value value(long nodeId) {
286-
return Values.longValue(longValue(nodeId));
287-
}
288-
289-
@Override
290-
public OptionalLong getMaxLongPropertyValue() {
291-
return OptionalLong.empty();
292-
}
293-
294-
@Override
295-
public long size() {
296-
return graph.nodeCount();
297-
}
298-
}
299-
300276
static final class RelationshipCreator implements Runnable {
301277

302278
private final RelationshipsBuilder relationshipsBuilder;

test-utils/src/main/java/org/neo4j/gds/core/IdentityPropertyValues.java renamed to core/src/main/java/org/neo4j/gds/core/utils/IdentityPropertyValues.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* You should have received a copy of the GNU General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
package org.neo4j.gds.core;
20+
package org.neo4j.gds.core.utils;
2121

2222
import org.neo4j.gds.api.properties.nodes.LongNodePropertyValues;
2323

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.core.utils;
21+
22+
import org.neo4j.gds.api.IdMap;
23+
import org.neo4j.gds.api.properties.nodes.LongNodePropertyValues;
24+
25+
import java.util.OptionalLong;
26+
27+
public class OriginalIdNodePropertyValues implements LongNodePropertyValues {
28+
private final IdMap idMap;
29+
30+
public OriginalIdNodePropertyValues(IdMap idMap) {
31+
this.idMap = idMap;
32+
}
33+
34+
@Override
35+
public long longValue(long nodeId) {
36+
return idMap.toOriginalNodeId(nodeId);
37+
}
38+
39+
@Override
40+
public OptionalLong getMaxLongPropertyValue() {
41+
return OptionalLong.of(idMap.highestNeoId());
42+
}
43+
44+
@Override
45+
public long size() {
46+
return idMap.nodeCount();
47+
}
48+
}

core/src/test/java/org/neo4j/gds/core/loading/GraphStoreCatalogTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import static org.junit.jupiter.api.Assertions.assertNotEquals;
4444
import static org.junit.jupiter.api.Assertions.assertTrue;
4545
import static org.junit.jupiter.api.Assertions.fail;
46-
import static org.neo4j.gds.extension.GdlSupportExtension.DATABASE_ID;
46+
import static org.neo4j.gds.extension.GdlSupportPerMethodExtension.DATABASE_ID;
4747

4848
@GdlExtension
4949
class GraphStoreCatalogTest {

proc/catalog/src/test/java/org/neo4j/gds/catalog/GraphStreamNodePropertiesProcTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
import org.neo4j.gds.PropertyMappings;
3333
import org.neo4j.gds.api.GraphStore;
3434
import org.neo4j.gds.api.properties.nodes.NodePropertyValues;
35-
import org.neo4j.gds.core.IdentityPropertyValues;
3635
import org.neo4j.gds.core.loading.GraphStoreCatalog;
36+
import org.neo4j.gds.core.utils.IdentityPropertyValues;
3737
import org.neo4j.gds.functions.AsNodeFunc;
3838

3939
import java.util.Map;

proc/catalog/src/test/java/org/neo4j/gds/catalog/GraphWriteNodePropertiesProcTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
import org.neo4j.gds.api.properties.nodes.NodePropertyValues;
3636
import org.neo4j.gds.compat.Neo4jProxy;
3737
import org.neo4j.gds.compat.TestLog;
38-
import org.neo4j.gds.core.IdentityPropertyValues;
3938
import org.neo4j.gds.core.loading.GraphStoreCatalog;
39+
import org.neo4j.gds.core.utils.IdentityPropertyValues;
4040
import org.neo4j.gds.core.write.NativeNodePropertiesExporterBuilder;
4141
import org.neo4j.gds.degree.DegreeCentralityMutateProc;
4242
import org.neo4j.gds.pagerank.PageRankMutateProc;

test-utils/src/main/java/org/neo4j/gds/TestSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.neo4j.gds.core.GraphDimensions;
3838
import org.neo4j.gds.core.loading.construction.GraphFactory;
3939
import org.neo4j.gds.core.utils.mem.MemoryEstimation;
40-
import org.neo4j.gds.extension.GdlSupportExtension;
40+
import org.neo4j.gds.extension.GdlSupportPerMethodExtension;
4141
import org.neo4j.gds.extension.IdFunction;
4242
import org.neo4j.gds.extension.TestGraph;
4343
import org.neo4j.gds.gdl.GdlFactory;
@@ -155,7 +155,7 @@ public static TestGraph gdl(
155155
.builder()
156156
.nodeIdFunction(idSupplier.orElse(new OffsetIdSupplier(0L)))
157157
.graphProjectConfig(config)
158-
.namedDatabaseId(GdlSupportExtension.DATABASE_ID)
158+
.namedDatabaseId(GdlSupportPerMethodExtension.DATABASE_ID)
159159
.build();
160160

161161
return new TestGraph(gdlFactory.build().getUnion(), gdlFactory::nodeId, graphName);

test-utils/src/main/java/org/neo4j/gds/extension/GdlSupportExtension.java renamed to test-utils/src/main/java/org/neo4j/gds/extension/BaseGdlSupportExtension.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
package org.neo4j.gds.extension;
2121

2222
import org.immutables.value.Value;
23-
import org.junit.jupiter.api.extension.AfterEachCallback;
24-
import org.junit.jupiter.api.extension.BeforeEachCallback;
2523
import org.junit.jupiter.api.extension.ExtensionConfigurationException;
2624
import org.junit.jupiter.api.extension.ExtensionContext;
2725
import org.neo4j.gds.Orientation;
@@ -52,18 +50,16 @@
5250
import static org.neo4j.gds.extension.ExtensionUtil.getStringValueOfField;
5351
import static org.neo4j.gds.extension.ExtensionUtil.setField;
5452

55-
public class GdlSupportExtension implements BeforeEachCallback, AfterEachCallback {
53+
abstract class BaseGdlSupportExtension {
5654

5755
public static final NamedDatabaseId DATABASE_ID = DatabaseIdFactory.from("GDL", UUID.fromString("42-42-42-42-42"));
5856

59-
@Override
60-
public void beforeEach(ExtensionContext context) {
57+
void beforeAction(ExtensionContext context) {
6158
Class<?> requiredTestClass = context.getRequiredTestClass();
6259
gdlGraphs(requiredTestClass).forEach(setup -> injectGraphStore(setup, context));
6360
}
6461

65-
@Override
66-
public void afterEach(ExtensionContext context) {
62+
void afterAction(ExtensionContext context) {
6763
GraphStoreCatalog.removeAllLoadedGraphs();
6864
}
6965

@@ -73,7 +69,7 @@ private static Collection<GdlGraphSetup> gdlGraphs(Class<?> testClass) {
7369
do {
7470
stream(testClass.getDeclaredFields())
7571
.filter(f -> f.isAnnotationPresent(GdlGraph.class) || f.isAnnotationPresent(GdlGraphs.class))
76-
.flatMap(GdlSupportExtension::gdlGraphsForField)
72+
.flatMap(BaseGdlSupportExtension::gdlGraphsForField)
7773
.peek(setup -> {
7874
if (setups.contains(setup)) {
7975
throw new ExtensionConfigurationException(String.format(
@@ -158,7 +154,13 @@ private static void injectGraphStore(GdlGraphSetup gdlGraphSetup, ExtensionConte
158154
});
159155
}
160156

161-
private static <T> void injectInstance(Object testInstance, String graphNamePrefix, T instance, Class<T> clazz, String suffix) {
157+
private static <T> void injectInstance(
158+
Object testInstance,
159+
String graphNamePrefix,
160+
T instance,
161+
Class<T> clazz,
162+
String suffix
163+
) {
162164
Stream.<Class<?>>iterate(testInstance.getClass(), Objects::nonNull, Class::getSuperclass)
163165
.flatMap(c -> Arrays.stream(c.getDeclaredFields()))
164166
.filter(field -> field.getType() == clazz)

test-utils/src/main/java/org/neo4j/gds/extension/GdlExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
@Inherited
3131
@Target({ElementType.TYPE, ElementType.METHOD})
3232
@Retention(RetentionPolicy.RUNTIME)
33-
@ExtendWith(GdlSupportExtension.class)
33+
@ExtendWith(GdlSupportPerMethodExtension.class)
3434
public @interface GdlExtension {
3535
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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.extension;
21+
22+
import org.junit.jupiter.api.TestInstance;
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
25+
import java.lang.annotation.ElementType;
26+
import java.lang.annotation.Inherited;
27+
import java.lang.annotation.Retention;
28+
import java.lang.annotation.RetentionPolicy;
29+
import java.lang.annotation.Target;
30+
31+
@Inherited
32+
@Target({ElementType.TYPE, ElementType.METHOD})
33+
@Retention(RetentionPolicy.RUNTIME)
34+
@ExtendWith(GdlSupportPerClassExtension.class)
35+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
36+
public @interface GdlPerClassExtension {
37+
}

0 commit comments

Comments
 (0)