共用方式為


graph-mark-components 運算符 (預覽)

適用於:✅Microsoft網狀架構

graph-mark-components運算子會尋找圖形的所有已連接元件,並以元件標識碼標記每個節點。

注意

這個運算子會與 make-graph 運算子搭配使用,

語法

G|graph-mark-components [ Kind] [kind=with_component_id=ComponentId]

參數

姓名 類型​​ 必要 描述
G 字串 ✔️ 圖表來源。
種類 字串 連線的元件種類,可以是 weak (預設值) 或 strong。 弱式元件是一組由路徑連接的節點,忽略邊緣的方向。 強元件是一組以兩個方向連接的節點,考慮邊緣的方向。
ComponentId 字串 表示元件識別碼的屬性名稱。 預設屬性名稱稱為 ComponentId

傳回

運算符graph-mark-components會傳回圖形結果,其中每個節點在 ComponentId 屬性中都有元件標識碼。 標識碼是元件之以零起始的連續索引。 每個元件索引都是任意選擇的,而且在執行之間可能不一致。

範例

下列範例會從一組子父組建立圖形,並使用標識碼來識別連接的元件 family

let ChildOf = datatable(child:string, parent:string) 
[ 
  "Alice", "Bob",  
  "Carol", "Alice",  
  "Carol", "Dave",  
  "Greg", "Alice",  
  "Greg", "Dave",  
  "Howard", "Alice",  
  "Howard", "Dave",  
  "Eve", "Frank",  
  "Frank", "Mallory",
  "Eve", "Kirk",
]; 
ChildOf 
| make-graph child --> parent with_node_id=name
| graph-mark-components with_component_id = family
| graph-to-table nodes

輸出

NAME 系列
愛麗絲 0
鮑勃 0
頌歌 0
戴夫 0
格雷格 0
霍華德 0
前夕 1
弗蘭克 1
馬婁裡 1
柯克 1

下列範例會使用連接的元件 family 標識碼和 graph-match 運算符,來識別一組子父數據中每個家族的最大祖系。

let ChildOf = datatable(child:string, parent:string) 
[ 
  "Alice", "Bob",  
  "Carol", "Alice",  
  "Carol", "Dave",  
  "Greg", "Alice",  
  "Greg", "Dave",  
  "Howard", "Alice",  
  "Howard", "Dave",  
  "Eve", "Frank",  
  "Frank", "Mallory",
  "Eve", "Kirk",
]; 
ChildOf 
| make-graph child --> parent with_node_id=name
| graph-mark-components with_component_id = family
| graph-match (descendant)-[childOf*1..5]->(ancestor)
  project name = ancestor.name, lineage = map(childOf, child), family = ancestor.family
| summarize (generations, name) = arg_max(array_length(lineage),name) by family

輸出

系列 NAME
1 2 馬婁裡
0 2 鮑勃