Betweenness Centrality
UDTF: cugraph_betweenness_centrality
Official cuGraph reference: C API
Measure how often each vertex lies on shortest paths between other vertex pairs, exactly or from an explicit sample of source vertices.
Quickstart
The call below supplies edges from registered relation target_edges with canonical src and dst columns and may include weight.
SELECT *
FROM cugraph_betweenness_centrality(
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.
The vertex-ID types this UDTF accepts, the numeric types a per-call codebook maps to native ids, and its string-key limits are listed in Vertex ID support; the concrete call-specific schema comes from gpu_validate_call.
Arguments and options
Relation arguments
Every edge_id column must have the integer type of src and dst; string-keyed graphs accept no edge IDs.
Named value arguments
Graph construction options
Graph construction follows the shared defaults (directed=true, renumbering, python_cugraph policy) documented in Graph Construction Options.
Output
These are generic descriptor schemas. Run gpu_validate_call to get the concrete, table-specific output schema.
Examples
- MerRec
- Citation network
Which brands connect the shopping worlds?
Betweenness centrality counts how often a brand lies on the shortest paths between other brands in the similarity graph. Brands that connect many worlds are candidates for cross-world navigation, or for exclusion from a collection that should stay inside one world.
The SQL builds the same Jaccard graph as the worlds query: 5,000
brands, edges where the shared-fan similarity reaches 0.02. Leiden assigns
the worlds and cugraph_betweenness_centrality scores the same edges. A
join of each brand's graph neighbors to their world labels counts how many
worlds the brand touches directly.
), worlds AS (
SELECT vertex AS brand_id, community AS world
FROM cugraph_leiden(
edges => (SELECT first AS src, second AS dst, CAST(similarity AS DOUBLE) AS weight FROM similar),
directed => false, resolution => 3, seed => 42)
), bridges AS (
SELECT vertex AS brand_id, value AS betweenness
FROM cugraph_betweenness_centrality(
edges => (SELECT first AS src, second AS dst FROM similar),
directed => false, normalized => true)
), neighbors AS (
SELECT first AS brand_id, second AS neighbor FROM similar
UNION ALL SELECT second, first FROM similar
), reach AS (
SELECT n.brand_id, COUNT(*) AS neighbors, COUNT(DISTINCT w.world) AS worlds_reached
FROM neighbors n JOIN worlds w ON w.brand_id = n.neighbor
GROUP BY n.brand_id
The query took 8.15 s over Flight SQL.
The connectors are mostly sellers and generic labels that the catalog stores in its brand field. Department stores and retailers (Walmart, JCPenney, Macy's, Claire's), house brands (Mainstays, Better Homes & Gardens) and catch-all entries (As Seen on TV, Customized & Personalized, Eyeshadow, US Vintage) hold most of the first fifteen positions, each with neighbors in 37 to 44 of the worlds. Samsung is the manufacturer with the highest score. Its 98 neighbors span 13 worlds. To isolate manufacturer brands from retail aggregators, exclude retailer and catch-all labels in the initial CTE and rerun the centrality query.
Betweenness depends on the graph the query defines. A different similarity threshold changes which paths exist, and a brand with few neighbors can score highly when it is the only link between two worlds. The world counts use the Leiden labels of the same execution.
The plan had 15 native fragments and zero host DataFusion boundaries. The largest query allocator peak was 54.46 GiB of the 90 GiB query limit. The capture contains the executed SQL, query IDs, timings and every result row.
Which papers connect the most citation routes across AI research?
A paper can connect many shortest citation routes without having the largest citation count. This query ranks papers by betweenness in a selected 2010s AI subgraph of the citation network.
CREATE OR REPLACE VIEW ai_nodes AS
SELECT paper_id FROM papers
WHERE year >= 2010 AND primary_fos IN (
'Deep learning', 'Artificial neural network', 'Convolutional neural network',
'Recurrent neural network', 'Natural language processing',
'Reinforcement learning', 'Image segmentation', 'Feature extraction',
'Object detection', 'Speech recognition');
CREATE OR REPLACE VIEW ai_edges AS
SELECT e.src, e.dst
FROM citation_edges e
JOIN ai_nodes a ON a.paper_id = e.src
JOIN ai_nodes b ON b.paper_id = e.dst;
SELECT p.title, p.year, p.primary_fos, CAST(b.value AS BIGINT) AS betweenness
FROM cugraph_betweenness_centrality(
edges => (SELECT src, dst FROM ai_edges), normalized => false) b
JOIN papers p ON p.paper_id = b.vertex
ORDER BY b.value DESC
LIMIT 6;
With normalized: false, each paper's score sums its share of shortest paths
across source-target pairs in this subgraph.
For sampling options on larger graphs, see the Betweenness Centrality UDTF reference.