all() (graph function)

Applies to: ✅ Microsoft FabricAzure Data ExplorerAzure MonitorMicrosoft Sentinel

The all() graph function evaluates a condition for each edge or inner node along a variable length path.

Note

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

Syntax

all(edge, condition)

all(inner_nodes(edge), condition)

Parameters

Name Type Required Description
edge string ✔️ A variable length edge from the graph-match operator or graph-shortest-paths operator pattern. For more information, see Graph pattern notation.
condition string ✔️ A Boolean expression composed of properties of the edge or inner node, when inner_nodes is used, in the variable length edge. A property is referenced using the property name directly. The expression is evaluated for each edge or inner node in the variable length edge.

Returns

Returns true if the condition evaluates to true for each edge or inner node, when inner_nodes is used, in the variable length edge. Otherwise, it returns false.

For zero length paths, the condition evaluates to true.

Examples

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

Find all round-trip paths between two train stations using different lines for each direction

The following example shows how to use the graph-match operator with the all() function to find all round-trip paths between two stations in a transportation network. It uses a different line for each direction. The query constructs a graph from the connections data, finding all paths up to five connections long that use the "red" line for the outward route, and the "blue" line for the return route. The all() function ensures that all edges in the variable length edge are part of the same line, either "red" or "blue".

let connections = datatable(from_station:string, to_station:string, line:string) 
[ 
  "Central", "North", "red",
  "North", "Central", "red", 
  "Central", "South",  "red", 
  "South", "Central",  "red", 
  "South", "South-West", "red", 
  "South-West", "South", "red", 
  "South-West", "West", "red", 
  "West", "South-West", "red", 
  "Central", "East", "blue", 
  "East", "Central", "blue", 
  "Central", "West", "blue",
  "West", "Central", "blue",
]; 
connections 
| make-graph from_station --> to_station with_node_id=station
| graph-match (start)-[outward*1..5]->(destination)-[return*1..5]->(start)
  where start.station != destination.station and 
        all(outward, line == "red") and
        all(return, line == "blue") 
  project from = start.station, 
          outward_stations = strcat_array(map(inner_nodes(outward), station), "->"), 
          to = destination.station, 
          return_stations = strcat_array(map(inner_nodes(return), station), "->"), 
          back=start.station

Output

from outward_stations to return_stations back
Central North->Central->South->South-West West Central
West South-West->South->Central->North Central West
Central South->South-West West Central
West South-West->South Central West
Central North->Central->South->South-West West Central->East Central
West South-West->South->Central->North Central East->Central West
Central South->South-West West Central->East Central
West South-West->South Central East->Central West

Find the shortest path between two stations with Wi-Fi available

The following example shows how to use the graph-shortest-paths operator with the all() and inner_nodes functions to find a path between two stations in a transportation network. The query constructs a graph from the connections data and finds the shortest path from the "South-West" station to the "North" station, passing through stations where Wi-Fi is available.

let connections = datatable(from_station:string, to_station:string, line:string) 
[ 
  "Central", "North", "red",
  "North", "Central", "red", 
  "Central", "South",  "red", 
  "South", "Central",  "red", 
  "South", "South-West", "red", 
  "South-West", "South", "red", 
  "South-West", "West", "red", 
  "West", "South-West", "red", 
  "Central", "East", "blue", 
  "East", "Central", "blue", 
  "Central", "West", "blue",
  "West", "Central", "blue",
]; 
let stations = datatable(station:string, wifi: bool) 
[ 
  "Central", true,
  "North", false,
  "South", false,
  "South-West", true,
  "West", true,
  "East", false
];
connections 
| make-graph from_station --> to_station with stations on station
| graph-shortest-paths (start)-[connections*2..5]->(destination)
  where start.station == "South-West" and
        destination.station == "North" and 
        all(inner_nodes(connections), wifi)
  project from = start.station, 
          stations = strcat_array(map(inner_nodes(connections), station), "->"), 
          to = destination.station

Output

from stations to
South-West West->Central North