共用方式為


map() (圖表函式)

適用於:✅Microsoft網狀架構

圖形map()函式會沿著可變長度路徑計算每個邊緣內部節點的運算式,並傳回所有結果的動態陣列。

備註

此函式會與 圖形比對圖表最短路徑 運算符搭配使用。

語法

map*edge* *expression*)'

map(inner_nodes( 邊緣),表達)

參數

名稱 類型 為必填項目 說明
邊緣 string ✔️ 圖形比對運算符圖形最短路徑運算符模式中的可變長度邊緣。 如需詳細資訊,請參閱 圖形模式表示法
表示式 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_with_wifi
>中西部 [ “West”, “Central”]
>中南部 [ “Central”]