Skip to content

Commit 04b79e3

Browse files
committed
Support offset test graphs on block format (5.22+)
1 parent e2d9548 commit 04b79e3

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

compatibility/common/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/Neo4jProxy.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
import java.util.stream.Stream;
109109

110110
import static java.lang.String.format;
111-
import static org.neo4j.gds.compat.InternalReadOps.countByIdGenerator;
112111

113112
public final class Neo4jProxy {
114113

@@ -519,12 +518,15 @@ public static Long pageCacheMemoryValue(String value) {
519518
}
520519

521520
public static long getHighestPossibleNodeCount(IdGeneratorFactory idGeneratorFactory) {
522-
return countByIdGenerator(
523-
idGeneratorFactory,
524-
RecordIdType.NODE,
525-
BlockFormat.INSTANCE.nodeType,
526-
BlockFormat.INSTANCE.dynamicNodeType
527-
);
521+
return InternalReadOps.findValidIdGeneratorsStream(
522+
idGeneratorFactory,
523+
RecordIdType.NODE,
524+
BlockFormat.INSTANCE.nodeType,
525+
BlockFormat.INSTANCE.dynamicNodeType
526+
)
527+
.mapToLong(IdGenerator::getHighId)
528+
.max()
529+
.orElseThrow(InternalReadOps::unsupportedStoreFormatException);
528530
}
529531

530532
public static long getHighestPossibleRelationshipCount(Read read) {
@@ -668,7 +670,13 @@ public static long transactionId(KernelTransaction kernelTransaction) {
668670
}
669671

670672
public static void reserveNeo4jIds(IdGeneratorFactory generatorFactory, int size, CursorContext cursorContext) {
671-
IdGenerator idGenerator = generatorFactory.get(RecordIdType.NODE);
673+
var idGenerator = InternalReadOps.findValidIdGeneratorsStream(
674+
generatorFactory,
675+
RecordIdType.NODE,
676+
BlockFormat.INSTANCE.nodeType,
677+
BlockFormat.INSTANCE.dynamicNodeType
678+
)
679+
.findFirst().orElseThrow(InternalReadOps::unsupportedStoreFormatException);
672680

673681
idGenerator.nextConsecutiveIdRange(size, false, cursorContext);
674682
}

neo4j-adapter/src/main/java/org/neo4j/gds/compat/InternalReadOps.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,33 @@
2424
import org.neo4j.internal.id.IdGeneratorFactory;
2525
import org.neo4j.internal.id.IdType;
2626

27-
import java.util.OptionalLong;
27+
import java.util.Arrays;
28+
import java.util.stream.Stream;
2829

2930
public final class InternalReadOps {
3031

31-
public static long countByIdGenerator(
32+
public static Stream<IdGenerator> findValidIdGeneratorsStream(
3233
@Nullable IdGeneratorFactory idGeneratorFactory,
3334
IdType... idTypes
3435
) {
35-
long highestId = Long.MIN_VALUE;
36-
for (IdType idType : idTypes) {
37-
final OptionalLong count = countByIdGenerator(idGeneratorFactory, idType);
38-
if (count.isPresent()) {
39-
highestId = Math.max(highestId, count.getAsLong());
40-
}
41-
}
42-
if (highestId == Long.MIN_VALUE) {
43-
throw new IllegalStateException(
44-
"Unsupported store format for GDS; GDS cannot read data from this database. " +
45-
"Please try to use Cypher projection instead.");
36+
if (idGeneratorFactory == null || idTypes.length == 0) {
37+
return Stream.empty();
4638
}
47-
return highestId;
48-
}
49-
50-
private static OptionalLong countByIdGenerator(@Nullable IdGeneratorFactory idGeneratorFactory, @Nullable IdType idType) {
51-
if (idGeneratorFactory != null && idType != null) {
39+
return Arrays.stream(idTypes).mapMulti((idType, downstream) -> {
5240
try {
53-
final IdGenerator idGenerator = idGeneratorFactory.get(idType);
41+
var idGenerator = idGeneratorFactory.get(idType);
5442
if (idGenerator != null) {
55-
// getHighId returns the highestId + 1, which is actually a count
56-
return OptionalLong.of(idGenerator.getHighId());
43+
downstream.accept(idGenerator);
5744
}
5845
} catch (Exception ignored) {
5946
}
60-
}
61-
return OptionalLong.empty();
47+
});
48+
}
49+
50+
public static IllegalStateException unsupportedStoreFormatException() {
51+
return new IllegalStateException(
52+
"Unsupported store format for GDS; GDS cannot read data from this database. " +
53+
"Please try to use Cypher projection instead.");
6254
}
6355

6456
private InternalReadOps() {

0 commit comments

Comments
 (0)