2525import org .neo4j .gds .annotation .CustomProcedure ;
2626import org .neo4j .gds .api .DatabaseId ;
2727import org .neo4j .gds .api .DefaultValue ;
28- import org .neo4j .gds .api .nodeproperties .ValueType ;
2928import org .neo4j .gds .api .schema .ImmutableGraphSchema ;
30- import org .neo4j .gds .api .schema .RelationshipPropertySchema ;
3129import org .neo4j .gds .api .schema .RelationshipSchema ;
3230import org .neo4j .gds .api .schema .RelationshipSchemaEntry ;
3331import org .neo4j .gds .compat .CompatUserAggregator ;
5957import org .neo4j .values .virtual .MapValue ;
6058import org .neo4j .values .virtual .MapValueBuilder ;
6159
62- import java .util .ArrayList ;
63- import java .util .Arrays ;
6460import java .util .HashMap ;
6561import java .util .List ;
6662import java .util .Map ;
@@ -149,6 +145,10 @@ void projectNextRelationship(
149145 AnyValue relationshipConfig ,
150146 AnyValue config
151147 ) {
148+ this .configValidator .validateConfigs (nodesConfig , relationshipConfig );
149+
150+ var data = initGraphData (graphName , config );
151+
152152 @ Nullable MapValue sourceNodePropertyValues = null ;
153153 @ Nullable MapValue targetNodePropertyValues = null ;
154154 NodeLabelToken sourceNodeLabels = NodeLabelTokens .missing ();
@@ -168,16 +168,6 @@ void projectNextRelationship(
168168 }
169169 }
170170
171- var data = initGraphData (
172- graphName ,
173- config ,
174- targetNodePropertyValues ,
175- sourceNodePropertyValues ,
176- targetNodeLabels ,
177- sourceNodeLabels ,
178- relationshipConfig
179- );
180-
181171 data .update (
182172 sourceNode ,
183173 targetNode ,
@@ -189,15 +179,7 @@ void projectNextRelationship(
189179 );
190180 }
191181
192- private GraphImporter initGraphData (
193- TextValue graphName ,
194- AnyValue config ,
195- @ Nullable MapValue sourceNodePropertyValues ,
196- @ Nullable MapValue targetNodePropertyValues ,
197- NodeLabelToken sourceNodeLabels ,
198- NodeLabelToken targetNodeLabels ,
199- AnyValue relationshipConfig
200- ) {
182+ private GraphImporter initGraphData (TextValue graphName , AnyValue config ) {
201183 var data = this .importer ;
202184 if (data != null ) {
203185 return data ;
@@ -212,13 +194,7 @@ private GraphImporter initGraphData(
212194 this .username ,
213195 this .databaseId ,
214196 config ,
215- sourceNodePropertyValues ,
216- targetNodePropertyValues ,
217- sourceNodeLabels ,
218- targetNodeLabels ,
219- relationshipConfig ,
220- this .canWriteToDatabase ,
221- this .lock
197+ this .canWriteToDatabase
222198 );
223199 }
224200 return data ;
@@ -334,28 +310,22 @@ private static final class GraphImporter {
334310 private final String graphName ;
335311 private final GraphProjectFromCypherAggregationConfig config ;
336312 private final LazyIdMapBuilder idMapBuilder ;
337- // private final @Nullable List<RelationshipPropertySchema> relationshipPropertySchemas;
338313
339314 private final boolean canWriteToDatabase ;
340315 private final ExtractNodeId extractNodeId ;
341- private final Lock lock ;
342316 private final Map <RelationshipType , RelationshipsBuilder > relImporters ;
343317 private final ImmutableGraphSchema .Builder graphSchemaBuilder ;
344318
345319 private GraphImporter (
346320 String graphName ,
347321 GraphProjectFromCypherAggregationConfig config ,
348322 LazyIdMapBuilder idMapBuilder ,
349- @ Nullable List <RelationshipPropertySchema > relationshipPropertySchemas ,
350- boolean canWriteToDatabase ,
351- Lock lock
323+ boolean canWriteToDatabase
352324 ) {
353325 this .graphName = graphName ;
354326 this .config = config ;
355327 this .idMapBuilder = idMapBuilder ;
356- // this.relationshipPropertySchemas = relationshipPropertySchemas;
357328 this .canWriteToDatabase = canWriteToDatabase ;
358- this .lock = lock ;
359329 this .relImporters = new ConcurrentHashMap <>();
360330 this .graphSchemaBuilder = ImmutableGraphSchema .builder ();
361331 this .extractNodeId = new ExtractNodeId ();
@@ -366,13 +336,7 @@ static GraphImporter of(
366336 String username ,
367337 DatabaseId databaseId ,
368338 AnyValue configMap ,
369- @ Nullable MapValue sourceNodePropertyValues ,
370- @ Nullable MapValue targetNodePropertyValues ,
371- NodeLabelToken sourceNodeLabels ,
372- NodeLabelToken targetNodeLabels ,
373- AnyValue relationshipConfig ,
374- boolean canWriteToDatabase ,
375- Lock lock
339+ boolean canWriteToDatabase
376340 ) {
377341
378342 var graphName = graphNameValue .stringValue ();
@@ -384,24 +348,9 @@ static GraphImporter of(
384348 (configMap instanceof MapValue ) ? (MapValue ) configMap : MapValue .EMPTY
385349 );
386350
387- var idMapBuilder = idMapBuilder (
388- sourceNodeLabels ,
389- sourceNodePropertyValues ,
390- targetNodeLabels ,
391- targetNodePropertyValues ,
392- config .readConcurrency ()
393- );
394-
395- var relationshipPropertySchemas = relationshipPropertySchemas (relationshipConfig );
351+ var idMapBuilder = idMapBuilder (config .readConcurrency ());
396352
397- return new GraphImporter (
398- graphName ,
399- config ,
400- idMapBuilder ,
401- relationshipPropertySchemas ,
402- canWriteToDatabase ,
403- lock
404- );
353+ return new GraphImporter (graphName , config , idMapBuilder , canWriteToDatabase );
405354 }
406355
407356 private static void validateGraphName (String graphName , String username , DatabaseId databaseId ) {
@@ -410,46 +359,10 @@ private static void validateGraphName(String graphName, String username, Databas
410359 }
411360 }
412361
413- private static LazyIdMapBuilder idMapBuilder (
414- NodeLabelToken sourceNodeLabels ,
415- @ Nullable MapValue sourceNodeProperties ,
416- NodeLabelToken targetNodeLabels ,
417- @ Nullable MapValue targetNodeProperties ,
418- int readConcurrency
419- ) {
362+ private static LazyIdMapBuilder idMapBuilder (int readConcurrency ) {
420363 return new LazyIdMapBuilder (readConcurrency , true , true );
421364 }
422365
423- private static @ Nullable List <RelationshipPropertySchema > relationshipPropertySchemas (AnyValue relationshipConfigValue ) {
424- if (!(relationshipConfigValue instanceof MapValue )) {
425- return null ;
426- }
427-
428- //noinspection PatternVariableCanBeUsed
429- var relationshipConfig = (MapValue ) relationshipConfigValue ;
430-
431- var relationshipPropertySchemas = new ArrayList <RelationshipPropertySchema >();
432-
433- // We need to do this before extracting the `relationshipProperties`, because
434- // we remove the original entry from the map during converting; also we remove null keys
435- // so we could not create a schema entry for properties that are absent on the current relationship
436- var relationshipPropertyKeys = relationshipConfig .get ("properties" );
437- if (relationshipPropertyKeys instanceof MapValue ) {
438- for (var propertyKey : ((MapValue ) relationshipPropertyKeys ).keySet ()) {
439- relationshipPropertySchemas .add (RelationshipPropertySchema .of (
440- propertyKey ,
441- ValueType .DOUBLE
442- ));
443- }
444- }
445-
446- if (relationshipPropertySchemas .isEmpty ()) {
447- return null ;
448- }
449-
450- return relationshipPropertySchemas ;
451- }
452-
453366 void update (
454367 AnyValue sourceNode ,
455368 AnyValue targetNode ,
@@ -590,26 +503,6 @@ private long loadNode(
590503 );
591504 }
592505
593- private static double loadOneRelationshipProperty (
594- @ NotNull MapValue relationshipProperties ,
595- String relationshipPropertyKey
596- ) {
597- var propertyValue = relationshipProperties .get (relationshipPropertyKey );
598- return ReadHelper .extractValue (propertyValue , DefaultValue .DOUBLE_DEFAULT_FALLBACK );
599- }
600-
601- private static double [] loadMultipleRelationshipProperties (
602- @ NotNull MapValue relationshipProperties ,
603- List <RelationshipPropertySchema > relationshipPropertyKeys
604- ) {
605- var propertyValues = new double [relationshipPropertyKeys .size ()];
606- Arrays .setAll (propertyValues , i -> {
607- var relationshipPropertyKey = relationshipPropertyKeys .get (i ).key ();
608- return loadOneRelationshipProperty (relationshipProperties , relationshipPropertyKey );
609- });
610- return propertyValues ;
611- }
612-
613506 private AdjacencyCompressor .ValueMapper buildNodesWithProperties (GraphStoreBuilder graphStoreBuilder ) {
614507 var idMapAndProperties = this .idMapBuilder .build ();
615508
@@ -648,14 +541,6 @@ private void buildRelationshipsWithProperties(
648541 );
649542 var schema = relationships .relationshipSchema (relationshipType );
650543 relationshipSchemas .put (relationshipType , schema .get (relationshipType ));
651- // schema
652- // .entries()
653- // .forEach(entry -> relationshipSchemas.merge(
654- // relationshipType,
655- // entry,
656- // RelationshipSchemaEntry::union
657- // ));
658-
659544 relationshipImportResultBuilder .putImportResult (relationshipType , relationships );
660545 });
661546
0 commit comments