19
19
*/
20
20
package org .neo4j .graphalgo .core .utils .export ;
21
21
22
- import org .eclipse .collections .impl .tuple .Tuples ;
23
22
import org .jetbrains .annotations .NotNull ;
24
23
import org .jetbrains .annotations .TestOnly ;
25
24
import org .neo4j .common .Validator ;
65
64
import java .util .stream .Collectors ;
66
65
import java .util .stream .Stream ;
67
66
67
+ import static org .eclipse .collections .impl .tuple .Tuples .pair ;
68
68
import static org .neo4j .graphalgo .utils .StringFormatting .formatWithLocale ;
69
69
import static org .neo4j .io .ByteUnit .mebiBytes ;
70
70
import static org .neo4j .kernel .impl .scheduler .JobSchedulerFactory .createScheduler ;
@@ -333,43 +333,38 @@ RelationshipStore concurrentCopy() {
333
333
}
334
334
335
335
static RelationshipStore of (GraphStore graphStore , String defaultRelationshipType ) {
336
- var graphs = graphStore
337
- .relationshipTypes ()
338
- .stream ()
339
- .flatMap (relType -> {
340
- Set <String > relProperties = graphStore .relationshipPropertyKeys (relType );
341
- if (relProperties .isEmpty ()) {
342
- return Stream .of (Tuples .pair (relType , Optional .<String >empty ()));
343
- } else {
344
- return relProperties
345
- .stream ()
346
- .map (propertyKey -> Tuples .pair (relType , Optional .of (propertyKey )));
347
- }
348
- })
349
- .collect (Collectors .toMap (
350
- relTypeAndProperty -> Tuples .pair (
351
- relTypeAndProperty .getOne ().equals (RelationshipType .ALL_RELATIONSHIPS )
352
- ? RelationshipType .of (defaultRelationshipType )
353
- : relTypeAndProperty .getOne (),
354
- relTypeAndProperty .getTwo ()
355
- ),
356
- relTypeAndProperty -> graphStore .getGraph (relTypeAndProperty .getOne (), relTypeAndProperty .getTwo ())
357
- ));
358
-
359
336
Map <RelationshipType , Relationships .Topology > topologies = new HashMap <>();
360
337
Map <RelationshipType , Map <String , Relationships .Properties >> properties = new HashMap <>();
361
338
362
- graphs .forEach ((typeAndProperty , graph ) -> {
363
- RelationshipType relationshipType = typeAndProperty .getOne ();
364
- topologies .computeIfAbsent (relationshipType , ignored -> ((HugeGraph ) graph ).relationshipTopology ());
365
-
366
- typeAndProperty .getTwo ().ifPresent (propertyKey -> properties
367
- .computeIfAbsent (relationshipType , ignored -> new HashMap <>())
368
- .put (propertyKey , ((HugeGraph ) graph ).relationships ().properties ().get ()));
369
- });
339
+ graphStore .relationshipTypes ().stream ()
340
+ // extract (relationshipType, propertyKey) tuples
341
+ .flatMap (relType -> graphStore .relationshipPropertyKeys (relType ).isEmpty ()
342
+ ? Stream .of (pair (relType , Optional .<String >empty ()))
343
+ : graphStore
344
+ .relationshipPropertyKeys (relType )
345
+ .stream ()
346
+ .map (propertyKey -> pair (relType , Optional .of (propertyKey ))))
347
+ // extract graph for relationship type and property
348
+ .map (relTypeAndProperty -> pair (
349
+ relTypeAndProperty ,
350
+ graphStore .getGraph (relTypeAndProperty .getOne (), relTypeAndProperty .getTwo ())
351
+ ))
352
+ // extract Topology list and associated Properties lists
353
+ .forEach (relTypeAndPropertyAndGraph -> {
354
+ var relationshipType = relTypeAndPropertyAndGraph .getOne ().getOne ();
355
+ var maybePropertyKey = relTypeAndPropertyAndGraph .getOne ().getTwo ();
356
+ var graph = relTypeAndPropertyAndGraph .getTwo ();
357
+
358
+ topologies .computeIfAbsent (relationshipType , ignored -> ((HugeGraph ) graph ).relationshipTopology ());
359
+ maybePropertyKey .ifPresent (propertyKey -> properties
360
+ .computeIfAbsent (relationshipType , ignored -> new HashMap <>())
361
+ // .get() is safe, since we have a property key
362
+ .put (propertyKey , ((HugeGraph ) graph ).relationships ().properties ().get ()));
363
+ });
370
364
371
365
Map <RelationshipType , CompositeRelationshipIterator > relationshipIterators = new HashMap <>();
372
366
367
+ // for each relationship type, merge its Topology list and all associated Property lists
373
368
topologies .forEach ((relationshipType , topology ) -> {
374
369
var adjacencyList = (TransientAdjacencyList ) topology .list ();
375
370
var adjacencyOffsets = (TransientAdjacencyOffsets ) topology .offsets ();
@@ -390,8 +385,13 @@ static RelationshipStore of(GraphStore graphStore, String defaultRelationshipTyp
390
385
entry -> (TransientAdjacencyOffsets ) entry .getValue ().offsets ()
391
386
));
392
387
388
+ // iff relationshipType is '*', change it the given default
389
+ var outputRelationshipType = relationshipType .equals (RelationshipType .ALL_RELATIONSHIPS )
390
+ ? RelationshipType .of (defaultRelationshipType )
391
+ : relationshipType ;
392
+
393
393
relationshipIterators .put (
394
- relationshipType ,
394
+ outputRelationshipType ,
395
395
new CompositeRelationshipIterator (adjacencyList , adjacencyOffsets , propertyLists , propertyOffsets )
396
396
);
397
397
});
0 commit comments