map() (graph function)
Applies to: ✅ Microsoft Fabric ✅ Azure Data Explorer ✅ Azure Monitor ✅ Microsoft Sentinel
The map()
graph function calculates an expression for each edge or inner node along a variable length path and returns a dynamic array of all results.
Note
This function is used with the graph-match and graph-shortest-paths operators.
Syntax
map``(
edge,
expression)
map(inner_nodes(
edge),
expression)
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. |
expression | string |
✔️ | The calculation to perform over the 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
A dynamic array where:
- The array length matches the number of edges or inner nodes, when inner_nodes is used, in the variable length edge.
- The array is empty for zero length paths.
- Each element in the array corresponds to the results of applying the expression to each edge or inner node in the variable length edge.
Examples
The examples in this section show how to use the syntax to help you get started.
Find the station and line for the shortest route between two stations
The following example shows how to use the graph-shortest-paths
operator to find the shortest path between the "South-West"
and "North"
stations in a transportation network. It adds line information to the path using the map()
function. The query constructs a graph from the connections
data, considering paths up to five connections long.
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-shortest-paths (start)-[connections*1..5]->(destination)
where start.station == "South-West" and destination.station == "North"
project from = start.station, path = map(connections, strcat(to_station, " (", line, ")")), to = destination.station
Output
from | path | to |
---|---|---|
South-West | [ "South (red)", "Central (red)", "North (red)" ] |
North |
Get list of stopovers with Wi-Fi in all routes between two stations
The following example shows how to use the graph-match
operator with the all()
and inner_nodes
functions to find all stopovers with Wi-Fi along all routes between two stations in a transportation network.
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-match cycles=none (start)-[connections*1..5]->(destination)
where start.station == "South-West" and destination.station == "East"
project stopovers = strcat_array(map(inner_nodes(connections), station), "->"),
stopovers_with_wifi = set_intersect(map(inner_nodes(connections), station), map(inner_nodes(connections), iff(wifi, station, "")))
Output
stopovers | stopovers_with_wifi |
---|---|
West->Central | [ "West", "Central"] |
South->Central | [ "Central"] |