map(图函数)

适用于:✅Azure 数据资源管理器Azure MonitorMicrosoft Sentinel

map() 图形函数计算每个 边缘内部节点 沿 可变长度 路径的表达式,并返回所有结果的动态数组。

备注

此函数与 图形匹配图形最短路径 运算符一起使用。

语法

map``( 边缘,表达式)

map(inner_nodes( 边缘),表达式)

参数

名字 类型 必填 说明
边缘 string ✔️ 图形匹配运算符图形最短路径运算符 模式中的可变长度边缘。 有关详细信息,请参阅 图形模式表示法
expression string ✔️ 可变长度边缘中使用 inner_nodes 时,要对 边缘内部节点的属性执行计算。 直接使用属性名称引用属性。 为 可变长度边缘中的每个 边缘内部节点 计算表达式。

退货

动态数组,其中:

  • 在可变长度边缘中使用 inner_nodes 时,数组长度与边缘或内部节点数匹配。
  • 对于零长度路径,数组为空。
  • 数组中的每个元素对应于将 表达式 应用于可变长度边缘中的每个边缘或内部节点的结果。

例子

本节中的示例演示如何使用语法帮助你入门。

查找两个车站之间的最短路线的车站和线路

以下示例演示如何使用 graph-shortest-paths作员在交通网络中 "South-West""North" 站之间查找最短的路径。 它使用 map() 函数向路径添加行信息。 该查询根据 connections 数据构造图形,并考虑最长五个连接的路径。

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

输出

路径 接收方
South-West [
“南(红色)”,
“中央(红色)”,
“北(红色)”
]
北部

获取两个车站之间所有路线中 Wi-Fi 的停车列表

以下示例演示如何将 graph-match作员与 all()inner_nodes 功能一起使用,以查找运输网络中两个车站之间所有路线之间所有路线 Wi-Fi 的所有停靠点。

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, "")))

输出

stopovers stopovers_with_wifi
中西部-> [ “West”, “Central”]
中南部-> [ “Central”]