Skip to content

Commit 2734732

Browse files
Use the highest value from NODE and DYNAMIC_NODE id types on block format
Co-Authored-By: Sören Reichardt <[email protected]>
1 parent 6866721 commit 2734732

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

compatibility/4.4/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/_44/Neo4jProxyImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,14 @@ public ProcedureSignature procedureSignature(
537537
public long getHighestPossibleNodeCount(
538538
Read read, IdGeneratorFactory idGeneratorFactory
539539
) {
540-
return countByIdGenerator(idGeneratorFactory, RecordIdType.NODE, RecordIdType.NODE);
540+
return countByIdGenerator(idGeneratorFactory, RecordIdType.NODE);
541541
}
542542

543543
@Override
544544
public long getHighestPossibleRelationshipCount(
545545
Read read, IdGeneratorFactory idGeneratorFactory
546546
) {
547-
return countByIdGenerator(idGeneratorFactory, RecordIdType.RELATIONSHIP, RecordIdType.RELATIONSHIP);
547+
return countByIdGenerator(idGeneratorFactory, RecordIdType.RELATIONSHIP);
548548
}
549549

550550
@Override

compatibility/5-common/neo4j-kernel-adapter/src/main/java17/org/neo4j/gds/compat/_5x/CommonNeo4jProxyImpl.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public List<StoreScan<NodeLabelIndexCursor>> entityCursorScan(
178178
int batchSize,
179179
boolean allowPartitionedScan
180180
) {
181-
return PartitionedStoreScan.createScans(transaction, batchSize, this, labelIds);
181+
return PartitionedStoreScan.createScans(transaction, batchSize, this, labelIds);
182182
}
183183

184184
@Override
@@ -187,7 +187,7 @@ public List<StoreScan<NodeLabelIndexCursor>> partitionedCursorScan(
187187
int batchSize,
188188
int... labelIds
189189
) {
190-
return PartitionedStoreScan.createScans(transaction, batchSize, this, labelIds);
190+
return PartitionedStoreScan.createScans(transaction, batchSize, this, labelIds);
191191
}
192192

193193
@Override
@@ -453,44 +453,49 @@ public Long pageCacheMemoryValue(String value) {
453453
public long getHighestPossibleNodeCount(
454454
Read read, IdGeneratorFactory idGeneratorFactory
455455
) {
456-
return countByIdGenerator(idGeneratorFactory, RecordIdType.NODE, BlockFormat.INSTANCE.nodeType);
456+
return countByIdGenerator(
457+
idGeneratorFactory,
458+
RecordIdType.NODE,
459+
BlockFormat.INSTANCE.nodeType,
460+
BlockFormat.INSTANCE.dynamicNodeType
461+
);
457462
}
458463

459464
@Override
460465
public long getHighestPossibleRelationshipCount(
461466
Read read, IdGeneratorFactory idGeneratorFactory
462467
) {
463-
return countByIdGenerator(idGeneratorFactory, RecordIdType.RELATIONSHIP, BlockFormat.INSTANCE.relationshipType);
468+
return countByIdGenerator(
469+
idGeneratorFactory,
470+
RecordIdType.RELATIONSHIP,
471+
BlockFormat.INSTANCE.relationshipType,
472+
BlockFormat.INSTANCE.dynamicRelationshipType
473+
);
464474
}
465475

466476
private static final class BlockFormat {
467477
private static final BlockFormat INSTANCE = new BlockFormat();
468478

469-
private final org.neo4j.internal.id.IdType nodeType;
470-
private final org.neo4j.internal.id.IdType relationshipType;
479+
private org.neo4j.internal.id.IdType nodeType = null;
480+
private org.neo4j.internal.id.IdType dynamicNodeType = null;
481+
private org.neo4j.internal.id.IdType relationshipType = null;
482+
private org.neo4j.internal.id.IdType dynamicRelationshipType = null;
471483

472484
BlockFormat() {
473-
org.neo4j.internal.id.IdType nodeType = null;
474-
org.neo4j.internal.id.IdType relationshipType = null;
475-
476485
try {
477486
var blockIdType = Class.forName("com.neo4j.internal.blockformat.BlockIdType");
478487
var blockTypes = Objects.requireNonNull(blockIdType.getEnumConstants());
479488
for (Object blockType : blockTypes) {
480489
var type = (Enum<?>) blockType;
481-
if (type.name().equals("NODE")) {
482-
nodeType = (org.neo4j.internal.id.IdType) type;
483-
} else if (type.name().equals("RELATIONSHIP")) {
484-
relationshipType = (org.neo4j.internal.id.IdType) type;
490+
switch (type.name()) {
491+
case "NODE" -> this.nodeType = (org.neo4j.internal.id.IdType) type;
492+
case "DYNAMIC_NODE" -> this.dynamicNodeType = (org.neo4j.internal.id.IdType) type;
493+
case "RELATIONSHIP" -> this.relationshipType = (org.neo4j.internal.id.IdType) type;
494+
case "DYNAMIC_RELATIONSHIP" -> this.dynamicRelationshipType = (org.neo4j.internal.id.IdType) type;
485495
}
486496
}
487-
} catch (ClassNotFoundException | NullPointerException | ClassCastException e) {
488-
nodeType = null;
489-
relationshipType = null;
497+
} catch (ClassNotFoundException | NullPointerException | ClassCastException ignored) {
490498
}
491-
492-
this.nodeType = Objects.requireNonNullElse(nodeType, RecordIdType.NODE);
493-
this.relationshipType = Objects.requireNonNullElse(relationshipType, RecordIdType.RELATIONSHIP);
494499
}
495500
}
496501

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,25 @@ public final class InternalReadOps {
3030

3131
public static long countByIdGenerator(
3232
@Nullable IdGeneratorFactory idGeneratorFactory,
33-
IdType idType,
34-
IdType idType2
33+
IdType... idTypes
3534
) {
36-
return countByIdGenerator(idGeneratorFactory, idType)
37-
.orElseGet(() -> countByIdGenerator(idGeneratorFactory, idType2)
38-
.orElseThrow(() -> new IllegalStateException(
39-
"Unsupported store format for GDS; GDS cannot read data from this database. " +
40-
"Please try to use Cypher projection instead.")));
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.");
46+
}
47+
return highestId;
4148
}
4249

43-
private static OptionalLong countByIdGenerator(@Nullable IdGeneratorFactory idGeneratorFactory, IdType idType) {
44-
if (idGeneratorFactory != null) {
50+
private static OptionalLong countByIdGenerator(@Nullable IdGeneratorFactory idGeneratorFactory, @Nullable IdType idType) {
51+
if (idGeneratorFactory != null && idType != null) {
4552
try {
4653
final IdGenerator idGenerator = idGeneratorFactory.get(idType);
4754
if (idGenerator != null) {

0 commit comments

Comments
 (0)