node_degree_in() (graph function)

Applies to: ✅ Azure Data Explorer

The node_degree_in function calculates the in-degree, or number of incoming edges, to a node in a directed graph.

Note

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

Syntax

node_degree_in(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 in-degree of the input node.

Example

The following example creates a graph to represent the hierarchical relationships between employees and their managers. It uses the graph-match operator to identify where a manager node has an incoming edge from an employee node. Then, it uses the node_degree_in function to find managers with exactly three direct reports. The query returns the manager, the name of each direct report, the in-degree to the manager, and the number of direct reports for each employee.

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,
];
let reports = datatable(employee:string, manager:string)
[
"Bob", "Alice",
"Chris", "Alice",
"Eve", "Bob",
"Ben", "Chris",
"Joe", "Alice",
"Richard", "Bob"
];
reports
| make-graph employee --> manager with employees on name
| graph-match (manager)<-[reports]-(employee)
where node_degree_in(manager) == 3
project manager.name, employee.name, degree_in_m=node_degree_in(manager), degree_out_e=node_degree_out(employee) 

Output

manager_name employee_name degree_in_m degree_out_e
Alice Bob 3 1
Alice Chris 3 1
Alice Joe 3 1