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.
Don't pass any parameters when used inside all(), any(), and map() graph functions, with inner_nodes().

Returns

Returns the in-degree of the input node or of all inner nodes, when used inside all(), any(), and map() functions with inner_nodes().

Example

The following example creates a graph to analyze a hierarchical structure of employees and their managers.

The graph-match operator looks for managers who have exactly three direct reports (node_degree_in(manager) == 3) and where any of the inner nodes (employees) have at least one report (node_degree_in() > 1).

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.

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*1..3]-(employee)
    where node_degree_in(manager) == 3 and any(inner_nodes(reports), node_degree_in() > 1)
    project manager.name, employee.name, 
            reports_and_inner_nodes_degree_in = map(inner_nodes(reports), strcat(name, " has ", node_degree_in(), " reports")),
            degree_in_m=node_degree_in(manager), 
            degree_out_e=node_degree_out(employee) 

Output

manager_name employee_name reports_and_inner_nodes_degree_in degree_in_m degree_out_e
Alice Richard ["Bob has 2 reports"] 3 1
Alice Eve ["Bob has 2 reports"] 3 1
Alice Ellen [
"Bob has 2 reports",
"Eve has 1 reports"
]
3 1