node_degree_out (graph function)

This article describes the node_degree_out() command.

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

Syntax

node_degree_out([node])

Parameters

NameTypeRequiredDescription
nodestring✔️The reference to a graph node variable in a graph pattern.
No parameters should be passed when used inside all(), any() and map() graph functions, in conjunction with inner_nodes().

Returns

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

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 methods along the route, the node_degree_out, which is the number of outgoing edges from the source node (location), and the route_nodes_degree_out, which are the number of outgoing edges from the inner nodes (stopover locations) along the route.

// 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*1..2]->(dest)
project src.LocationName, 
        dest.LocationName, 
        node_degree_out(src),
        route_TransportModes = map(route, TransportMode),
        route_nodes_degree_out = map(inner_nodes(route), node_degree_out())

Output

src_LocationNamedest_LocationNamenode_degree_outroute_TransportModesroute_nodes_degree_out
ChicagoSeattle1[“Train”][]
New YorkChicago2[“Train”][]
Los AngelesNew York1[“Truck”][]
San FranciscoLos Angeles1[“Truck”][]
SeattleSan Francisco1[“Train”][]
New YorkSan Francisco2[“Truck”][]
ChicagoSan Francisco1[“Train”,“Train”][1]
New YorkSeattle2[“Train”,“Train”][1]
New YorkLos Angeles2[“Truck”,“Truck”][1]
San FranciscoNew York1[“Truck”,“Truck”][1]
SeattleLos Angeles1[“Train”,“Truck”][1]
Los AngelesSan Francisco1[“Truck”,“Truck”][2]
Los AngelesChicago1[“Truck”,“Train”][2]

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.

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_nameemployee_namedegree_in_mdegree_out_m
JimAlice10