Skip to content

Commit d35742e

Browse files
committed
Use lazily built node schema in Cypher Aggregation
1 parent 77d1e01 commit d35742e

File tree

2 files changed

+21
-74
lines changed

2 files changed

+21
-74
lines changed

core/src/main/java/org/neo4j/gds/core/loading/LazyIdMapBuilder.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.neo4j.gds.annotation.ValueClass;
2323
import org.neo4j.gds.api.IdMap;
2424
import org.neo4j.gds.api.PartialIdMap;
25+
import org.neo4j.gds.api.properties.nodes.NodePropertyStore;
2526
import org.neo4j.gds.api.properties.nodes.NodePropertyValues;
2627
import org.neo4j.gds.api.schema.NodeSchema;
2728
import org.neo4j.gds.core.loading.construction.GraphFactory;
@@ -31,7 +32,6 @@
3132
import org.neo4j.gds.core.utils.paged.ShardedLongLongMap;
3233

3334
import java.util.Map;
34-
import java.util.Optional;
3535
import java.util.OptionalLong;
3636
import java.util.concurrent.atomic.AtomicBoolean;
3737

@@ -113,7 +113,11 @@ public interface HighLimitIdMapAndProperties {
113113

114114
NodeSchema schema();
115115

116-
Optional<Map<String, NodePropertyValues>> nodeProperties();
116+
NodePropertyStore propertyStore();
117+
118+
default Map<String, NodePropertyValues> properties() {
119+
return propertyStore().propertyValues();
120+
}
117121
}
118122

119123
public HighLimitIdMapAndProperties build() {
@@ -145,7 +149,7 @@ public OptionalLong rootNodeCount() {
145149
.idMap(idMap)
146150
.intermediateIdMap(partialIdMap)
147151
.schema(nodes.schema())
148-
.nodeProperties(nodes.properties().propertyValues())
152+
.propertyStore(nodes.properties())
149153
.build();
150154
}
151155
}

cypher-aggregation/src/main/java/org/neo4j/gds/projection/GraphAggregator.java

Lines changed: 14 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,18 @@
2121

2222
import org.jetbrains.annotations.NotNull;
2323
import org.jetbrains.annotations.Nullable;
24-
import org.neo4j.gds.NodeLabel;
2524
import org.neo4j.gds.RelationshipType;
2625
import org.neo4j.gds.annotation.CustomProcedure;
2726
import org.neo4j.gds.api.DatabaseId;
2827
import org.neo4j.gds.api.DefaultValue;
29-
import org.neo4j.gds.api.PropertyState;
3028
import org.neo4j.gds.api.nodeproperties.ValueType;
31-
import org.neo4j.gds.api.properties.nodes.NodePropertyValues;
3229
import org.neo4j.gds.api.schema.ImmutableGraphSchema;
33-
import org.neo4j.gds.api.schema.NodeSchema;
34-
import org.neo4j.gds.api.schema.PropertySchema;
3530
import org.neo4j.gds.api.schema.RelationshipPropertySchema;
3631
import org.neo4j.gds.api.schema.RelationshipSchema;
3732
import org.neo4j.gds.compat.CompatUserAggregator;
3833
import org.neo4j.gds.core.Aggregation;
3934
import org.neo4j.gds.core.ConfigKeyValidation;
4035
import org.neo4j.gds.core.compress.AdjacencyCompressor;
41-
import org.neo4j.gds.core.loading.CSRGraphStoreUtil;
4236
import org.neo4j.gds.core.loading.GraphStoreBuilder;
4337
import org.neo4j.gds.core.loading.GraphStoreCatalog;
4438
import org.neo4j.gds.core.loading.ImmutableNodes;
@@ -188,8 +182,7 @@ void projectNextRelationship(
188182
targetNodePropertyValues,
189183
sourceNodeLabels,
190184
targetNodeLabels,
191-
relationshipConfig,
192-
this.configValidator
185+
relationshipConfig
193186
);
194187
}
195188

@@ -334,7 +327,6 @@ void validateConfigs(AnyValue nodesConfig, AnyValue relationshipConfig) {
334327
}
335328

336329
// Does the actual importing work once we can initialize it with the first row
337-
@SuppressWarnings("CodeBlock2Expr")
338330
private static final class GraphImporter {
339331
private final String graphName;
340332
private final GraphProjectFromCypherAggregationConfig config;
@@ -464,8 +456,7 @@ void update(
464456
@Nullable MapValue targetNodePropertyValues,
465457
NodeLabelToken sourceNodeLabels,
466458
NodeLabelToken targetNodeLabels,
467-
AnyValue relationshipConfig,
468-
ConfigValidator configValidator
459+
AnyValue relationshipConfig
469460
) {
470461
MapValue relationshipProperties = null;
471462
RelationshipType relationshipType = RelationshipType.ALL_RELATIONSHIPS;
@@ -624,75 +615,27 @@ private static double[] loadMultipleRelationshipProperties(
624615
}
625616

626617
private AdjacencyCompressor.ValueMapper buildNodesWithProperties(GraphStoreBuilder graphStoreBuilder) {
627-
628618
var idMapAndProperties = this.idMapBuilder.build();
629-
var nodes = idMapAndProperties.idMap();
630-
631-
var maybeNodeProperties = idMapAndProperties.nodeProperties();
632-
633-
var nodesBuilder = ImmutableNodes.builder().idMap(nodes);
634-
635-
var nodePropertySchema = maybeNodeProperties
636-
.map(nodeProperties -> nodeSchemaWithProperties(
637-
nodes.availableNodeLabels(),
638-
nodeProperties
639-
))
640-
.orElseGet(() -> nodeSchemaWithoutProperties(nodes.availableNodeLabels()))
641-
.unionProperties();
642-
643-
NodeSchema nodeSchema = NodeSchema.empty();
644-
nodes.availableNodeLabels().forEach(nodeSchema::getOrCreateLabel);
645-
nodePropertySchema.forEach((propertyKey, propertySchema) -> {
646-
nodes.availableNodeLabels().forEach(label -> {
647-
nodeSchema.getOrCreateLabel(label).addProperty(propertySchema.key(), propertySchema);
648-
});
649-
});
619+
620+
var idMap = idMapAndProperties.idMap();
621+
var nodeSchema = idMapAndProperties.schema();
650622

651623
this.graphSchemaBuilder.nodeSchema(nodeSchema);
652624

653-
maybeNodeProperties.ifPresent(allNodeProperties -> {
654-
CSRGraphStoreUtil.extractNodeProperties(
655-
nodesBuilder,
656-
nodePropertySchema::get,
657-
allNodeProperties
658-
);
659-
});
625+
var nodes = ImmutableNodes
626+
.builder()
627+
.idMap(idMap)
628+
.schema(nodeSchema)
629+
.properties(idMapAndProperties.propertyStore())
630+
.build();
660631

661-
graphStoreBuilder.nodes(nodesBuilder.schema(nodeSchema).build());
632+
// graphStoreBuilder.nodes(nodesBuilder.schema(nodeSchema).build());
633+
graphStoreBuilder.nodes(nodes);
662634

663635
// Relationships are added using their intermediate node ids.
664636
// In order to map to the final internal ids, we need to use
665637
// the mapping function of the wrapped id map.
666-
return nodes.rootIdMap()::toMappedNodeId;
667-
}
668-
669-
private static NodeSchema nodeSchemaWithProperties(
670-
Iterable<NodeLabel> nodeLabels,
671-
Map<String, NodePropertyValues> propertyMap
672-
) {
673-
var nodeSchema = NodeSchema.empty();
674-
675-
nodeLabels.forEach((nodeLabel) -> {
676-
propertyMap.forEach((propertyName, nodeProperties) -> {
677-
nodeSchema.getOrCreateLabel(nodeLabel).addProperty(
678-
propertyName,
679-
PropertySchema.of(
680-
propertyName,
681-
nodeProperties.valueType(),
682-
nodeProperties.valueType().fallbackValue(),
683-
PropertyState.TRANSIENT
684-
)
685-
);
686-
});
687-
});
688-
689-
return nodeSchema;
690-
}
691-
692-
private static NodeSchema nodeSchemaWithoutProperties(Iterable<NodeLabel> nodeLabels) {
693-
var nodeSchema = NodeSchema.empty();
694-
nodeLabels.forEach(nodeSchema::getOrCreateLabel);
695-
return nodeSchema;
638+
return idMap.rootIdMap()::toMappedNodeId;
696639
}
697640

698641
private void buildRelationshipsWithProperties(

0 commit comments

Comments
 (0)