Skip to main content

Weakly Connected Components

UDTF: cugraph_weakly_connected_components

Official cuGraph reference: C API

Label maximal connected subgraphs after treating directed edges as undirected.

Quickstart​

The call below supplies edges from registered relation target_edges with canonical src and dst columns and may include weight. Substitute your own registered relations.

SELECT *
FROM cugraph_weakly_connected_components(
edges => (SELECT src, dst FROM target_edges)
);

Inputs​

Every relation is a named parenthesized SELECT subquery. The required edges role uses canonical src and dst columns; every role, its canonical columns, and their accepted Arrow types are listed under Relation arguments. Metadata validation resolves registered tables named in its JSON request.

Endpoint columns accept numeric Int32, Int64 vertex IDs or logical string Utf8, LargeUtf8, Utf8View vertex IDs; string vertex-identity outputs are canonicalized to Utf8 (native mapping Int64) while scores, distances, counts, coordinates, and opaque labels stay numeric. The shared vertex-ID contract is summarized in Vertex ID support; the concrete call-specific schema comes from gpu_validate_call.

Logical string side-input limitations:

  • edge ID columns and edge-ID predicate side inputs are not supported for logical string graphs

Arguments and options​

Relation arguments​

ArgumentRequiredColumnsDescription
edgesyes
  • src, dst: Int32, Int64, Utf8, LargeUtf8, Utf8View
  • weight (optional): Float32, Float64
  • edge_id (optional): Int32, Int64
edge relation with canonical src and dst columns, plus optional weight and edge_id columns

Every edge_id column must have the integer type of src and dst; string-keyed graphs accept no edge IDs.

Named value arguments​

This UDTF has no algorithm-specific value arguments. Its inputs are the relation arguments above and the graph construction options below.

Graph construction options​

This UDTF requires directed=false (undirected/symmetric graph); all other graph construction options follow the shared defaults documented in Graph Construction Options.

Output​

ColumnTypeNullableDescription
vertexInt64|Utf8noVertex assigned to a weakly connected component.
labelInt64noWeakly connected component identifier for the vertex: the minimum vertex id in the component, stable across runs.

These are generic descriptor schemas; run gpu_validate_call to get the concrete, table-specific output schema.

Examples​

This example runs on the citation network demo dataset.

Which research pockets are disconnected from the main citation network?​

An exploration that starts in the largest connected component cannot reach the other components, even when citations can be followed in either direction. This query finds the largest disconnected groups and names the most-cited paper in each. Papers without any citation edge are outside this graph.

Component labels belong to one execution. Save one result table so the size calculation and paper lookup use matching labels.

CREATE OR REPLACE TABLE wcc_snapshot AS
SELECT vertex, label
FROM cugraph_weakly_connected_components(
edges => (SELECT src, dst FROM citation_edges), directed => false);

WITH sizes AS (
SELECT label, COUNT(*) AS members FROM wcc_snapshot
GROUP BY label ORDER BY members DESC LIMIT 3 OFFSET 1),
detail AS (
SELECT s.members, p.year, p.venue, p.title,
ROW_NUMBER() OVER (PARTITION BY s.label ORDER BY p.n_citation DESC) AS rn
FROM sizes s
JOIN wcc_snapshot c ON c.label = s.label
JOIN papers p ON p.paper_id = c.vertex)
SELECT members, year, venue, title
FROM detail WHERE rn = 1
ORDER BY members DESC;
membersyearvenuetitle
392008IEICE Transactions on ElectronicsMotion of Break Arcs Driven by External Magnetic Field…
252013IEICE Electronics ExpressCavity-resonator-integrated guided-mode resonance filter…
212015SymmetryInflationary Cosmology in Modified Gravity Theories

The displayed groups have no citation links to the main component in this snapshot. Their representative papers suggest subject areas for a separate search. Missing links in this corpus do not establish that the research fields are disconnected in the wider literature.

Limits​

  • cuGraph requires directed=false so the graph is constructed as an undirected/symmetric view

To dry-run validate relation metadata, column types, and options without execution, see gpu_validate_call.