Compartir a través de


map() (función de grafo)

Se aplica a: ✅Microsoft FabricAzure Data Explorer✅Azure MonitorMicrosoft Sentinel

La map() función de grafo calcula una expresión para cada borde o nodo interno a lo largo de una ruta de acceso de longitud variable y devuelve una matriz dinámica de todos los resultados.

Nota:

Esta función se usa con los operadores graph-match y graph-shortest-paths .

Sintaxis

map(*edge*, *expression*)'

map(inner_nodes( borde),expresión)

Parámetros

Nombre Tipo Obligatorio Descripción
borde string ✔️ Borde de longitud variable desde el operador graph-match o el patrón de operador graph-shortest-paths . Para obtener más información, consulte Notación de patrones de graph.
expresión string ✔️ Cálculo que se va a realizar sobre las propiedades del nodo perimetral o interno, cuando se usa inner_nodes , en el borde de longitud variable. Se hace referencia a una propiedad mediante el nombre de propiedad directamente. La expresión se evalúa para cada borde o nodo interno en el borde de longitud variable.

Devoluciones

Matriz dinámica donde:

  • La longitud de la matriz coincide con el número de bordes o nodos internos, cuando se usa inner_nodes , en el borde de longitud variable.
  • La matriz está vacía para rutas de acceso de longitud cero.
  • Cada elemento de la matriz corresponde a los resultados de aplicar la expresión a cada borde o nodo interno en el borde de longitud variable.

Ejemplos

Los ejemplos de esta sección muestran cómo usar la sintaxis para ayudarle a empezar.

Encuentre la estación y la línea para la ruta más corta entre dos estaciones

En el ejemplo siguiente se muestra cómo usar el graph-shortest-paths operador para buscar la ruta más corta entre las "South-West" estaciones y "North" en una red de transporte. Agrega información de línea a la ruta de acceso mediante la map() función . La consulta construye un gráfico a partir de los datos, teniendo en cuenta las connections rutas de acceso de hasta cinco conexiones de longitud.

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

Salida

desde camino Para
Suroeste [
"Sur (rojo)",
"Central (rojo)",
"Norte (rojo)"
]
Norte

Obtener la lista de paradas con Wi-Fi en todas las rutas entre dos estaciones

En el ejemplo siguiente se muestra cómo usar el graph-match operador con las all() funciones y inner_nodes para buscar todas las paradas con Wi-Fi en todas las rutas entre dos estaciones de una red de transporte.

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

Salida

Escalas stopovers_with_wifi
Centro-oeste> [ "Oeste", "Centro"]
Centro-sur> [ "Central"]