Cypher query to count the number of wcc's of size >= 2:
CALL algo.unionFind.stream('User', null, {})
YIELD nodeId, setId
WITH setId, count(*) AS componentSize
WHERE componentSize >= 2
RETURN count(*) as numberOfComponentsOfSize2OrGreater
It's important to have nodeId, setId
and setId, count(*)
in there even though we neither use nodeId
nor setId
. It prevents collapsing identical result rows into one, which would make the query miscount!
See also Neo4J's article on aggregation and grouping attributes being implicit.