Separate disconnected groups
The language tabs use earlier client interfaces. Check SDK versions and connection setup before running them.
Find groups connected within themselves but disconnected from each other.
Before you run it: Treat _component as an opaque string key, not a nested JSON object.
First load the five-person social graph. It creates the exact social.users table and follows relation used below.
This asks which records can be connected when link direction is ignored. It is different from finding smaller communities inside one connected group.
- Read the self-relationStart with the table's records and their links.
- Follow connected neighborsCollect records that can reach each other without considering direction.
- Group matching labelsRecords with the same component value belong together.
Follow the example
- Prepare the self-referencing relationship.
- Run components for the whole table.
- Group results by their component value.
- Check isolated records too.
Set up the relationship
The relation must be declared in the schema's [[relations]] block and must target the table it is declared on. See schemas/reference#relations.
Run the request
rel names the relation. The optional include_rows=true switch also echoes each row's full body alongside its component id; leave it off unless you need the columns, because the default response carries only what the algorithm actually computed.
curl -G "https://$OC_HOST/v1/tenants/$OC_TENANT/graph/social.users/components" \
--data-urlencode "rel=follows" \
-H "Authorization: Bearer $OC_TOKEN"Check the result
Every row belongs to a component, including rows without links.
[
{ "pk": ["alice"], "_component": "[\"alice\"]" },
{ "pk": ["bob"], "_component": "[\"alice\"]" },
{ "pk": ["carol"], "_component": "[\"alice\"]" },
{ "pk": ["heidi"], "_component": "[\"heidi\"]" },
{ "pk": ["ivan"], "_component": "[\"heidi\"]" },
{ "pk": ["judy"], "_component": "[\"heidi\"]" },
{ "pk": ["mallory"], "_component": "[\"mallory\"]" }
]One entry per node. pk is the node's primary-key array. _component is the canonical JSON encoding of the component root's primary key, which makes it a string containing a JSON array, not an array. Treat it as an opaque grouping key: nodes that share it are in the same island. With include_rows=true each entry additionally carries the row's own columns, next to the same _component field.
Understand the behavior
- Union-find over the schema's whole node universe, with every
reledge treated as undirected. - Each row is emitted exactly once whether or not it has edges, so the number of distinct
_componentvalues is the number of islands. - The compact
{pk, _component}shape is the default because the algorithm's entire answer is one id per node. Echoing row bodies made the response grow with row width without adding information. include_rows=truerestores the earlier verbatim-row shape for callers that depended on it. The partitioning is identical either way - only the payload changes.
Important limits and checks
- Treating
_componentas a key you can look up. It is a canonical-JSON string, not a bare primary key and not an integer. Group on it; do not try to resolve it back to a row. - Reaching for
include_rows=trueby habit. It multiplies the response by your row width. Get the partition first, then fetch only the rows you actually want by primary key. - Expecting isolated rows to be absent. A row with no edges is a component of one and is present in the response.