node_degree_out() (graph function)

Applies to: ✅ Azure Data Explorer

The node_degree_out function calculates the out-degree, or number of outgoing edges, from a node in a directed graph.

Note

This function is used with the graph-match and graph-shortest-paths operators.

Syntax

node_degree_out(node)

Learn more about syntax conventions.

Parameters

Name Type Required Description
node string ✔️ The reference to a graph node variable in a graph pattern.

Returns

Returns the out-degree of the input node.

Examples

The examples in this section show how to use the syntax to help you get started.

Find paths between locations and transportation modes

The following example uses the Locations and Routes data tables to construct a graph that finds paths from a source location to a destination location through a route. It returns the source location name, destination location name, transportation method, and the node_degree_out, which is the number of outgoing edges from the source node (location).

Run the query

// Locations table (nodes)
let Locations = datatable(LocationName: string, LocationType: string) [
    "New York", "City",
    "San Francisco", "City",
    "Chicago", "City",
    "Los Angeles", "City",
    "Seattle", "Warehouse"
];
// Routes table (edges)
let Routes = datatable(OriginLocationID: string, DestinationLocationID: string, TransportMode: string) [
    "New York", "San Francisco", "Truck",
    "New York", "Chicago", "Train",
    "San Francisco", "Los Angeles", "Truck",
    "Chicago", "Seattle", "Train",
    "Los Angeles", "New York", "Truck",
    "Seattle", "San Francisco", "Train"
];
Routes
| make-graph OriginLocationID --> DestinationLocationID with Locations on LocationName
| graph-match (src)-[route]->(dest)
project src.LocationName, dest.LocationName, route.TransportMode, node_degree_out(src)

Output

src_LocationName dest_LocationName route_TransportMode node_degree_out
New York San Francisco Truck 2
New York Chicago Train 2
San Francisco Los Angeles Truck 1
Chicago Seattle Train 1
Los Angeles New York Truck 1
Seattle San Francisco Train 1

Find employee with no managers

The following example creates a graph to represent the hierarchical relationships between employees and their managers. It uses the graph-match operator to find employees who report to a top-level manager who doesn't report to anyone else. It uses the node_degree_out function to identify the managers who don't report to any other manager.

Run the query

let employees = datatable(name:string, age:long)
[
"Alice", 32,
"Bob", 31,
"Eve", 27,
"Joe", 29,
"Chris", 45,
"Alex", 35,
"Ben", 23,
"Richard", 39,
"Jim", 42,
];
let reports = datatable(employee:string, manager:string)
[
"Bob", "Alice",
"Chris", "Alice",
"Eve", "Bob",
"Ben", "Chris",
"Joe", "Alice",
"Richard", "Bob",
"Alice", "Jim"
];
reports
| make-graph employee --> manager with employees on name
| graph-match (manager)<-[reports]-(employee)
where node_degree_out(manager) == 0
project manager.name, employee.name, di_m=node_degree_in(manager), do_m=node_degree_out(manager), di_e=node_degree_in(employee), do_e=node_degree_out(employee)

Output

manager_name employee_name degree_in_m degree_out_m
Jim Alice 1 0