本文内容
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 | [ “南(红色)”, “中央(红色)”, “北(红色)” ] |
北部 |
以下示例演示如何将 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”] |