4949import org .neo4j .gds .api .schema .RelationshipPropertySchema ;
5050import org .neo4j .gds .api .schema .RelationshipSchema ;
5151import org .neo4j .gds .core .Aggregation ;
52- import org .neo4j .gds .core .ProcedureConstants ;
5352import org .neo4j .gds .core .huge .CSRCompositeRelationshipIterator ;
5453import org .neo4j .gds .core .huge .HugeGraph ;
5554import org .neo4j .gds .core .huge .NodeFilteredGraph ;
5655import org .neo4j .gds .core .huge .UnionGraph ;
57- import org .neo4j .gds .core .loading .construction .GraphFactory ;
5856import org .neo4j .gds .core .utils .TimeUtil ;
5957import org .neo4j .gds .utils .ExceptionUtil ;
6058import org .neo4j .gds .utils .StringJoining ;
@@ -115,18 +113,13 @@ public static CSRGraphStore of(
115113 Map <RelationshipType , RelationshipPropertyStore > relationshipPropertyStores ,
116114 int concurrency
117115 ) {
118- // A graph store must contain at least one topology, even if it is empty.
119- var topologies = relationships .isEmpty ()
120- ? Map .of (RelationshipType .ALL_RELATIONSHIPS , GraphFactory .emptyRelationships (nodes ).topology ())
121- : relationships ;
122-
123116 return new CSRGraphStore (
124117 databaseId ,
125118 capabilities ,
126119 schema ,
127120 nodes ,
128121 nodePropertyStore == null ? NodePropertyStore .empty () : nodePropertyStore ,
129- topologies ,
122+ relationships ,
130123 relationshipPropertyStores ,
131124 concurrency
132125 );
@@ -478,27 +471,8 @@ public DeletionResult deleteRelationships(RelationshipType relationshipType) {
478471 }
479472
480473 @ Override
481- public Graph getGraph (Collection <NodeLabel > nodeLabels ) {
482- var filteredNodes = getFilteredIdMap (nodeLabels );
483- var filteredNodeProperties = filterNodeProperties (nodeLabels );
484-
485- var graphSchema = GraphSchema .of (
486- schema ().nodeSchema (),
487- RelationshipSchema .empty (),
488- schema .graphProperties ()
489- );
490-
491- var initialGraph = HugeGraph .create (
492- nodes ,
493- graphSchema ,
494- filteredNodeProperties ,
495- Relationships .Topology .EMPTY ,
496- Optional .empty ()
497- );
498-
499- return filteredNodes .isPresent ()
500- ? new NodeFilteredGraph (initialGraph , filteredNodes .get ())
501- : initialGraph ;
474+ public CSRGraph getGraph (Collection <NodeLabel > nodeLabels ) {
475+ return getGraph (nodeLabels , List .of (), Optional .empty ());
502476 }
503477
504478 @ Override
@@ -508,11 +482,18 @@ public CSRGraph getGraph(
508482 Optional <String > maybeRelationshipProperty
509483 ) {
510484 validateInput (relationshipTypes , maybeRelationshipProperty );
511- return createGraph (nodeLabels , relationshipTypes , maybeRelationshipProperty );
485+ if (relationshipTypes .isEmpty ()) {
486+ return createNodeOnlyGraph (nodeLabels );
487+ } else {
488+ return createGraph (nodeLabels , relationshipTypes , maybeRelationshipProperty );
489+ }
512490 }
513491
514492 @ Override
515493 public CSRGraph getUnion () {
494+ if (relationships .isEmpty ()) {
495+ return getGraph (nodeLabels ());
496+ }
516497 var graphs = relationships
517498 .keySet ()
518499 .stream ()
@@ -681,6 +662,29 @@ private CSRGraph createGraph(
681662 return UnionGraph .of (filteredGraphs );
682663 }
683664
665+ private CSRGraph createNodeOnlyGraph (Collection <NodeLabel > nodeLabels ) {
666+ var filteredNodes = getFilteredIdMap (nodeLabels );
667+ var filteredNodeProperties = filterNodeProperties (nodeLabels );
668+
669+ var graphSchema = GraphSchema .of (
670+ schema ().nodeSchema (),
671+ RelationshipSchema .empty (),
672+ schema .graphProperties ()
673+ );
674+
675+ var initialGraph = HugeGraph .create (
676+ nodes ,
677+ graphSchema ,
678+ filteredNodeProperties ,
679+ Relationships .Topology .EMPTY ,
680+ Optional .empty ()
681+ );
682+
683+ return filteredNodes .isPresent ()
684+ ? new NodeFilteredGraph (initialGraph , filteredNodes .get ())
685+ : initialGraph ;
686+ }
687+
684688 @ NotNull
685689 private Optional <IdMap > getFilteredIdMap (Collection <NodeLabel > filteredLabels ) {
686690 boolean loadAllNodes = filteredLabels .containsAll (nodeLabels ());
@@ -744,13 +748,6 @@ private void validateInput(
744748 Collection <RelationshipType > relationshipTypes ,
745749 Optional <String > maybeRelationshipProperty
746750 ) {
747- if (relationshipTypes .isEmpty ()) {
748- throw new IllegalArgumentException (formatWithLocale (
749- "The parameter '%s' should not be empty. Use '*' to load all relationship types." ,
750- ProcedureConstants .RELATIONSHIP_TYPES
751- ));
752- }
753-
754751 relationshipTypes .forEach (relationshipType -> {
755752 if (!relationships .containsKey (relationshipType )) {
756753 throw new IllegalArgumentException (formatWithLocale (
0 commit comments