Skip to main content

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​

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; this algorithm ignores weight

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

Named value arguments​

OptionTypeDefaultConstraintsDescription
exact_vertex_thresholdinteger100000min 0; max 18446744073709552000vertex count threshold for exact betweenness
include_endpointsbooleanfalsewhether betweenness includes endpoints
kinteger|nullnullmin 1; max 18446744073709552000optional sample count, at least 1
normalizedbooleantruewhether centrality scores are normalized
seedsarray|nullnulloptional non-empty homogeneous seed vertex array

Graph construction options​

Graph construction follows the shared defaults (directed=true, renumbering, python_cugraph policy) documented in Graph Construction Options.

Output​

ColumnTypeNullableDescription
vertexInt64|Utf8noAlgorithm result column.
valueFloat64noAlgorithm result column.

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

Examples​

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
BrandFansGraph neighborsWorlds among neighborsBetweenness
As Seen on TV7,532339370.0170
Claire's9,336639440.0127
Customized & Personalized44,627445370.0126
Mainstays10,007541430.0119
Better Homes & Gardens8,468484410.0103
Samsung51,33898130.0091
Walmart22,097589440.0088
IZOD7,719359430.0080
US Vintage12,239510420.0072
Gibson3,855195180.0070
Eyeshadow2,177650410.0069
Original Vintage Style16,398491410.0063
JCPenney9,911712440.0062
Macy's12,993785440.0061
Ellen Tracy5,101821440.0057

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.