Connected Component Finding
Introduction
Connected Component Finding is an algorithm that identifies all nodes (vertices) reachable from specified starting nodes (vertices) through given edge types. The algorithm calculates the minimum distance (hops) from any start node (vertex) to each reachable node.
Output
The algorithm produces the following fields:
Field Name | Description |
---|---|
ID | The ID of the node (vertex) |
hop | The minimum hops from any of the provided nodes (vertices) |
Query Example
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 node (vertex) IDs | Yes |
maxIterations | Maximum number of iterations | No |
Method | Description | Required |
---|---|---|
edges(String... names) | Edge types to traverse | Yes |
startIds(String... ids) | Initial node (vertex) IDs | Yes |
maxIteration(int n) | Sets the maximum number of iterations | No |
vertexFilter(String labelName, String Attr, P predicate) | Filter nodes (vertices) of specific label by attribute | No |
vertexFilter(String Attr, P predicate) | Filter all nodes (vertices) by attribute (if the node 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:
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"
])