2020package org .neo4j .gds .core .loading ;
2121
2222import org .immutables .value .Value ;
23+ import org .neo4j .gds .NodeLabel ;
24+ import org .neo4j .gds .PropertyMapping ;
25+ import org .neo4j .gds .PropertyMappings ;
2326import org .neo4j .gds .annotation .ValueClass ;
2427import org .neo4j .gds .api .IdMap ;
28+ import org .neo4j .gds .api .PropertyState ;
29+ import org .neo4j .gds .api .properties .nodes .ImmutableNodeProperty ;
2530import org .neo4j .gds .api .properties .nodes .NodePropertyStore ;
31+ import org .neo4j .gds .api .properties .nodes .NodePropertyValues ;
32+ import org .neo4j .gds .api .schema .ImmutablePropertySchema ;
2633import org .neo4j .gds .api .schema .NodeSchema ;
2734
35+ import java .util .Map ;
36+
2837@ ValueClass
2938public interface Nodes {
3039
@@ -37,4 +46,42 @@ default NodePropertyStore properties() {
3746 return NodePropertyStore .empty ();
3847 }
3948
49+ static Nodes of (
50+ IdMap idMap ,
51+ Map <NodeLabel , PropertyMappings > propertyMappings ,
52+ Map <PropertyMapping , NodePropertyValues > propertyValues ,
53+ PropertyState propertyState
54+ ) {
55+ var nodeSchema = NodeSchema .empty ();
56+ var nodePropertyStoreBuilder = NodePropertyStore .builder ();
57+
58+ propertyMappings .forEach (((nodeLabel , mappings ) -> {
59+ if (mappings .mappings ().isEmpty ()) {
60+ nodeSchema .addLabel (nodeLabel );
61+ } else {
62+ mappings .mappings ().forEach (propertyMapping -> {
63+ var nodePropertyValues = propertyValues .get (propertyMapping );
64+ // The default value is either overridden by the user
65+ // or inferred from the actual property value.
66+ var defaultValue = propertyMapping .defaultValue ().isUserDefined ()
67+ ? propertyMapping .defaultValue ()
68+ : nodePropertyValues .valueType ().fallbackValue ();
69+ var propertySchema = ImmutablePropertySchema .builder ()
70+ .key (propertyMapping .propertyKey ())
71+ .valueType (nodePropertyValues .valueType ())
72+ .defaultValue (defaultValue )
73+ .state (propertyState )
74+ .build ();
75+
76+ nodeSchema .addProperty (nodeLabel , propertySchema .key (), propertySchema );
77+ nodePropertyStoreBuilder .putProperty (
78+ propertySchema .key (),
79+ ImmutableNodeProperty .of (nodePropertyValues , propertySchema )
80+ );
81+ });
82+ }
83+ }));
84+
85+ return ImmutableNodes .of (nodeSchema , idMap , nodePropertyStoreBuilder .build ());
86+ }
4087}
0 commit comments