共用方式為


any() (圖表函式)

適用於:✅Microsoft網狀架構

圖形any()函式會沿著可變長度路徑評估每個邊緣內部節點的條件。

備註

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

語法

any( 邊緣,條件)

any(inner_nodes( 邊緣),條件)

參數

名稱 類型 為必填項目 說明
邊緣 string ✔️ 圖形比對運算符圖形最短路徑運算符模式中的可變長度邊緣。 如需詳細資訊,請參閱 圖形模式表示法
條件 string ✔️ 布爾表達式,由 邊緣內部節點的屬性所組成 ,當inner_nodes 用於 可變長度邊緣時。 直接使用屬性名稱參考屬性。 表達式會針對可變長度邊緣中的每個邊緣內部節點進行評估。

退貨

true如果在true中使用inner_nodes時,條件評估為 至少一個邊緣內部節點,則傳回 。 否則會傳回 false

針對零長度路徑,條件會評估為 false

範例

下列範例會使用 LocationsRoutes 數據表來建構圖表,以透過 route尋找來源位置到目的地位置的路徑。 它會使用 any() 函式來尋找至少使用 "Train" 運輸方法一次的路徑。 它會傳回路線沿線的來源位置名稱、目的地位置名稱和運輸方法。

// Locations table (nodes)
let Locations = datatable(LocationName: string, LocationType: string) [
    "New York", "City",
    "San Francisco", "City",
    "Chicago", "City",
    "Los Angeles", "City",
    "Seattle", "Warehouse"
];
// Routes table (edges)
let Routes = datatable(OriginLocationID: string, DestinationLocationID: string, TransportMode: string) [
    "New York", "San Francisco", "Truck",
    "New York", "Chicago", "Train",
    "San Francisco", "Los Angeles", "Truck",
    "Chicago", "Seattle", "Train",
    "Los Angeles", "New York", "Truck",
    "Seattle", "San Francisco", "Train"
];
Routes
| make-graph OriginLocationID --> DestinationLocationID with Locations on LocationName
| graph-match (src)-[route*1..2]->(dest)
  where any(route, TransportMode == "Train")
  project src.LocationName, 
        dest.LocationName, 
        route_TransportModes = map(route, TransportMode)

輸出

src_LocationName dest_LocationName route_TransportModes
西雅圖 舊金山 [“Train”]
芝加哥 西雅圖 [“Train”]
紐約 芝加哥 [“Train”]
西雅圖 洛杉磯 [
“Train”,
“Truck”
]
芝加哥 舊金山 [
“Train”,
“Train”
]
紐約 西雅圖 [
“Train”,
“Train”
]
洛杉磯 芝加哥 [
“Truck”,
“Train”
]

下列範例示範如何使用 graph-shortest-paths 運算符搭配 any()inner_nodes 函式,在運輸網路中尋找兩個月臺之間的路徑。 查詢會從 connections 數據建構圖表,並尋找從 "South-West" 月臺到 "North" 月臺的最短路徑,並傳遞至少一個月臺,其中 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*2..5]->(destination)
  where start.station == "South-West" and
        destination.station == "North" and 
        any(inner_nodes(connections), wifi)
  project from = start.station, 
          stations = strcat_array(map(inner_nodes(connections), station), "->"), 
          to = destination.station

輸出

South-West >中南部
South-West >中西部