Skip to content

Connected Component Finding

Introduction

Connected Component Finding is an algorithm that identifies all vertices reachable from specified starting vertices through given edge types. The algorithm calculates the minimum distance (hops) from any start vertex to each reachable node.

Output

The algorithm produces the following fields:

Field Name Description
ID The ID of the vertex (node)
hop The minimum hops from any of the provided vertices

Query Example

CALL algo.paral.connectedComponentFinding({
    relationshipTypes: ['Knows', 'WorkAt'],
    startIds: ['User[2]'],
    maxIterations: 10
    }) YIELD ID, hop
RETURN ID, hop 
graph.program(
    ConnectedComponentFindingProgram.builder()
    .edges('Knows', 'WorkAt')
    .startIds('User[2]')
    .maxIteration(10)
    .vertexFilter('Company', 'city', TextP.startsWith('B'))                             // filter for one label
    .edgeFilter('Knows', 'startYear', P.gte(2020))
    .vertexFilter('isOutdated', P.eq(false))                                              // filter for all labels
    .edgeFilter('isDeleted', P.eq(false))
    .create()
).submitAndGet().toList()

Parameters

Name Description Required
relationshipTypes Relationship types to traverse Yes
startIds Initial vertex IDs Yes
maxIterations Maximum number of iterations No
Method Description Required
edges(String... names) Edge types to traverse Yes
startIds(String... ids) Initial vertex IDs Yes
maxIteration(int n) Sets the maximum number of iterations No
vertexFilter(String labelName, String Attr, P predicate) Filter vertices of specific label by attribute No
vertexFilter(String Attr, P predicate) Filter all vertices by attribute (if the vertex has the given attribute) No
edgeFilter(String labelName, String Attr, P predicate) Filter edges of specific label by attribute No
edgeFilter(String Attr, P predicate) Filter all edges by attribute (if the edge has the given attribute) No

cypher is not support filtering nodes and relationships for now.

Exporting Query Results

For large datasets, export the results to object storage:

EXPORT TO 's3://my_bucket/target_dir'
PROPERTIES {
  catalog: 'puppygraph_catalog_name'
}
CALL algo.paral.connectedComponentFinding({
    relationshipTypes: ['Knows', 'WorkAt'],
    startIds: ['User[2]']
    }) YIELD ID, hop
RETURN ID, hop 
graph.program(
    ConnectedComponentFindingProgram.builder()
    .edges('Knows', 'WorkAt')
    .startIds('User[2]')
    .vertexFilter('Company', 'city', TextP.startsWith('B'))
    .edgeFilter('Knows', 'startYear', P.gte(2020))
    .vertexFilter('isOutdated', P.eq(false))
    .edgeFilter('isDeleted', P.eq(false))
    .create()
).submitAndSave([
  "exportTo": "s3://my_bucket/target_dir",
  "catalog": "puppygraph_catalog_name"
])